diff --git a/README.md b/README.md index 9c3b821..05020e6 100644 --- a/README.md +++ b/README.md @@ -78,21 +78,55 @@ If you are using the scripts on a different Fritz!Box model please let me know b 2. Make sure the FritzBox has UPnP status information enabled. (German interface: Heimnetz > Heimnetzübersicht > Netzwerkeinstellungen > Statusinformationen über UPnP übertragen) -3. Copy all the scripts to `/usr/share/munin/plugins` +3. Copy all the scripts (*.py) to `/usr/share/munin/plugins` -4. Create entry in `/etc/munin/plugin-conf.d/munin-node`: +4. Make all the scripts execute able (chmod 755 /usr/share/munin/plugins.*py) +5. Create entry in `/etc/munin/plugin-conf.d/munin-node`: + + a. only one fritzbox or all fritz boxes use the same password: [fritzbox_*] - env.fritzbox_ip env.fritzbox_password env.traffic_remove_max true # if you do not want the possible max values - host_name fritzbox -5. Create symbolic links to `/etc/munin/plugins`. + b. multble fritz boxes: + [fritzbox__*] + env.fritzbox_password + env.traffic_remove_max true # if you do not want the possible max values -6. Restart the munin-node daemon: `/etc/init.d/munin-node restart`. + [fritzbox__*] + env.fritzbox_password + env.traffic_remove_max true # if you do not want the possible max values -7. Done. You should now start to see the charts on the Munin pages. +6. Create symbolic link in `/etc/munin/plugins` for `fritzbox_helper.py`. + cd /etc/munin/plugins + ln -d /usr/share/munin/plugins/fritzbox_helper.py fritzbox_helper.py + +7. Create symbolic link in `/etc/munin/plugins` for probes. + link `/usr/share/munin/plugins/fritzbox__.py` to `fritzbox__` + + example + cd /etc/munin/plugins + ln -d /usr/share/munin/plugins/fritzbox__cpu_usage.py fritzbox_fritz.box_cpu_usage + ln -d /usr/share/munin/plugins/fritzbox__cpu_temperature.py fritzbox_fritz.box_cpu_temperature + ... + + if you have multible fritz box just create multble sets of links with a different fqdn or ip. + + example + cd /etc/munin/plugins + ln -d /usr/share/munin/plugins/fritzbox__cpu_usage.py fritzbox_fritz.box_cpu_usage + ln -d /usr/share/munin/plugins/fritzbox__cpu_usage.py fritzbox_box2.fritz.box_cpu_usage + ln -d /usr/share/munin/plugins/fritzbox__cpu_usage.py fritzbox_192.168.100.1_cpu_usage + ln -d /usr/share/munin/plugins/fritzbox__cpu_temperature.py fritzbox_box2.fritz.box_cpu_temperature + ln -d /usr/share/munin/plugins/fritzbox__cpu_temperature.py fritzbox_box2.fritz.box_cpu_temperature + ln -d /usr/share/munin/plugins/fritzbox__cpu_temperature.py fritzbox_192.168.100.1_cpu_temperature + ... + + +8. Restart the munin-node daemon: `systemctl restart munin-node`. + +9. Done. You should now start to see the charts on the Munin pages. ## Localization @@ -106,26 +140,22 @@ You can change the used locale by setting an environment variable in your plugin env.locale en -## Different hosts for the fritzbox and your system +## Set a group for your fritz boxes -You can split the graphs of your fritzbox from the localhost graphs by following the next steps: +You can group the graphs of your fritzbox: -1. Use the following as your host configuration in `/etc/munin/munin.conf` +1. Use the following as your host configuration in `/etc/munin/munin.conf` or by creating a file in `/etc/munin/munin-conf.d` - [home.yourhost.net;server] - address 127.0.0.1 - use_node_name yes - - - [home.yourhost.net;fritzbox] + [;] address 127.0.0.1 use_node_name no -2. Add the following to your munin-node configuration + example: + [Network;fritz.box] + address 127.0.0.1 + use_node_name no - env.host_name fritzbox - -3. Restart your munin-node: `systemctl restart munin-node` +2. Restart your munin-node: `systemctl restart munin-node` ## Environment Settings diff --git a/fritzbox__connection_uptime.py b/fritzbox__connection_uptime.py index 846fa66..b36d76f 100644 --- a/fritzbox__connection_uptime.py +++ b/fritzbox__connection_uptime.py @@ -1,61 +1,61 @@ -#!/usr/bin/env python -""" - fritzbox_connection_uptime - A munin plugin for Linux to monitor AVM Fritzbox connection uptime - Copyright (C) 2015 Christian Stade-Schuldt - Author: Christian Stade-Schuldt - - Updated to fritzconnection library version 1.3.1 - Copyright (C) 2020 Oliver Edelamnn - Author: Oliver Edelmann - - Like Munin, this plugin is licensed under the GNU GPL v2 license - http://www.opensource.org/licenses/GPL-2.0 - Like Munin, this plugin is licensed under the GNU GPL v2 license - http://www.opensource.org/licenses/GPL-2.0 - This plugin requires the fritzconnection plugin. To install it using pip: - pip install fritzconnection - This plugin supports the following munin configuration parameters: - #%# family=auto contrib - #%# capabilities=autoconf -""" - -import os -import sys - -from fritzconnection.lib.fritzstatus import FritzStatus - -hostname = os.path.basename(__file__).split('_')[1] - -def print_values(): - try: - conn = FritzStatus(address=hostname, password=os.environ['fritzbox_password']) - except Exception: - sys.exit("Couldn't get connection uptime") - - uptime = conn.uptime - print('uptime.value %.2f' % (int(uptime) / 3600.0)) - - -def print_config(): - print("host_name %s" % hostname) - print("graph_title AVM Fritz!Box Connection Uptime") - print("graph_args --base 1000 -l 0") - print('graph_vlabel uptime in hours') - print("graph_scale no'") - print("graph_category network") - print("uptime.label uptime") - print("uptime.draw AREA") - if os.environ.get('host_name'): - print("host_name " + os.environ['host_name']) - - -if __name__ == "__main__": - if len(sys.argv) == 2 and sys.argv[1] == 'config': - print_config() - elif len(sys.argv) == 2 and sys.argv[1] == 'autoconf': - print("yes") # Some docs say it'll be called with fetch, some say no arg at all - elif len(sys.argv) == 1 or (len(sys.argv) == 2 and sys.argv[1] == 'fetch'): - try: - print_values() - except: - sys.exit("Couldn't retrieve fritzbox connection uptime") +#!/usr/bin/env python +""" + fritzbox_connection_uptime - A munin plugin for Linux to monitor AVM Fritzbox connection uptime + Copyright (C) 2015 Christian Stade-Schuldt + Author: Christian Stade-Schuldt + + Updated to fritzconnection library version 1.3.1 + Copyright (C) 2020 Oliver Edelamnn + Author: Oliver Edelmann + + Like Munin, this plugin is licensed under the GNU GPL v2 license + http://www.opensource.org/licenses/GPL-2.0 + Like Munin, this plugin is licensed under the GNU GPL v2 license + http://www.opensource.org/licenses/GPL-2.0 + This plugin requires the fritzconnection plugin. To install it using pip: + pip install fritzconnection + This plugin supports the following munin configuration parameters: + #%# family=auto contrib + #%# capabilities=autoconf +""" + +import os +import sys + +from fritzconnection.lib.fritzstatus import FritzStatus + +hostname = os.path.basename(__file__).split('_')[1] + +def print_values(): + try: + conn = FritzStatus(address=hostname, password=os.environ['fritzbox_password']) + except Exception: + sys.exit("Couldn't get connection uptime") + + uptime = conn.uptime + print('uptime.value %.2f' % (int(uptime) / 3600.0)) + + +def print_config(): + print("host_name %s" % hostname) + print("graph_title AVM Fritz!Box Connection Uptime") + print("graph_args --base 1000 -l 0") + print('graph_vlabel uptime in hours') + print("graph_scale no'") + print("graph_category network") + print("uptime.label uptime") + print("uptime.draw AREA") + if os.environ.get('host_name'): + print("host_name " + os.environ['host_name']) + + +if __name__ == "__main__": + if len(sys.argv) == 2 and sys.argv[1] == 'config': + print_config() + elif len(sys.argv) == 2 and sys.argv[1] == 'autoconf': + print("yes") # Some docs say it'll be called with fetch, some say no arg at all + elif len(sys.argv) == 1 or (len(sys.argv) == 2 and sys.argv[1] == 'fetch'): + try: + print_values() + except: + sys.exit("Couldn't retrieve fritzbox connection uptime") diff --git a/fritzbox__cpu_temperature.py b/fritzbox__cpu_temperature.py index 53e0024..e608c72 100644 --- a/fritzbox__cpu_temperature.py +++ b/fritzbox__cpu_temperature.py @@ -1,62 +1,62 @@ -#!/usr/bin/env python -""" - fritzbox_cpu_temperature - A munin plugin for Linux to monitor AVM Fritzbox - Copyright (C) 2015 Christian Stade-Schuldt - Author: Christian Stade-Schuldt - Like Munin, this plugin is licensed under the GNU GPL v2 license - http://www.opensource.org/licenses/GPL-2.0 - Add the following section to your munin-node's plugin configuration: - - [fritzbox_*] - env.fritzbox_ip [ip address of the fritzbox] - env.fritzbox_password [fritzbox password] - - This plugin supports the following munin configuration parameters: - #%# family=auto contrib - #%# capabilities=autoconf -""" -import json -import os -import sys -import fritzbox_helper as fh - -PAGE = 'ecoStat' -hostname = os.path.basename(__file__).split('_')[1] - - -def get_cpu_temperature(): - """get the current cpu temperature""" - - server = hostname - password = os.environ['fritzbox_password'] - - session_id = fh.get_session_id(server, password) - xhr_data = fh.get_xhr_content(server, session_id, PAGE) - data = json.loads(xhr_data) - print('temp.value %d' % (int(data['data']['cputemp']['series'][0][-1]))) - - -def print_config(): - print("host_name %s" % hostname) - print("graph_title AVM Fritz!Box CPU temperature") - print("graph_vlabel degrees Celsius") - print("graph_category sensors") - print("graph_order tmp") - print("graph_scale no") - print("temp.label CPU temperature") - print("temp.type GAUGE") - print("temp.graph LINE1") - print("temp.min 0") - print("temp.info Fritzbox CPU temperature") - if os.environ.get('host_name'): - print("host_name " + os.environ['host_name']) - - -if __name__ == '__main__': - if len(sys.argv) == 2 and sys.argv[1] == 'config': - print_config() - elif len(sys.argv) == 2 and sys.argv[1] == 'autoconf': - print('yes') - elif len(sys.argv) == 1 or len(sys.argv) == 2 and sys.argv[1] == 'fetch': - # Some docs say it'll be called with fetch, some say no arg at all - get_cpu_temperature() +#!/usr/bin/env python +""" + fritzbox_cpu_temperature - A munin plugin for Linux to monitor AVM Fritzbox + Copyright (C) 2015 Christian Stade-Schuldt + Author: Christian Stade-Schuldt + Like Munin, this plugin is licensed under the GNU GPL v2 license + http://www.opensource.org/licenses/GPL-2.0 + Add the following section to your munin-node's plugin configuration: + + [fritzbox_*] + env.fritzbox_ip [ip address of the fritzbox] + env.fritzbox_password [fritzbox password] + + This plugin supports the following munin configuration parameters: + #%# family=auto contrib + #%# capabilities=autoconf +""" +import json +import os +import sys +import fritzbox_helper as fh + +PAGE = 'ecoStat' +hostname = os.path.basename(__file__).split('_')[1] + + +def get_cpu_temperature(): + """get the current cpu temperature""" + + server = hostname + password = os.environ['fritzbox_password'] + + session_id = fh.get_session_id(server, password) + xhr_data = fh.get_xhr_content(server, session_id, PAGE) + data = json.loads(xhr_data) + print('temp.value %d' % (int(data['data']['cputemp']['series'][0][-1]))) + + +def print_config(): + print("host_name %s" % hostname) + print("graph_title AVM Fritz!Box CPU temperature") + print("graph_vlabel degrees Celsius") + print("graph_category sensors") + print("graph_order tmp") + print("graph_scale no") + print("temp.label CPU temperature") + print("temp.type GAUGE") + print("temp.graph LINE1") + print("temp.min 0") + print("temp.info Fritzbox CPU temperature") + if os.environ.get('host_name'): + print("host_name " + os.environ['host_name']) + + +if __name__ == '__main__': + if len(sys.argv) == 2 and sys.argv[1] == 'config': + print_config() + elif len(sys.argv) == 2 and sys.argv[1] == 'autoconf': + print('yes') + elif len(sys.argv) == 1 or len(sys.argv) == 2 and sys.argv[1] == 'fetch': + # Some docs say it'll be called with fetch, some say no arg at all + get_cpu_temperature() diff --git a/fritzbox__cpu_usage.py b/fritzbox__cpu_usage.py index 1575408..9109844 100644 --- a/fritzbox__cpu_usage.py +++ b/fritzbox__cpu_usage.py @@ -1,65 +1,65 @@ -#!/usr/bin/env python -""" - fritzbox_cpu_usage - A munin plugin for Linux to monitor AVM Fritzbox - Copyright (C) 2015 Christian Stade-Schuldt - Author: Christian Stade-Schuldt - Like Munin, this plugin is licensed under the GNU GPL v2 license - http://www.opensource.org/licenses/GPL-2.0 - Add the following section to your munin-node's plugin configuration: - - [fritzbox_*] - env.fritzbox_ip [ip address of the fritzbox] - env.fritzbox_password [fritzbox password] - - This plugin supports the following munin configuration parameters: - #%# family=auto contrib - #%# capabilities=autoconf -""" -import json -import os -import sys -import fritzbox_helper as fh - -PAGE = 'ecoStat' -hostname = os.path.basename(__file__).split('_')[1] - - -def get_cpu_usage(): - """get the current cpu usage""" - - server = hostname - password = os.environ['fritzbox_password'] - - session_id = fh.get_session_id(server, password) - xhr_data = fh.get_xhr_content(server, session_id, PAGE) - data = json.loads(xhr_data) - print('cpu.value %d' % (int(data['data']['cpuutil']['series'][0][-1]))) - - -def print_config(): - print("host_name %s" % hostname) - print("graph_title AVM Fritz!Box CPU usage") - print("graph_vlabel %") - print("graph_category system") - print("graph_order cpu") - print("graph_scale no") - print("cpu.label system") - print("cpu.type GAUGE") - print("cpu.graph AREA") - print("cpu.min 0") - print("cpu.info Fritzbox CPU usage") - if os.environ.get('host_name'): - print("host_name " + os.environ['host_name']) - - -if __name__ == '__main__': - if len(sys.argv) == 2 and sys.argv[1] == 'config': - print_config() - elif len(sys.argv) == 2 and sys.argv[1] == 'autoconf': - print('yes') - elif len(sys.argv) == 1 or len(sys.argv) == 2 and sys.argv[1] == 'fetch': - # Some docs say it'll be called with fetch, some say no arg at all - try: - get_cpu_usage() - except: - sys.exit("Couldn't retrieve fritzbox cpu usage") +#!/usr/bin/env python +""" + fritzbox_cpu_usage - A munin plugin for Linux to monitor AVM Fritzbox + Copyright (C) 2015 Christian Stade-Schuldt + Author: Christian Stade-Schuldt + Like Munin, this plugin is licensed under the GNU GPL v2 license + http://www.opensource.org/licenses/GPL-2.0 + Add the following section to your munin-node's plugin configuration: + + [fritzbox_*] + env.fritzbox_ip [ip address of the fritzbox] + env.fritzbox_password [fritzbox password] + + This plugin supports the following munin configuration parameters: + #%# family=auto contrib + #%# capabilities=autoconf +""" +import json +import os +import sys +import fritzbox_helper as fh + +PAGE = 'ecoStat' +hostname = os.path.basename(__file__).split('_')[1] + + +def get_cpu_usage(): + """get the current cpu usage""" + + server = hostname + password = os.environ['fritzbox_password'] + + session_id = fh.get_session_id(server, password) + xhr_data = fh.get_xhr_content(server, session_id, PAGE) + data = json.loads(xhr_data) + print('cpu.value %d' % (int(data['data']['cpuutil']['series'][0][-1]))) + + +def print_config(): + print("host_name %s" % hostname) + print("graph_title AVM Fritz!Box CPU usage") + print("graph_vlabel %") + print("graph_category system") + print("graph_order cpu") + print("graph_scale no") + print("cpu.label system") + print("cpu.type GAUGE") + print("cpu.graph AREA") + print("cpu.min 0") + print("cpu.info Fritzbox CPU usage") + if os.environ.get('host_name'): + print("host_name " + os.environ['host_name']) + + +if __name__ == '__main__': + if len(sys.argv) == 2 and sys.argv[1] == 'config': + print_config() + elif len(sys.argv) == 2 and sys.argv[1] == 'autoconf': + print('yes') + elif len(sys.argv) == 1 or len(sys.argv) == 2 and sys.argv[1] == 'fetch': + # Some docs say it'll be called with fetch, some say no arg at all + try: + get_cpu_usage() + except: + sys.exit("Couldn't retrieve fritzbox cpu usage") diff --git a/fritzbox__memory_usage.py b/fritzbox__memory_usage.py index d6fb1e8..868ce43 100644 --- a/fritzbox__memory_usage.py +++ b/fritzbox__memory_usage.py @@ -1,73 +1,73 @@ -#!/usr/bin/env python -""" - fritzbox_memory_usage - A munin plugin for Linux to monitor AVM Fritzbox - Copyright (C) 2015 Christian Stade-Schuldt - Author: Christian Stade-Schuldt - Like Munin, this plugin is licensed under the GNU GPL v2 license - http://www.opensource.org/licenses/GPL-2.0 - Add the following section to your munin-node's plugin configuration: - - [fritzbox_*] - env.fritzbox_ip [ip address of the fritzbox] - env.fritzbox_password [fritzbox password] - - This plugin supports the following munin configuration parameters: - #%# family=auto contrib - #%# capabilities=autoconf -""" -import json -import os -import sys -import fritzbox_helper as fh - -PAGE = 'ecoStat' -USAGE = ['strict', 'cache', 'free'] -hostname = os.path.basename(__file__).split('_')[1] - - -def get_memory_usage(): - """get the current memory usage""" - - server = hostname - password = os.environ['fritzbox_password'] - - session_id = fh.get_session_id(server, password) - xhr_data = fh.get_xhr_content(server, session_id, PAGE) - data = json.loads(xhr_data) - for i, usage in enumerate(USAGE): - print('%s.value %s' % (usage, data['data']['ramusage']['series'][i][-1])) - - -def print_config(): - print("host_name %s" % hostname) - print("graph_title AVM Fritz!Box Memory") - print("graph_vlabel %") - print("graph_args --base 1000 -r --lower-limit 0 --upper-limit 100") - print("graph_category system") - print("graph_order strict cache free") - print("graph_info This graph shows what the Fritzbox uses memory for.") - print("graph_scale no") - print("strict.label strict") - print("strict.type GAUGE") - print("strict.draw AREA") - print("cache.label cache") - print("cache.type GAUGE") - print("cache.draw STACK") - print("free.label free") - print("free.type GAUGE") - print("free.draw STACK") - if os.environ.get('host_name'): - print("host_name " + os.environ['host_name']) - - -if __name__ == '__main__': - if len(sys.argv) == 2 and sys.argv[1] == 'config': - print_config() - elif len(sys.argv) == 2 and sys.argv[1] == 'autoconf': - print('yes') - elif len(sys.argv) == 1 or len(sys.argv) == 2 and sys.argv[1] == 'fetch': - # Some docs say it'll be called with fetch, some say no arg at all - try: - get_memory_usage() - except: - sys.exit("Couldn't retrieve fritzbox memory usage") +#!/usr/bin/env python +""" + fritzbox_memory_usage - A munin plugin for Linux to monitor AVM Fritzbox + Copyright (C) 2015 Christian Stade-Schuldt + Author: Christian Stade-Schuldt + Like Munin, this plugin is licensed under the GNU GPL v2 license + http://www.opensource.org/licenses/GPL-2.0 + Add the following section to your munin-node's plugin configuration: + + [fritzbox_*] + env.fritzbox_ip [ip address of the fritzbox] + env.fritzbox_password [fritzbox password] + + This plugin supports the following munin configuration parameters: + #%# family=auto contrib + #%# capabilities=autoconf +""" +import json +import os +import sys +import fritzbox_helper as fh + +PAGE = 'ecoStat' +USAGE = ['strict', 'cache', 'free'] +hostname = os.path.basename(__file__).split('_')[1] + + +def get_memory_usage(): + """get the current memory usage""" + + server = hostname + password = os.environ['fritzbox_password'] + + session_id = fh.get_session_id(server, password) + xhr_data = fh.get_xhr_content(server, session_id, PAGE) + data = json.loads(xhr_data) + for i, usage in enumerate(USAGE): + print('%s.value %s' % (usage, data['data']['ramusage']['series'][i][-1])) + + +def print_config(): + print("host_name %s" % hostname) + print("graph_title AVM Fritz!Box Memory") + print("graph_vlabel %") + print("graph_args --base 1000 -r --lower-limit 0 --upper-limit 100") + print("graph_category system") + print("graph_order strict cache free") + print("graph_info This graph shows what the Fritzbox uses memory for.") + print("graph_scale no") + print("strict.label strict") + print("strict.type GAUGE") + print("strict.draw AREA") + print("cache.label cache") + print("cache.type GAUGE") + print("cache.draw STACK") + print("free.label free") + print("free.type GAUGE") + print("free.draw STACK") + if os.environ.get('host_name'): + print("host_name " + os.environ['host_name']) + + +if __name__ == '__main__': + if len(sys.argv) == 2 and sys.argv[1] == 'config': + print_config() + elif len(sys.argv) == 2 and sys.argv[1] == 'autoconf': + print('yes') + elif len(sys.argv) == 1 or len(sys.argv) == 2 and sys.argv[1] == 'fetch': + # Some docs say it'll be called with fetch, some say no arg at all + try: + get_memory_usage() + except: + sys.exit("Couldn't retrieve fritzbox memory usage") diff --git a/fritzbox__power_consumption.py b/fritzbox__power_consumption.py index 1972480..8f1a143 100644 --- a/fritzbox__power_consumption.py +++ b/fritzbox__power_consumption.py @@ -1,99 +1,99 @@ -#!/usr/bin/env python -# coding=utf-8 -""" - fritzbox_power_consumption - A munin plugin for Linux to monitor AVM Fritzbox - Copyright (C) 2015 Christian Stade-Schuldt - Author: Christian Stade-Schuldt - Like Munin, this plugin is licensed under the GNU GPL v2 license - http://www.opensource.org/licenses/GPL-2.0 - Add the following section to your munin-node's plugin configuration: - - [fritzbox_*] - env.fritzbox_ip [ip address of the fritzbox] - env.fritzbox_password [fritzbox password] - - This plugin supports the following munin configuration parameters: - #%# family=auto contrib - #%# capabilities=autoconf -""" -import json -import os -import sys - -import fritzbox_helper as fh - -PAGE = 'energy' -DEVICES = ['system', 'cpu', 'wifi', 'dsl', 'ab', 'usb'] -hostname = os.path.basename(__file__).split('_')[1] - -def get_power_consumption(): - """get the current power consumption usage""" - - server = hostname - password = os.environ['fritzbox_password'] - - session_id = fh.get_session_id(server, password) - xhr_data = fh.get_xhr_content(server, session_id, PAGE) - data = json.loads(xhr_data) - devices = data['data']['drain'] - for i, device in enumerate(DEVICES): - print('%s.value %s' % (device, devices[i]['actPerc'])) - - -def print_config(): - print("host_name %s" % hostname) - print("graph_title AVM Fritz!Box Power Consumption") - print("graph_vlabel %") - print("graph_category system") - print("graph_order system cpu wifi dsl ab usb") - print("system.label system") - print("system.type GAUGE") - print("system.graph LINE12") - print("system.min 0") - print("system.max 100") - print("system.info Fritzbox overall power consumption") - print("cpu.label cpu") - print("cpu.type GAUGE") - print("cpu.graph LINE1") - print("cpu.min 0") - print("cpu.max 100") - print("cpu.info Fritzbox central processor power consumption") - print("wifi.label wifi") - print("wifi.type GAUGE") - print("wifi.graph LINE1") - print("wifi.min 0") - print("wifi.max 100") - print("wifi.info Fritzbox wifi power consumption") - print("dsl.label dsl") - print("dsl.type GAUGE") - print("dsl.graph LINE1") - print("dsl.min 0") - print("dsl.max 100") - print("dsl.info Fritzbox dsl power consumption") - print("ab.label ab") - print("ab.type GAUGE") - print("ab.graph LINE1") - print("ab.min 0") - print("ab.max 100") - print("ab.info Fritzbox analog phone ports power consumption") - print("usb.label usb") - print("usb.type GAUGE") - print("usb.graph LINE1") - print("usb.min 0") - print("usb.max 100") - print("usb.info Fritzbox usb devices power consumption") - if os.environ.get('host_name'): - print("host_name " + os.environ['host_name']) - - -if __name__ == '__main__': - if len(sys.argv) == 2 and sys.argv[1] == 'config': - print_config() - elif len(sys.argv) == 2 and sys.argv[1] == 'autoconf': - print('yes') - elif len(sys.argv) == 1 or len(sys.argv) == 2 and sys.argv[1] == 'fetch': - # Some docs say it'll be called with fetch, some say no arg at all - try: - get_power_consumption() - except: - sys.exit("Couldn't retrieve fritzbox power consumption") +#!/usr/bin/env python +# coding=utf-8 +""" + fritzbox_power_consumption - A munin plugin for Linux to monitor AVM Fritzbox + Copyright (C) 2015 Christian Stade-Schuldt + Author: Christian Stade-Schuldt + Like Munin, this plugin is licensed under the GNU GPL v2 license + http://www.opensource.org/licenses/GPL-2.0 + Add the following section to your munin-node's plugin configuration: + + [fritzbox_*] + env.fritzbox_ip [ip address of the fritzbox] + env.fritzbox_password [fritzbox password] + + This plugin supports the following munin configuration parameters: + #%# family=auto contrib + #%# capabilities=autoconf +""" +import json +import os +import sys + +import fritzbox_helper as fh + +PAGE = 'energy' +DEVICES = ['system', 'cpu', 'wifi', 'dsl', 'ab', 'usb'] +hostname = os.path.basename(__file__).split('_')[1] + +def get_power_consumption(): + """get the current power consumption usage""" + + server = hostname + password = os.environ['fritzbox_password'] + + session_id = fh.get_session_id(server, password) + xhr_data = fh.get_xhr_content(server, session_id, PAGE) + data = json.loads(xhr_data) + devices = data['data']['drain'] + for i, device in enumerate(DEVICES): + print('%s.value %s' % (device, devices[i]['actPerc'])) + + +def print_config(): + print("host_name %s" % hostname) + print("graph_title AVM Fritz!Box Power Consumption") + print("graph_vlabel %") + print("graph_category system") + print("graph_order system cpu wifi dsl ab usb") + print("system.label system") + print("system.type GAUGE") + print("system.graph LINE12") + print("system.min 0") + print("system.max 100") + print("system.info Fritzbox overall power consumption") + print("cpu.label cpu") + print("cpu.type GAUGE") + print("cpu.graph LINE1") + print("cpu.min 0") + print("cpu.max 100") + print("cpu.info Fritzbox central processor power consumption") + print("wifi.label wifi") + print("wifi.type GAUGE") + print("wifi.graph LINE1") + print("wifi.min 0") + print("wifi.max 100") + print("wifi.info Fritzbox wifi power consumption") + print("dsl.label dsl") + print("dsl.type GAUGE") + print("dsl.graph LINE1") + print("dsl.min 0") + print("dsl.max 100") + print("dsl.info Fritzbox dsl power consumption") + print("ab.label ab") + print("ab.type GAUGE") + print("ab.graph LINE1") + print("ab.min 0") + print("ab.max 100") + print("ab.info Fritzbox analog phone ports power consumption") + print("usb.label usb") + print("usb.type GAUGE") + print("usb.graph LINE1") + print("usb.min 0") + print("usb.max 100") + print("usb.info Fritzbox usb devices power consumption") + if os.environ.get('host_name'): + print("host_name " + os.environ['host_name']) + + +if __name__ == '__main__': + if len(sys.argv) == 2 and sys.argv[1] == 'config': + print_config() + elif len(sys.argv) == 2 and sys.argv[1] == 'autoconf': + print('yes') + elif len(sys.argv) == 1 or len(sys.argv) == 2 and sys.argv[1] == 'fetch': + # Some docs say it'll be called with fetch, some say no arg at all + try: + get_power_consumption() + except: + sys.exit("Couldn't retrieve fritzbox power consumption") diff --git a/fritzbox__traffic.py b/fritzbox__traffic.py index dfc2013..73fe90a 100644 --- a/fritzbox__traffic.py +++ b/fritzbox__traffic.py @@ -1,105 +1,105 @@ -#!/usr/bin/env python -""" - fritzbox_traffic - A munin plugin for Linux to monitor AVM Fritzbox WAN traffic - Copyright (C) 2015 Christian Stade-Schuldt - Author: Christian Stade-Schuldt - - Updated to fritzconnection library version 1.3.1 - Copyright (C) 2020 Oliver Edelamnn - Author: Oliver Edelmann - - Like Munin, this plugin is licensed under the GNU GPL v2 license - http://www.opensource.org/licenses/GPL-2.0 - Like Munin, this plugin is licensed under the GNU GPL v2 license - http://www.opensource.org/licenses/GPL-2.0 - This plugin requires the fritzconnection plugin. To install it using pip: - pip install fritzconnection - This plugin supports the following munin configuration parameters: - #%# family=auto contrib - #%# capabilities=autoconf -""" - -import os -import sys - -from fritzconnection.lib.fritzstatus import FritzStatus - -hostname = os.path.basename(__file__).split('_')[1] - -def print_values(): - try: - conn = FritzStatus(address=hostname, password=os.environ['fritzbox_password']) - except Exception as e: - print(e) - sys.exit("Couldn't get WAN traffic") - - traffic = conn.transmission_rate - up = traffic[0]*8 - down = traffic[1]*8 - print('down.value %d' % down) - - print('up.value %d' % up) - - if not os.environ.get('traffic_remove_max') or "false" in os.environ.get('traffic_remove_max'): - max_traffic = conn.max_bit_rate - print('maxdown.value %d' % max_traffic[1]) - - print('maxup.value %d' % max_traffic[0]) - - -def print_config(): - try: - conn = FritzStatus(address=hostname, password=os.environ['fritzbox_password']) - except Exception as e: - print(e) - sys.exit("Couldn't get WAN traffic") - - max_traffic = conn.max_bit_rate - - print("host_name %s" % hostname) - print("graph_title AVM Fritz!Box WAN traffic") - print("graph_args --base 1000") - print("graph_vlabel bit up (+) / down (-) per ${graph_period}") - print("graph_category network") - print("graph_order down up maxdown maxup") - print("down.label received") - print("down.type GAUGE") - print("down.graph no") - #print("down.cdef down,8,*") - print("down.min 0") - print("down.max %d" % max_traffic[1]) - #print("down.warning %.0f" % (max_traffic[1]*0.6)) - #print("down.critical %.0f" % (max_traffic[1]*0.8)) - print("up.label bps") - print("up.type GAUGE") - print("up.draw AREA") - #print("up.cdef up,8,*") - print("up.min 0") - print("up.max %d" % max_traffic[0]) - print("up.negative down") - #print("up.warning %.0f" % (max_traffic[0]*0.6)) - #print("down.critical %.0f" % (max_traffic[0]*0.8)) - print("up.info Traffic of the WAN interface.") - if not os.environ.get('traffic_remove_max') or "false" in os.environ.get('traffic_remove_max'): - print("maxdown.label received") - print("maxdown.type GAUGE") - print("maxdown.graph no") - print("maxup.label MAX") - print("maxup.type GAUGE") - print("maxup.negative maxdown") - print("maxup.draw LINE1") - print("maxup.info Maximum speed of the WAN interface.") - if os.environ.get('host_name'): - print("host_name " + os.environ['host_name']) - - -if __name__ == "__main__": - if len(sys.argv) == 2 and sys.argv[1] == 'config': - print_config() - elif len(sys.argv) == 2 and sys.argv[1] == 'autoconf': - print("yes") # Some docs say it'll be called with fetch, some say no arg at all - elif len(sys.argv) == 1 or (len(sys.argv) == 2 and sys.argv[1] == 'fetch'): - try: - print_values() - except: - sys.exit("Couldn't retrieve fritzbox traffic") +#!/usr/bin/env python +""" + fritzbox_traffic - A munin plugin for Linux to monitor AVM Fritzbox WAN traffic + Copyright (C) 2015 Christian Stade-Schuldt + Author: Christian Stade-Schuldt + + Updated to fritzconnection library version 1.3.1 + Copyright (C) 2020 Oliver Edelamnn + Author: Oliver Edelmann + + Like Munin, this plugin is licensed under the GNU GPL v2 license + http://www.opensource.org/licenses/GPL-2.0 + Like Munin, this plugin is licensed under the GNU GPL v2 license + http://www.opensource.org/licenses/GPL-2.0 + This plugin requires the fritzconnection plugin. To install it using pip: + pip install fritzconnection + This plugin supports the following munin configuration parameters: + #%# family=auto contrib + #%# capabilities=autoconf +""" + +import os +import sys + +from fritzconnection.lib.fritzstatus import FritzStatus + +hostname = os.path.basename(__file__).split('_')[1] + +def print_values(): + try: + conn = FritzStatus(address=hostname, password=os.environ['fritzbox_password']) + except Exception as e: + print(e) + sys.exit("Couldn't get WAN traffic") + + traffic = conn.transmission_rate + up = traffic[0]*8 + down = traffic[1]*8 + print('down.value %d' % down) + + print('up.value %d' % up) + + if not os.environ.get('traffic_remove_max') or "false" in os.environ.get('traffic_remove_max'): + max_traffic = conn.max_bit_rate + print('maxdown.value %d' % max_traffic[1]) + + print('maxup.value %d' % max_traffic[0]) + + +def print_config(): + try: + conn = FritzStatus(address=hostname, password=os.environ['fritzbox_password']) + except Exception as e: + print(e) + sys.exit("Couldn't get WAN traffic") + + max_traffic = conn.max_bit_rate + + print("host_name %s" % hostname) + print("graph_title AVM Fritz!Box WAN traffic") + print("graph_args --base 1000") + print("graph_vlabel bit up (+) / down (-) per ${graph_period}") + print("graph_category network") + print("graph_order down up maxdown maxup") + print("down.label received") + print("down.type GAUGE") + print("down.graph no") + #print("down.cdef down,8,*") + print("down.min 0") + print("down.max %d" % max_traffic[1]) + #print("down.warning %.0f" % (max_traffic[1]*0.6)) + #print("down.critical %.0f" % (max_traffic[1]*0.8)) + print("up.label bps") + print("up.type GAUGE") + print("up.draw AREA") + #print("up.cdef up,8,*") + print("up.min 0") + print("up.max %d" % max_traffic[0]) + print("up.negative down") + #print("up.warning %.0f" % (max_traffic[0]*0.6)) + #print("down.critical %.0f" % (max_traffic[0]*0.8)) + print("up.info Traffic of the WAN interface.") + if not os.environ.get('traffic_remove_max') or "false" in os.environ.get('traffic_remove_max'): + print("maxdown.label received") + print("maxdown.type GAUGE") + print("maxdown.graph no") + print("maxup.label MAX") + print("maxup.type GAUGE") + print("maxup.negative maxdown") + print("maxup.draw LINE1") + print("maxup.info Maximum speed of the WAN interface.") + if os.environ.get('host_name'): + print("host_name " + os.environ['host_name']) + + +if __name__ == "__main__": + if len(sys.argv) == 2 and sys.argv[1] == 'config': + print_config() + elif len(sys.argv) == 2 and sys.argv[1] == 'autoconf': + print("yes") # Some docs say it'll be called with fetch, some say no arg at all + elif len(sys.argv) == 1 or (len(sys.argv) == 2 and sys.argv[1] == 'fetch'): + try: + print_values() + except: + sys.exit("Couldn't retrieve fritzbox traffic") diff --git a/fritzbox__traffic_down.py b/fritzbox__traffic_down.py index 273611b..3d8ecd0 100644 --- a/fritzbox__traffic_down.py +++ b/fritzbox__traffic_down.py @@ -1,92 +1,92 @@ -#!/usr/bin/env python -""" - fritzbox_traffic - A munin plugin for Linux to monitor AVM Fritzbox WAN traffic - Copyright (C) 2015 Christian Stade-Schuldt - Author: Christian Stade-Schuldt - - Updated to fritzconnection library version 1.3.1 - Copyright (C) 2020 Oliver Edelamnn - Author: Oliver Edelmann - - Like Munin, this plugin is licensed under the GNU GPL v2 license - http://www.opensource.org/licenses/GPL-2.0 - Like Munin, this plugin is licensed under the GNU GPL v2 license - http://www.opensource.org/licenses/GPL-2.0 - This plugin requires the fritzconnection plugin. To install it using pip: - pip install fritzconnection - This plugin supports the following munin configuration parameters: - #%# family=auto contrib - #%# capabilities=autoconf -""" - -import os -import sys - -from fritzconnection.lib.fritzstatus import FritzStatus - -hostname = os.path.basename(__file__).split('_')[1] - -def print_values(): - try: - conn = FritzStatus(address=hostname, password=os.environ['fritzbox_password']) - except Exception as e: - print(e) - sys.exit("Couldn't get WAN traffic") - - traffic = conn.transmission_rate - up = traffic[0]*8 - down = traffic[1]*8 - print('down.value %d' % down) - - print('up.value %d' % up) - - if not os.environ.get('traffic_remove_max') or "false" in os.environ.get('traffic_remove_max'): - max_traffic = conn.max_bit_rate - print('maxdown.value %d' % max_traffic[1]) - - print('maxup.value %d' % max_traffic[0]) - - -def print_config(): - try: - conn = FritzStatus(address=hostname, password=os.environ['fritzbox_password']) - except Exception as e: - print(e) - sys.exit("Couldn't get WAN traffic") - - max_traffic = conn.max_bit_rate - - print("host_name %s" % hostname) - print("graph_title AVM Fritz!Box WAN traffic") - print("graph_args --base 1000") - print("graph_vlabel bit down per ${graph_period}") - print("graph_category network") - print("graph_order down maxdown") - print("down.label bps") - print("down.type GAUGE") - print("down.draw AREA") - print("down.graph no") - print("down.min 0") - print("down.max %d" % max_traffic[1]) - print("down.warning %.0f" % (max_traffic[1]*0.6)) - print("down.critical %.0f" % (max_traffic[1]*0.8)) - print("down.info Traffic of the WAN interface.") - if not os.environ.get('traffic_remove_max') or "false" in os.environ.get('traffic_remove_max'): - print("maxdown.label received") - print("maxdown.type GAUGE") - print("maxdown.graph no") - print("maxdown.info Maximum down speed of the WAN interface.") - if os.environ.get('host_name'): - print("host_name " + os.environ['host_name']) - - -if __name__ == "__main__": - if len(sys.argv) == 2 and sys.argv[1] == 'config': - print_config() - elif len(sys.argv) == 2 and sys.argv[1] == 'autoconf': - print("yes") # Some docs say it'll be called with fetch, some say no arg at all - elif len(sys.argv) == 1 or (len(sys.argv) == 2 and sys.argv[1] == 'fetch'): - try: - print_values() - except: - sys.exit("Couldn't retrieve fritzbox traffic") +#!/usr/bin/env python +""" + fritzbox_traffic - A munin plugin for Linux to monitor AVM Fritzbox WAN traffic + Copyright (C) 2015 Christian Stade-Schuldt + Author: Christian Stade-Schuldt + + Updated to fritzconnection library version 1.3.1 + Copyright (C) 2020 Oliver Edelamnn + Author: Oliver Edelmann + + Like Munin, this plugin is licensed under the GNU GPL v2 license + http://www.opensource.org/licenses/GPL-2.0 + Like Munin, this plugin is licensed under the GNU GPL v2 license + http://www.opensource.org/licenses/GPL-2.0 + This plugin requires the fritzconnection plugin. To install it using pip: + pip install fritzconnection + This plugin supports the following munin configuration parameters: + #%# family=auto contrib + #%# capabilities=autoconf +""" + +import os +import sys + +from fritzconnection.lib.fritzstatus import FritzStatus + +hostname = os.path.basename(__file__).split('_')[1] + +def print_values(): + try: + conn = FritzStatus(address=hostname, password=os.environ['fritzbox_password']) + except Exception as e: + print(e) + sys.exit("Couldn't get WAN traffic") + + traffic = conn.transmission_rate + up = traffic[0]*8 + down = traffic[1]*8 + print('down.value %d' % down) + + print('up.value %d' % up) + + if not os.environ.get('traffic_remove_max') or "false" in os.environ.get('traffic_remove_max'): + max_traffic = conn.max_bit_rate + print('maxdown.value %d' % max_traffic[1]) + + print('maxup.value %d' % max_traffic[0]) + + +def print_config(): + try: + conn = FritzStatus(address=hostname, password=os.environ['fritzbox_password']) + except Exception as e: + print(e) + sys.exit("Couldn't get WAN traffic") + + max_traffic = conn.max_bit_rate + + print("host_name %s" % hostname) + print("graph_title AVM Fritz!Box WAN traffic") + print("graph_args --base 1000") + print("graph_vlabel bit down per ${graph_period}") + print("graph_category network") + print("graph_order down maxdown") + print("down.label bps") + print("down.type GAUGE") + print("down.draw AREA") + print("down.graph no") + print("down.min 0") + print("down.max %d" % max_traffic[1]) + print("down.warning %.0f" % (max_traffic[1]*0.6)) + print("down.critical %.0f" % (max_traffic[1]*0.8)) + print("down.info Traffic of the WAN interface.") + if not os.environ.get('traffic_remove_max') or "false" in os.environ.get('traffic_remove_max'): + print("maxdown.label received") + print("maxdown.type GAUGE") + print("maxdown.graph no") + print("maxdown.info Maximum down speed of the WAN interface.") + if os.environ.get('host_name'): + print("host_name " + os.environ['host_name']) + + +if __name__ == "__main__": + if len(sys.argv) == 2 and sys.argv[1] == 'config': + print_config() + elif len(sys.argv) == 2 and sys.argv[1] == 'autoconf': + print("yes") # Some docs say it'll be called with fetch, some say no arg at all + elif len(sys.argv) == 1 or (len(sys.argv) == 2 and sys.argv[1] == 'fetch'): + try: + print_values() + except: + sys.exit("Couldn't retrieve fritzbox traffic") diff --git a/fritzbox__traffic_up.py b/fritzbox__traffic_up.py index 6370b38..42fe5c4 100644 --- a/fritzbox__traffic_up.py +++ b/fritzbox__traffic_up.py @@ -1,91 +1,91 @@ -#!/usr/bin/env python -""" - fritzbox_traffic - A munin plugin for Linux to monitor AVM Fritzbox WAN traffic - Copyright (C) 2015 Christian Stade-Schuldt - Author: Christian Stade-Schuldt - - Updated to fritzconnection library version 1.3.1 - Copyright (C) 2020 Oliver Edelamnn - Author: Oliver Edelmann - - Like Munin, this plugin is licensed under the GNU GPL v2 license - http://www.opensource.org/licenses/GPL-2.0 - Like Munin, this plugin is licensed under the GNU GPL v2 license - http://www.opensource.org/licenses/GPL-2.0 - This plugin requires the fritzconnection plugin. To install it using pip: - pip install fritzconnection - This plugin supports the following munin configuration parameters: - #%# family=auto contrib - #%# capabilities=autoconf -""" - -import os -import sys - -from fritzconnection.lib.fritzstatus import FritzStatus - -hostname = os.path.basename(__file__).split('_')[1] - -def print_values(): - try: - conn = FritzStatus(address=hostname, password=os.environ['fritzbox_password']) - except Exception as e: - print(e) - sys.exit("Couldn't get WAN traffic") - - traffic = conn.transmission_rate - up = traffic[0]*8 - down = traffic[1]*8 - print('down.value %d' % down) - - print('up.value %d' % up) - - if not os.environ.get('traffic_remove_max') or "false" in os.environ.get('traffic_remove_max'): - max_traffic = conn.max_bit_rate - print('maxdown.value %d' % max_traffic[1]) - - print('maxup.value %d' % max_traffic[0]) - - -def print_config(): - try: - conn = FritzStatus(address=hostname, password=os.environ['fritzbox_password']) - except Exception as e: - print(e) - sys.exit("Couldn't get WAN traffic") - - max_traffic = conn.max_bit_rate - - print("host_name %s" % hostname) - print("graph_title AVM Fritz!Box WAN traffic") - print("graph_args --base 1000") - print("graph_vlabel bit up per ${graph_period}") - print("graph_category network") - print("graph_order up maxup") - print("up.label bps") - print("up.type GAUGE") - print("up.draw AREA") - print("up.min 0") - print("up.max %d" % max_traffic[1]) - print("up.warning %.0f" % (max_traffic[1]*0.6)) - print("up.critical %.0f" % (max_traffic[1]*0.8)) - print("up.info Traffic of the WAN interface.") - if not os.environ.get('traffic_remove_max') or "false" in os.environ.get('traffic_remove_max'): - print("maxup.label MAX") - print("maxup.type GAUGE") - print("maxup.draw LINE1") - print("maxup.info Maximum up speed of the WAN interface.") - if os.environ.get('host_name'): - print("host_name " + os.environ['host_name']) - - -if __name__ == "__main__": - if len(sys.argv) == 2 and sys.argv[1] == 'config': - print_config() - elif len(sys.argv) == 2 and sys.argv[1] == 'autoconf': - print("yes") # Some docs say it'll be called with fetch, some say no arg at all - elif len(sys.argv) == 1 or (len(sys.argv) == 2 and sys.argv[1] == 'fetch'): - try: - print_values() - except: - sys.exit("Couldn't retrieve fritzbox traffic") +#!/usr/bin/env python +""" + fritzbox_traffic - A munin plugin for Linux to monitor AVM Fritzbox WAN traffic + Copyright (C) 2015 Christian Stade-Schuldt + Author: Christian Stade-Schuldt + + Updated to fritzconnection library version 1.3.1 + Copyright (C) 2020 Oliver Edelamnn + Author: Oliver Edelmann + + Like Munin, this plugin is licensed under the GNU GPL v2 license + http://www.opensource.org/licenses/GPL-2.0 + Like Munin, this plugin is licensed under the GNU GPL v2 license + http://www.opensource.org/licenses/GPL-2.0 + This plugin requires the fritzconnection plugin. To install it using pip: + pip install fritzconnection + This plugin supports the following munin configuration parameters: + #%# family=auto contrib + #%# capabilities=autoconf +""" + +import os +import sys + +from fritzconnection.lib.fritzstatus import FritzStatus + +hostname = os.path.basename(__file__).split('_')[1] + +def print_values(): + try: + conn = FritzStatus(address=hostname, password=os.environ['fritzbox_password']) + except Exception as e: + print(e) + sys.exit("Couldn't get WAN traffic") + + traffic = conn.transmission_rate + up = traffic[0]*8 + down = traffic[1]*8 + print('down.value %d' % down) + + print('up.value %d' % up) + + if not os.environ.get('traffic_remove_max') or "false" in os.environ.get('traffic_remove_max'): + max_traffic = conn.max_bit_rate + print('maxdown.value %d' % max_traffic[1]) + + print('maxup.value %d' % max_traffic[0]) + + +def print_config(): + try: + conn = FritzStatus(address=hostname, password=os.environ['fritzbox_password']) + except Exception as e: + print(e) + sys.exit("Couldn't get WAN traffic") + + max_traffic = conn.max_bit_rate + + print("host_name %s" % hostname) + print("graph_title AVM Fritz!Box WAN traffic") + print("graph_args --base 1000") + print("graph_vlabel bit up per ${graph_period}") + print("graph_category network") + print("graph_order up maxup") + print("up.label bps") + print("up.type GAUGE") + print("up.draw AREA") + print("up.min 0") + print("up.max %d" % max_traffic[1]) + print("up.warning %.0f" % (max_traffic[1]*0.6)) + print("up.critical %.0f" % (max_traffic[1]*0.8)) + print("up.info Traffic of the WAN interface.") + if not os.environ.get('traffic_remove_max') or "false" in os.environ.get('traffic_remove_max'): + print("maxup.label MAX") + print("maxup.type GAUGE") + print("maxup.draw LINE1") + print("maxup.info Maximum up speed of the WAN interface.") + if os.environ.get('host_name'): + print("host_name " + os.environ['host_name']) + + +if __name__ == "__main__": + if len(sys.argv) == 2 and sys.argv[1] == 'config': + print_config() + elif len(sys.argv) == 2 and sys.argv[1] == 'autoconf': + print("yes") # Some docs say it'll be called with fetch, some say no arg at all + elif len(sys.argv) == 1 or (len(sys.argv) == 2 and sys.argv[1] == 'fetch'): + try: + print_values() + except: + sys.exit("Couldn't retrieve fritzbox traffic") diff --git a/fritzbox__uptime.py b/fritzbox__uptime.py index a7ac41d..6463626 100644 --- a/fritzbox__uptime.py +++ b/fritzbox__uptime.py @@ -1,85 +1,85 @@ -#!/usr/bin/env python -""" - fritzbox_uptime - A munin plugin for Linux to monitor AVM Fritzbox - Copyright (C) 2015 Christian Stade-Schuldt - Author: Christian Stade-Schuldt - Like Munin, this plugin is licensed under the GNU GPL v2 license - http://www.opensource.org/licenses/GPL-2.0 - Add the following section to your munin-node's plugin configuration: - - [fritzbox_*] - env.fritzbox_ip [ip address of the fritzbox] - env.fritzbox_password [fritzbox password] - - This plugin supports the following munin configuration parameters: - #%# family=auto contrib - #%# capabilities=autoconf -""" -import json -import os -import re -import sys - -import fritzbox_helper as fh - -locale = os.environ.get('locale', 'de') -patternLoc = {"de": r"(\d+)\s(Tag|Stunden|Minuten)", - "en": r"(\d+)\s(days|hours|minutes)"} -dayLoc = {"de": "Tag", "en": "days"} -hourLoc = {"de": "Stunden", "en": "hours"} -minutesLoc = {"de": "Minuten", "en": "minutes"} - -PAGE = 'energy' -pattern = re.compile(patternLoc[locale]) -hostname = os.path.basename(__file__).split('_')[1] - - -def get_uptime(): - """get the current uptime""" - - server = hostname - password = os.environ['fritzbox_password'] - - session_id = fh.get_session_id(server, password) - xhr_data = fh.get_xhr_content(server, session_id, PAGE) - data = json.loads(xhr_data) - for d in data['data']['drain']: - if 'aktiv' in d['statuses']: - matches = re.finditer(pattern, d['statuses']) - if matches: - hours = 0.0 - for m in matches: - if m.group(2) == dayLoc[locale]: - hours += 24 * int(m.group(1)) - if m.group(2) == hourLoc[locale]: - hours += int(m.group(1)) - if m.group(2) == minutesLoc[locale]: - hours += int(m.group(1)) / 60.0 - uptime = hours / 24 - print("uptime.value %.2f" % uptime) - - -def print_config(): - print("host_name %s" % hostname) - print("graph_title AVM Fritz!Box Uptime") - print("graph_args --base 1000 -l 0") - print('graph_vlabel uptime in days') - print("graph_scale no'") - print("graph_category system") - print("uptime.label uptime") - print("uptime.draw AREA") - if os.environ.get('host_name'): - print("host_name " + os.environ['host_name']) - - -if __name__ == '__main__': - if len(sys.argv) == 2 and sys.argv[1] == 'config': - print_config() - elif len(sys.argv) == 2 and sys.argv[1] == 'autoconf': - print('yes') - elif len(sys.argv) == 1 or len(sys.argv) == 2 and sys.argv[1] == 'fetch': - # Some docs say it'll be called with fetch, some say no arg at all - try: - get_uptime() - except: - sys.exit("Couldn't retrieve fritzbox uptime") +#!/usr/bin/env python +""" + fritzbox_uptime - A munin plugin for Linux to monitor AVM Fritzbox + Copyright (C) 2015 Christian Stade-Schuldt + Author: Christian Stade-Schuldt + Like Munin, this plugin is licensed under the GNU GPL v2 license + http://www.opensource.org/licenses/GPL-2.0 + Add the following section to your munin-node's plugin configuration: + + [fritzbox_*] + env.fritzbox_ip [ip address of the fritzbox] + env.fritzbox_password [fritzbox password] + + This plugin supports the following munin configuration parameters: + #%# family=auto contrib + #%# capabilities=autoconf +""" +import json +import os +import re +import sys + +import fritzbox_helper as fh + +locale = os.environ.get('locale', 'de') +patternLoc = {"de": r"(\d+)\s(Tag|Stunden|Minuten)", + "en": r"(\d+)\s(days|hours|minutes)"} +dayLoc = {"de": "Tag", "en": "days"} +hourLoc = {"de": "Stunden", "en": "hours"} +minutesLoc = {"de": "Minuten", "en": "minutes"} + +PAGE = 'energy' +pattern = re.compile(patternLoc[locale]) +hostname = os.path.basename(__file__).split('_')[1] + + +def get_uptime(): + """get the current uptime""" + + server = hostname + password = os.environ['fritzbox_password'] + + session_id = fh.get_session_id(server, password) + xhr_data = fh.get_xhr_content(server, session_id, PAGE) + data = json.loads(xhr_data) + for d in data['data']['drain']: + if 'aktiv' in d['statuses']: + matches = re.finditer(pattern, d['statuses']) + if matches: + hours = 0.0 + for m in matches: + if m.group(2) == dayLoc[locale]: + hours += 24 * int(m.group(1)) + if m.group(2) == hourLoc[locale]: + hours += int(m.group(1)) + if m.group(2) == minutesLoc[locale]: + hours += int(m.group(1)) / 60.0 + uptime = hours / 24 + print("uptime.value %.2f" % uptime) + + +def print_config(): + print("host_name %s" % hostname) + print("graph_title AVM Fritz!Box Uptime") + print("graph_args --base 1000 -l 0") + print('graph_vlabel uptime in days') + print("graph_scale no'") + print("graph_category system") + print("uptime.label uptime") + print("uptime.draw AREA") + if os.environ.get('host_name'): + print("host_name " + os.environ['host_name']) + + +if __name__ == '__main__': + if len(sys.argv) == 2 and sys.argv[1] == 'config': + print_config() + elif len(sys.argv) == 2 and sys.argv[1] == 'autoconf': + print('yes') + elif len(sys.argv) == 1 or len(sys.argv) == 2 and sys.argv[1] == 'fetch': + # Some docs say it'll be called with fetch, some say no arg at all + try: + get_uptime() + except: + sys.exit("Couldn't retrieve fritzbox uptime") diff --git a/fritzbox__wifi_devices.py b/fritzbox__wifi_devices.py index 44875ad..f9efb9a 100644 --- a/fritzbox__wifi_devices.py +++ b/fritzbox__wifi_devices.py @@ -1,69 +1,69 @@ -#!/usr/bin/env python -""" - fritzbox_wifi_devices - A munin plugin for Linux to monitor AVM Fritzbox - Copyright (C) 2015 Christian Stade-Schuldt - Author: Christian Stade-Schuldt - - Updated to fritzconnection library version 1.3.1 - Copyright (C) 2020 Oliver Edelamnn - Author: Oliver Edelmann - - Like Munin, this plugin is licensed under the GNU GPL v2 license - http://www.opensource.org/licenses/GPL-2.0 - Add the following section to your munin-node's plugin configuration: - - [fritzbox_*] - env.fritzbox_ip [ip address of the fritzbox] - env.fritzbox_password [fritzbox password] - - This plugin supports the following munin configuration parameters: - #%# family=auto contrib - #%# capabilities=autoconf -""" -import os -import sys - -from fritzconnection.lib.fritzwlan import FritzWLAN - -hostname = os.path.basename(__file__).split('_')[1] - -def get_connected_wifi_devices(): - """gets the numbrer of currently connected wifi devices""" - - try: - conn = FritzWLAN(address=hostname, password=os.environ['fritzbox_password']) - except Exception as e: - print(e) - sys.exit("Couldn't get connection uptime") - - - connected_devices = conn.host_number - print('wifi.value %d' % connected_devices) - - -def print_config(): - print("host_name %s" % hostname) - print('graph_title AVM Fritz!Box Connected Wifi Devices') - print('graph_vlabel Number of devices') - print('graph_args --base 1000') - print('graph_category network') - print('graph_order wifi') - print('wifi.label Wifi Connections on 2.4 & 5 Ghz') - print('wifi.type GAUGE') - print('wifi.graph LINE1') - print('wifi.info Wifi Connections on 2.4 & 5 Ghz') - if os.environ.get('host_name'): - print("host_name " + os.environ['host_name']) - - -if __name__ == '__main__': - if len(sys.argv) == 2 and sys.argv[1] == 'config': - print_config() - elif len(sys.argv) == 2 and sys.argv[1] == 'autoconf': - print('yes') - elif len(sys.argv) == 1 or len(sys.argv) == 2 and sys.argv[1] == 'fetch': - # Some docs say it'll be called with fetch, some say no arg at all - try: - get_connected_wifi_devices() - except: - sys.exit("Couldn't retrieve connected fritzbox wifi devices") +#!/usr/bin/env python +""" + fritzbox_wifi_devices - A munin plugin for Linux to monitor AVM Fritzbox + Copyright (C) 2015 Christian Stade-Schuldt + Author: Christian Stade-Schuldt + + Updated to fritzconnection library version 1.3.1 + Copyright (C) 2020 Oliver Edelamnn + Author: Oliver Edelmann + + Like Munin, this plugin is licensed under the GNU GPL v2 license + http://www.opensource.org/licenses/GPL-2.0 + Add the following section to your munin-node's plugin configuration: + + [fritzbox_*] + env.fritzbox_ip [ip address of the fritzbox] + env.fritzbox_password [fritzbox password] + + This plugin supports the following munin configuration parameters: + #%# family=auto contrib + #%# capabilities=autoconf +""" +import os +import sys + +from fritzconnection.lib.fritzwlan import FritzWLAN + +hostname = os.path.basename(__file__).split('_')[1] + +def get_connected_wifi_devices(): + """gets the numbrer of currently connected wifi devices""" + + try: + conn = FritzWLAN(address=hostname, password=os.environ['fritzbox_password']) + except Exception as e: + print(e) + sys.exit("Couldn't get connection uptime") + + + connected_devices = conn.host_number + print('wifi.value %d' % connected_devices) + + +def print_config(): + print("host_name %s" % hostname) + print('graph_title AVM Fritz!Box Connected Wifi Devices') + print('graph_vlabel Number of devices') + print('graph_args --base 1000') + print('graph_category network') + print('graph_order wifi') + print('wifi.label Wifi Connections on 2.4 & 5 Ghz') + print('wifi.type GAUGE') + print('wifi.graph LINE1') + print('wifi.info Wifi Connections on 2.4 & 5 Ghz') + if os.environ.get('host_name'): + print("host_name " + os.environ['host_name']) + + +if __name__ == '__main__': + if len(sys.argv) == 2 and sys.argv[1] == 'config': + print_config() + elif len(sys.argv) == 2 and sys.argv[1] == 'autoconf': + print('yes') + elif len(sys.argv) == 1 or len(sys.argv) == 2 and sys.argv[1] == 'fetch': + # Some docs say it'll be called with fetch, some say no arg at all + try: + get_connected_wifi_devices() + except: + sys.exit("Couldn't retrieve connected fritzbox wifi devices") diff --git a/fritzbox_helper.py b/fritzbox_helper.py index 876300d..7c9fcd3 100644 --- a/fritzbox_helper.py +++ b/fritzbox_helper.py @@ -1,137 +1,137 @@ -#!/usr/bin/env python -""" - fritzbox_helper - A munin plugin for Linux to monitor AVM Fritzbox - Copyright (C) 2015 Christian Stade-Schuldt - Author: Christian Stade-Schuldt - Like Munin, this plugin is licensed under the GNU GPL v2 license - http://www.opensource.org/licenses/GPL-2.0 - Add the following section to your munin-node's plugin configuration: - - [fritzbox_*] - env.fritzbox_ip [ip address of the fritzbox] - env.fritzbox_password [fritzbox password] - - This plugin supports the following munin configuration parameters: - #%# family=auto contrib - #%# capabilities=autoconf - - The initial script was inspired by - https://www.linux-tips-and-tricks.de/en/programming/389-read-data-from-a-fritzbox-7390-with-python-and-bash - framp at linux-tips-and-tricks dot de -""" - -import hashlib -import sys - -import requests -from lxml import etree - -USER_AGENT = "Mozilla/5.0 (Macintosh; Intel Mac OS X x.y; rv:10.0) Gecko/20100101 Firefox/10.0" - - -def get_session_id(server, password, port=80): - """Obtains the session id after login into the Fritzbox. - See https://avm.de/fileadmin/user_upload/Global/Service/Schnittstellen/AVM_Technical_Note_-_Session_ID.pdf - for deteils (in German). - - :param server: the ip address of the Fritzbox - :param password: the password to log into the Fritzbox webinterface - :param port: the port the Fritzbox webserver runs on - :return: the session id - """ - - headers = {"Accept": "application/xml", - "Content-Type": "text/plain", - "User-Agent": USER_AGENT} - - url = 'http://{}:{}/login_sid.lua'.format(server, port) - try: - r = requests.get(url, headers=headers) - r.raise_for_status() - except requests.exceptions.HTTPError as err: - print(err) - sys.exit(1) - - root = etree.fromstring(r.content) - session_id = root.xpath('//SessionInfo/SID/text()')[0] - if session_id == "0000000000000000": - challenge = root.xpath('//SessionInfo/Challenge/text()')[0] - challenge_bf = ('{}-{}'.format(challenge, password)).encode('utf-16le') - m = hashlib.md5() - m.update(challenge_bf) - response_bf = '{}-{}'.format(challenge, m.hexdigest().lower()) - else: - return session_id - - headers = {"Accept": "text/html,application/xhtml+xml,application/xml", - "Content-Type": "application/x-www-form-urlencoded", - "User-Agent": USER_AGENT} - - url = 'http://{}:{}/login_sid.lua?&response={}'.format(server, port, response_bf) - try: - r = requests.get(url, headers=headers) - r.raise_for_status() - except requests.exceptions.HTTPError as err: - print(err) - sys.exit(1) - - root = etree.fromstring(r.content) - session_id = root.xpath('//SessionInfo/SID/text()')[0] - if session_id == "0000000000000000": - print("ERROR - No SID received because of invalid password") - sys.exit(0) - return session_id - - -def get_page_content(server, session_id, page, port=80): - """Fetches a page from the Fritzbox and returns its content - - :param server: the ip address of the Fritzbox - :param session_id: a valid session id - :param page: the page you are regquesting - :param port: the port the Fritzbox webserver runs on - :return: the content of the page - """ - - headers = {"Accept": "application/xml", - "Content-Type": "text/plain", - "User-Agent": USER_AGENT} - - url = 'http://{}:{}/{}?sid={}'.format(server, port, page, session_id) - try: - r = requests.get(url, headers=headers) - r.raise_for_status() - except requests.exceptions.HTTPError as err: - print(err) - sys.exit(1) - return r.content - - -def get_xhr_content(server, session_id, page, port=80): - """Fetches the xhr content from the Fritzbox and returns its content - - :param server: the ip address of the Fritzbox - :param session_id: a valid session id - :param page: the page you are regquesting - :param port: the port the Fritzbox webserver runs on - :return: the content of the page - """ - - headers = {"Accept": "application/xml", - "Content-Type": "application/x-www-form-urlencoded", - "User-Agent": USER_AGENT} - - url = 'http://{}:{}/data.lua'.format(server, port) - data = {"xhr": 1, - "sid": session_id, - "lang": "en", - "page": page, - "xhrId": "all", - "no_sidrenew": "" - } - try: - r = requests.post(url, data=data, headers=headers) - except requests.exceptions.HTTPError as err: - print(err) - sys.exit(1) - return r.content +#!/usr/bin/env python +""" + fritzbox_helper - A munin plugin for Linux to monitor AVM Fritzbox + Copyright (C) 2015 Christian Stade-Schuldt + Author: Christian Stade-Schuldt + Like Munin, this plugin is licensed under the GNU GPL v2 license + http://www.opensource.org/licenses/GPL-2.0 + Add the following section to your munin-node's plugin configuration: + + [fritzbox_*] + env.fritzbox_ip [ip address of the fritzbox] + env.fritzbox_password [fritzbox password] + + This plugin supports the following munin configuration parameters: + #%# family=auto contrib + #%# capabilities=autoconf + + The initial script was inspired by + https://www.linux-tips-and-tricks.de/en/programming/389-read-data-from-a-fritzbox-7390-with-python-and-bash + framp at linux-tips-and-tricks dot de +""" + +import hashlib +import sys + +import requests +from lxml import etree + +USER_AGENT = "Mozilla/5.0 (Macintosh; Intel Mac OS X x.y; rv:10.0) Gecko/20100101 Firefox/10.0" + + +def get_session_id(server, password, port=80): + """Obtains the session id after login into the Fritzbox. + See https://avm.de/fileadmin/user_upload/Global/Service/Schnittstellen/AVM_Technical_Note_-_Session_ID.pdf + for deteils (in German). + + :param server: the ip address of the Fritzbox + :param password: the password to log into the Fritzbox webinterface + :param port: the port the Fritzbox webserver runs on + :return: the session id + """ + + headers = {"Accept": "application/xml", + "Content-Type": "text/plain", + "User-Agent": USER_AGENT} + + url = 'http://{}:{}/login_sid.lua'.format(server, port) + try: + r = requests.get(url, headers=headers) + r.raise_for_status() + except requests.exceptions.HTTPError as err: + print(err) + sys.exit(1) + + root = etree.fromstring(r.content) + session_id = root.xpath('//SessionInfo/SID/text()')[0] + if session_id == "0000000000000000": + challenge = root.xpath('//SessionInfo/Challenge/text()')[0] + challenge_bf = ('{}-{}'.format(challenge, password)).encode('utf-16le') + m = hashlib.md5() + m.update(challenge_bf) + response_bf = '{}-{}'.format(challenge, m.hexdigest().lower()) + else: + return session_id + + headers = {"Accept": "text/html,application/xhtml+xml,application/xml", + "Content-Type": "application/x-www-form-urlencoded", + "User-Agent": USER_AGENT} + + url = 'http://{}:{}/login_sid.lua?&response={}'.format(server, port, response_bf) + try: + r = requests.get(url, headers=headers) + r.raise_for_status() + except requests.exceptions.HTTPError as err: + print(err) + sys.exit(1) + + root = etree.fromstring(r.content) + session_id = root.xpath('//SessionInfo/SID/text()')[0] + if session_id == "0000000000000000": + print("ERROR - No SID received because of invalid password") + sys.exit(0) + return session_id + + +def get_page_content(server, session_id, page, port=80): + """Fetches a page from the Fritzbox and returns its content + + :param server: the ip address of the Fritzbox + :param session_id: a valid session id + :param page: the page you are regquesting + :param port: the port the Fritzbox webserver runs on + :return: the content of the page + """ + + headers = {"Accept": "application/xml", + "Content-Type": "text/plain", + "User-Agent": USER_AGENT} + + url = 'http://{}:{}/{}?sid={}'.format(server, port, page, session_id) + try: + r = requests.get(url, headers=headers) + r.raise_for_status() + except requests.exceptions.HTTPError as err: + print(err) + sys.exit(1) + return r.content + + +def get_xhr_content(server, session_id, page, port=80): + """Fetches the xhr content from the Fritzbox and returns its content + + :param server: the ip address of the Fritzbox + :param session_id: a valid session id + :param page: the page you are regquesting + :param port: the port the Fritzbox webserver runs on + :return: the content of the page + """ + + headers = {"Accept": "application/xml", + "Content-Type": "application/x-www-form-urlencoded", + "User-Agent": USER_AGENT} + + url = 'http://{}:{}/data.lua'.format(server, port) + data = {"xhr": 1, + "sid": session_id, + "lang": "en", + "page": page, + "xhrId": "all", + "no_sidrenew": "" + } + try: + r = requests.post(url, data=data, headers=headers) + except requests.exceptions.HTTPError as err: + print(err) + sys.exit(1) + return r.content