From c776ef25a98ffede2deee1176441e8e4566dc417 Mon Sep 17 00:00:00 2001 From: Christian Stade-Schuldt Date: Sat, 19 Dec 2015 11:34:21 +0100 Subject: [PATCH] update scripts for FRITZ!OS:131.06.36-32026 BETA --- .gitignore | 61 +++++++++++++++++++++++++++++++++++ README.md | 7 +++- fritzbox_cpu_temperature.py | 4 +-- fritzbox_cpu_usage.py | 4 +-- fritzbox_memory_usage.py | 9 +++--- fritzbox_power_consumption.py | 10 +++--- fritzbox_uptime.py | 12 ++++--- 7 files changed, 88 insertions(+), 19 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7facc9b --- /dev/null +++ b/.gitignore @@ -0,0 +1,61 @@ +# Created by .ignore support plugin (hsz.mobi) +### Python template +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +env/ +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +*.egg-info/ +.installed.cfg +*.egg + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*,cover + +# Translations +*.mo +*.pot + +# Django stuff: +*.log + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + diff --git a/README.md b/README.md index 4addb1c..fea63f6 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,10 @@ # fritzbox-munin -A collection of munin plugins to monitor your AVM FRITZ!Box router. The scripts have been developed using a FRITZ!Box 7362 SL running FRITZ!OS 06.30. +A collection of munin plugins to monitor your AVM FRITZ!Box router. The scripts have been developed using a +FRITZ!Box 7362 SL running FRITZ!OS:131.06.36-32026 BETA. AVM has modified the web interface if the Fritz!Box +in the current version that the old scripts do not work anymore. This branch also only works if the language +of the Fritz!Box is set to German. + +If you are using FRITZ!OS 6.30 use the master branch. ## Introduction diff --git a/fritzbox_cpu_temperature.py b/fritzbox_cpu_temperature.py index d40b058..1d6d9c7 100755 --- a/fritzbox_cpu_temperature.py +++ b/fritzbox_cpu_temperature.py @@ -22,7 +22,7 @@ import sys import fritzbox_helper as fh PAGE = '/system/ecostat.lua' -pattern = re.compile(".*/(StatTemperature)\".*=.*\"(.*?)\"") +pattern = re.compile('Query\s=\s"(\d{1,3})') def get_cpu_temperature(): @@ -36,7 +36,7 @@ def get_cpu_temperature(): m = re.search(pattern, data) if m: - print 'temp.value %d' % (int(m.group(2).split(',')[0])) + print 'temp.value %d' % (int(m.group(1))) def print_config(): diff --git a/fritzbox_cpu_usage.py b/fritzbox_cpu_usage.py index 224049e..8bb1a4e 100755 --- a/fritzbox_cpu_usage.py +++ b/fritzbox_cpu_usage.py @@ -22,7 +22,7 @@ import sys import fritzbox_helper as fh PAGE = '/system/ecostat.lua' -pattern = re.compile(".*/(StatCPU)\".*=.*\"(.*?)\"") +pattern = re.compile('Query1\s=\s"(\d{1,3})') def get_cpu_usage(): @@ -36,7 +36,7 @@ def get_cpu_usage(): m = re.search(pattern, data) if m: - print 'cpu.value %d' % (int(m.group(2).split(',')[0])) + print 'cpu.value %d' % (int(m.group(1))) def print_config(): diff --git a/fritzbox_memory_usage.py b/fritzbox_memory_usage.py index 99e5f44..a366af3 100755 --- a/fritzbox_memory_usage.py +++ b/fritzbox_memory_usage.py @@ -22,8 +22,8 @@ import sys import fritzbox_helper as fh PAGE = '/system/ecostat.lua' -pattern = re.compile(".*/(StatRAM.*?)\".*=.*\"(.*?)\"") -USAGE_MAPPING = {'StatRAMCacheUsed': 'cache', 'StatRAMPhysFree': 'free', 'StatRAMStrictlyUsed': 'strict'} +pattern = re.compile('Query[1-3]\s="(\d{1,3})') +USAGE = ['free', 'cache', 'strict'] def get_memory_usage(): @@ -36,8 +36,9 @@ def get_memory_usage(): data = fh.get_page(server, sid, PAGE) matches = re.finditer(pattern, data) if matches: - for m in matches: - print'%s.value %d' % (USAGE_MAPPING[m.group(1)], int(m.group(2).split(',')[0])) + data = zip(USAGE, [m.group(1) for m in matches]) + for d in data: + print'%s.value %s' % (d[0], d[1]) def print_config(): diff --git a/fritzbox_power_consumption.py b/fritzbox_power_consumption.py index 220db67..bbe06a8 100755 --- a/fritzbox_power_consumption.py +++ b/fritzbox_power_consumption.py @@ -22,9 +22,8 @@ import sys import fritzbox_helper as fh PAGE = '/system/energy.lua' -pattern = re.compile(".*/(.*act?)\".*=.*\"(.*?)\"") -DEVICE_MAPPING = {'rate_abact': 'ab', 'rate_dspact': 'dsl', 'rate_sumact': 'system', - 'rate_systemact': 'cpu', 'rate_usbhostact': 'usb', 'rate_wlanact': 'wifi'} +pattern = re.compile('(.+?)"bar\s(act|fillonly)"(.+?)\s(\d{1,3})\s%') +DEVICES = ['system', 'cpu', 'wifi', 'dsl', 'ab', 'usb'] def get_power_consumption(): @@ -37,8 +36,9 @@ def get_power_consumption(): data = fh.get_page(server, sid, PAGE) matches = re.finditer(pattern, data) if matches: - for m in matches: - print'%s.value %d' % (DEVICE_MAPPING[m.group(1)], int(m.group(2))) + data = zip(DEVICES, [m.group(4) for m in matches]) + for d in data: + print'%s.value %s' % (d[0], d[1]) def print_config(): diff --git a/fritzbox_uptime.py b/fritzbox_uptime.py index 1e1d256..525dc0c 100755 --- a/fritzbox_uptime.py +++ b/fritzbox_uptime.py @@ -22,7 +22,7 @@ import sys import fritzbox_helper as fh PAGE = '/system/energy.lua' -pattern = re.compile(".*/(.*uptime_\w+?)\".*=.*\"(.*?)\"") +pattern = re.compile("(\d+)\s(Tagen|Stunden|Minuten)") def get_uptime(): @@ -37,10 +37,12 @@ def get_uptime(): if matches: hours = 0.0 for m in matches: - if m.group(1) == "uptime_hours": - hours += int(m.group(2)) - if m.group(1) == "uptime_minutes": - hours += int(m.group(2)) / 60.0 + if m.group(2) == 'Tagen': + hours += 24 * int(m.group(1)) + if m.group(2) == "Stunden": + hours += int(m.group(1)) + if m.group(2) == "Minuten": + hours += int(m.group(1)) / 60.0 uptime = hours / 24 print "uptime.value %.2f" % uptime