diff --git a/README.md b/README.md index 690c5ae..e08b648 100644 --- a/README.md +++ b/README.md @@ -1,26 +1,9 @@ # fritzbox-munin -A collection of munin plugins to monitor your AVM FRITZ!Box router. The scripts have been developed using a [FRITZ!Box 7590](http://geni.us/OO2c7S)(Amazon link) running FRITZ!OS 7.00. +A collection of munin plugins to monitor your AVM FRITZ!Box router. The scripts have been developed using a [FRITZ!Box 7490](http://geni.us/OO2c7S)(Amazon link) running FRITZ!OS 07.12. If you are using the scripts on a different Fritz!Box model please let me know by -- opening an issue -- submitting a pull request - - So far the following models (running FRITZ!OS 06.83) have been confirmed working: - -- [FRITZ!Box 3370](http://geni.us/zh3U) -- [FRITZ!Box 5490](http://geni.us/ACtUyFt) -- [FRITZ!Box 7362 SL](http://geni.us/fTyoY) -- [FRITZ!Box 7390](http://geni.us/BlAP) -- [FRITZ!Box 7430](http://geni.us/BlAP) -- [FRITZ!Box 7490](http://geni.us/fTyoY) -- [FRITZ!Box 7560](http://geni.us/6gPZNI) -- [FRITZ!Box 7580](http://geni.us/yUYyQTE) -- [FRITZ!Box 7590](http://geni.us/OO2c7S) - - If you are still running Fritz!OS 6.30 check out the [releases section](https://github.com/Tafkas/fritzbox-munin/releases/tag/6.30.1). - ## Introduction These python scripts are [Munin](http://munin-monitoring.org) plugins for monitoring the [Fritz!Box](http://avm.de/produkte/fritzbox/) router by AVM. @@ -74,25 +57,61 @@ If you are using the scripts on a different Fritz!Box model please let me know b 1. Pre-requesites for the fritzbox\_traffic and fritzbox\_uptime plugins are the [fritzconnection](https://pypi.python.org/pypi/fritzconnection) and [requests](https://pypi.python.org/pypi/requests) package. To install it pip install fritzconnection - pip install requests + pip install lxml 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) - [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 entry in `/etc/munin/plugin-conf.d/munin-node`: + 1. only one fritzbox or all fritzboxes use the same password: -5. Create symbolic links to `/etc/munin/plugins`. + [fritzbox_*] + env.fritzbox_password + env.traffic_remove_max true # if you do not want the possible max values + + 2. multiple fritzboxes: + + [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 multiple fritz box just create multiple 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 +125,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 fritzboxes -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 old mode 100755 new mode 100644 similarity index 90% rename from fritzbox_connection_uptime.py rename to fritzbox__connection_uptime.py index 9721fa6..b36d76f --- a/fritzbox_connection_uptime.py +++ b/fritzbox__connection_uptime.py @@ -24,11 +24,12 @@ import sys from fritzconnection.lib.fritzstatus import FritzStatus +hostname = os.path.basename(__file__).split('_')[1] def print_values(): try: - conn = FritzStatus(address=os.environ['fritzbox_ip'], password=os.environ['fritzbox_password']) - except Exception as e: + conn = FritzStatus(address=hostname, password=os.environ['fritzbox_password']) + except Exception: sys.exit("Couldn't get connection uptime") uptime = conn.uptime @@ -36,6 +37,7 @@ def print_values(): 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') diff --git a/fritzbox_cpu_temperature.py b/fritzbox__cpu_temperature.py old mode 100755 new mode 100644 similarity index 94% rename from fritzbox_cpu_temperature.py rename to fritzbox__cpu_temperature.py index d38015a..e608c72 --- a/fritzbox_cpu_temperature.py +++ b/fritzbox__cpu_temperature.py @@ -21,12 +21,13 @@ 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 = os.environ['fritzbox_ip'] + server = hostname password = os.environ['fritzbox_password'] session_id = fh.get_session_id(server, password) @@ -36,6 +37,7 @@ def get_cpu_temperature(): 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") diff --git a/fritzbox_cpu_usage.py b/fritzbox__cpu_usage.py old mode 100755 new mode 100644 similarity index 94% rename from fritzbox_cpu_usage.py rename to fritzbox__cpu_usage.py index 4f56321..9109844 --- a/fritzbox_cpu_usage.py +++ b/fritzbox__cpu_usage.py @@ -21,12 +21,13 @@ 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 = os.environ['fritzbox_ip'] + server = hostname password = os.environ['fritzbox_password'] session_id = fh.get_session_id(server, password) @@ -36,6 +37,7 @@ def get_cpu_usage(): def print_config(): + print("host_name %s" % hostname) print("graph_title AVM Fritz!Box CPU usage") print("graph_vlabel %") print("graph_category system") diff --git a/fritzbox_memory_usage.py b/fritzbox__memory_usage.py old mode 100755 new mode 100644 similarity index 95% rename from fritzbox_memory_usage.py rename to fritzbox__memory_usage.py index a73d13b..868ce43 --- a/fritzbox_memory_usage.py +++ b/fritzbox__memory_usage.py @@ -22,12 +22,13 @@ 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 = os.environ['fritzbox_ip'] + server = hostname password = os.environ['fritzbox_password'] session_id = fh.get_session_id(server, password) @@ -38,6 +39,7 @@ def get_memory_usage(): 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") diff --git a/fritzbox_power_consumption.py b/fritzbox__power_consumption.py old mode 100755 new mode 100644 similarity index 96% rename from fritzbox_power_consumption.py rename to fritzbox__power_consumption.py index 9d71a76..8f1a143 --- a/fritzbox_power_consumption.py +++ b/fritzbox__power_consumption.py @@ -24,12 +24,12 @@ 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 = os.environ['fritzbox_ip'] + server = hostname password = os.environ['fritzbox_password'] session_id = fh.get_session_id(server, password) @@ -41,6 +41,7 @@ def get_power_consumption(): def print_config(): + print("host_name %s" % hostname) print("graph_title AVM Fritz!Box Power Consumption") print("graph_vlabel %") print("graph_category system") diff --git a/fritzbox_traffic.py b/fritzbox__traffic.py old mode 100755 new mode 100644 similarity index 85% rename from fritzbox_traffic.py rename to fritzbox__traffic.py index a8122fd..73fe90a --- a/fritzbox_traffic.py +++ b/fritzbox__traffic.py @@ -24,15 +24,18 @@ import sys from fritzconnection.lib.fritzstatus import FritzStatus +hostname = os.path.basename(__file__).split('_')[1] + def print_values(): try: - conn = FritzStatus(address=os.environ['fritzbox_ip'], password=os.environ['fritzbox_password']) + 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] - down = traffic[1] + up = traffic[0]*8 + down = traffic[1]*8 print('down.value %d' % down) print('up.value %d' % up) @@ -46,29 +49,31 @@ def print_values(): def print_config(): try: - conn = FritzStatus(address=os.environ['fritzbox_ip'], password=os.environ['fritzbox_password']) + 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_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 DERIVE") + print("down.type GAUGE") print("down.graph no") - print("down.cdef down,8,*") + #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 DERIVE") + print("up.type GAUGE") print("up.draw AREA") - print("up.cdef up,8,*") + #print("up.cdef up,8,*") print("up.min 0") print("up.max %d" % max_traffic[0]) print("up.negative down") diff --git a/fritzbox__traffic_down.py b/fritzbox__traffic_down.py new file mode 100644 index 0000000..3d8ecd0 --- /dev/null +++ b/fritzbox__traffic_down.py @@ -0,0 +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") diff --git a/fritzbox__traffic_up.py b/fritzbox__traffic_up.py new file mode 100644 index 0000000..42fe5c4 --- /dev/null +++ b/fritzbox__traffic_up.py @@ -0,0 +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") diff --git a/fritzbox_uptime.py b/fritzbox__uptime.py old mode 100755 new mode 100644 similarity index 96% rename from fritzbox_uptime.py rename to fritzbox__uptime.py index 649c0d0..6463626 --- a/fritzbox_uptime.py +++ b/fritzbox__uptime.py @@ -31,12 +31,13 @@ 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 = os.environ['fritzbox_ip'] + server = hostname password = os.environ['fritzbox_password'] session_id = fh.get_session_id(server, password) @@ -59,6 +60,7 @@ def get_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') diff --git a/fritzbox_wifi_devices.py b/fritzbox__wifi_devices.py old mode 100755 new mode 100644 similarity index 91% rename from fritzbox_wifi_devices.py rename to fritzbox__wifi_devices.py index 180eb73..f9efb9a --- a/fritzbox_wifi_devices.py +++ b/fritzbox__wifi_devices.py @@ -25,13 +25,15 @@ 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=os.environ['fritzbox_ip'], password=os.environ['fritzbox_password']) + conn = FritzWLAN(address=hostname, password=os.environ['fritzbox_password']) except Exception as e: + print(e) sys.exit("Couldn't get connection uptime") @@ -40,6 +42,7 @@ def get_connected_wifi_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') diff --git a/fritzbox_helper.py b/fritzbox_helper.py old mode 100755 new mode 100644