From c4642ccbf3ff83fea8be70a3c3a6bb6955c93b04 Mon Sep 17 00:00:00 2001 From: oe73773 Date: Thu, 9 Jul 2020 20:11:01 +0200 Subject: [PATCH 01/17] initial commit --- fritzbox_connection_uptime.py | 59 -------------------- fritzbox_cpu_temperature.py | 60 -------------------- fritzbox_cpu_usage.py | 63 --------------------- fritzbox_memory_usage.py | 71 ------------------------ fritzbox_power_consumption.py | 98 --------------------------------- fritzbox_traffic.py | 100 ---------------------------------- fritzbox_uptime.py | 83 ---------------------------- fritzbox_wifi_devices.py | 66 ---------------------- 8 files changed, 600 deletions(-) delete mode 100755 fritzbox_connection_uptime.py delete mode 100755 fritzbox_cpu_temperature.py delete mode 100755 fritzbox_cpu_usage.py delete mode 100755 fritzbox_memory_usage.py delete mode 100755 fritzbox_power_consumption.py delete mode 100755 fritzbox_traffic.py delete mode 100755 fritzbox_uptime.py delete mode 100755 fritzbox_wifi_devices.py diff --git a/fritzbox_connection_uptime.py b/fritzbox_connection_uptime.py deleted file mode 100755 index 9721fa6..0000000 --- a/fritzbox_connection_uptime.py +++ /dev/null @@ -1,59 +0,0 @@ -#!/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 - - -def print_values(): - try: - conn = FritzStatus(address=os.environ['fritzbox_ip'], password=os.environ['fritzbox_password']) - except Exception as e: - sys.exit("Couldn't get connection uptime") - - uptime = conn.uptime - print('uptime.value %.2f' % (int(uptime) / 3600.0)) - - -def print_config(): - 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 deleted file mode 100755 index d38015a..0000000 --- a/fritzbox_cpu_temperature.py +++ /dev/null @@ -1,60 +0,0 @@ -#!/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' - - -def get_cpu_temperature(): - """get the current cpu temperature""" - - server = os.environ['fritzbox_ip'] - 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("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 deleted file mode 100755 index 4f56321..0000000 --- a/fritzbox_cpu_usage.py +++ /dev/null @@ -1,63 +0,0 @@ -#!/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' - - -def get_cpu_usage(): - """get the current cpu usage""" - - server = os.environ['fritzbox_ip'] - 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("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 deleted file mode 100755 index a73d13b..0000000 --- a/fritzbox_memory_usage.py +++ /dev/null @@ -1,71 +0,0 @@ -#!/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'] - - -def get_memory_usage(): - """get the current memory usage""" - - server = os.environ['fritzbox_ip'] - 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("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 deleted file mode 100755 index 9d71a76..0000000 --- a/fritzbox_power_consumption.py +++ /dev/null @@ -1,98 +0,0 @@ -#!/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'] - - -def get_power_consumption(): - """get the current power consumption usage""" - - server = os.environ['fritzbox_ip'] - 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("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 deleted file mode 100755 index a8122fd..0000000 --- a/fritzbox_traffic.py +++ /dev/null @@ -1,100 +0,0 @@ -#!/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 - -def print_values(): - try: - conn = FritzStatus(address=os.environ['fritzbox_ip'], password=os.environ['fritzbox_password']) - except Exception as e: - sys.exit("Couldn't get WAN traffic") - - traffic = conn.transmission_rate - up = traffic[0] - down = traffic[1] - 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=os.environ['fritzbox_ip'], password=os.environ['fritzbox_password']) - except Exception as e: - sys.exit("Couldn't get WAN traffic") - - max_traffic = conn.max_bit_rate - - 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 DERIVE") - 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 DERIVE") - 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_uptime.py b/fritzbox_uptime.py deleted file mode 100755 index 649c0d0..0000000 --- a/fritzbox_uptime.py +++ /dev/null @@ -1,83 +0,0 @@ -#!/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]) - - -def get_uptime(): - """get the current uptime""" - - server = os.environ['fritzbox_ip'] - 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("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 deleted file mode 100755 index 180eb73..0000000 --- a/fritzbox_wifi_devices.py +++ /dev/null @@ -1,66 +0,0 @@ -#!/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 - - -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']) - except Exception as e: - sys.exit("Couldn't get connection uptime") - - - connected_devices = conn.host_number - print('wifi.value %d' % connected_devices) - - -def print_config(): - 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") From c8137c2145883f05b2e800c10309281ffc6a5085 Mon Sep 17 00:00:00 2001 From: oe73773 Date: Thu, 9 Jul 2020 20:13:04 +0200 Subject: [PATCH 02/17] new filenames --- fritzbox__connection_uptime.py | 59 ++++++++++++++ fritzbox__cpu_temperature.py | 60 +++++++++++++++ fritzbox__cpu_usage.py | 63 +++++++++++++++ fritzbox__memory_usage.py | 71 +++++++++++++++++ fritzbox__power_consumption.py | 98 +++++++++++++++++++++++ fritzbox__traffic.py | 100 ++++++++++++++++++++++++ fritzbox__uptime.py | 83 ++++++++++++++++++++ fritzbox__wifi_devices.py | 66 ++++++++++++++++ fritzbox_helper.py | 137 --------------------------------- 9 files changed, 600 insertions(+), 137 deletions(-) create mode 100755 fritzbox__connection_uptime.py create mode 100755 fritzbox__cpu_temperature.py create mode 100755 fritzbox__cpu_usage.py create mode 100755 fritzbox__memory_usage.py create mode 100755 fritzbox__power_consumption.py create mode 100755 fritzbox__traffic.py create mode 100755 fritzbox__uptime.py create mode 100755 fritzbox__wifi_devices.py delete mode 100755 fritzbox_helper.py diff --git a/fritzbox__connection_uptime.py b/fritzbox__connection_uptime.py new file mode 100755 index 0000000..9721fa6 --- /dev/null +++ b/fritzbox__connection_uptime.py @@ -0,0 +1,59 @@ +#!/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 + + +def print_values(): + try: + conn = FritzStatus(address=os.environ['fritzbox_ip'], password=os.environ['fritzbox_password']) + except Exception as e: + sys.exit("Couldn't get connection uptime") + + uptime = conn.uptime + print('uptime.value %.2f' % (int(uptime) / 3600.0)) + + +def print_config(): + 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 new file mode 100755 index 0000000..d38015a --- /dev/null +++ b/fritzbox__cpu_temperature.py @@ -0,0 +1,60 @@ +#!/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' + + +def get_cpu_temperature(): + """get the current cpu temperature""" + + server = os.environ['fritzbox_ip'] + 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("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 new file mode 100755 index 0000000..4f56321 --- /dev/null +++ b/fritzbox__cpu_usage.py @@ -0,0 +1,63 @@ +#!/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' + + +def get_cpu_usage(): + """get the current cpu usage""" + + server = os.environ['fritzbox_ip'] + 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("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 new file mode 100755 index 0000000..a73d13b --- /dev/null +++ b/fritzbox__memory_usage.py @@ -0,0 +1,71 @@ +#!/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'] + + +def get_memory_usage(): + """get the current memory usage""" + + server = os.environ['fritzbox_ip'] + 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("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 new file mode 100755 index 0000000..9d71a76 --- /dev/null +++ b/fritzbox__power_consumption.py @@ -0,0 +1,98 @@ +#!/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'] + + +def get_power_consumption(): + """get the current power consumption usage""" + + server = os.environ['fritzbox_ip'] + 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("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 new file mode 100755 index 0000000..a8122fd --- /dev/null +++ b/fritzbox__traffic.py @@ -0,0 +1,100 @@ +#!/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 + +def print_values(): + try: + conn = FritzStatus(address=os.environ['fritzbox_ip'], password=os.environ['fritzbox_password']) + except Exception as e: + sys.exit("Couldn't get WAN traffic") + + traffic = conn.transmission_rate + up = traffic[0] + down = traffic[1] + 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=os.environ['fritzbox_ip'], password=os.environ['fritzbox_password']) + except Exception as e: + sys.exit("Couldn't get WAN traffic") + + max_traffic = conn.max_bit_rate + + 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 DERIVE") + 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 DERIVE") + 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__uptime.py b/fritzbox__uptime.py new file mode 100755 index 0000000..649c0d0 --- /dev/null +++ b/fritzbox__uptime.py @@ -0,0 +1,83 @@ +#!/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]) + + +def get_uptime(): + """get the current uptime""" + + server = os.environ['fritzbox_ip'] + 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("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 new file mode 100755 index 0000000..180eb73 --- /dev/null +++ b/fritzbox__wifi_devices.py @@ -0,0 +1,66 @@ +#!/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 + + +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']) + except Exception as e: + sys.exit("Couldn't get connection uptime") + + + connected_devices = conn.host_number + print('wifi.value %d' % connected_devices) + + +def print_config(): + 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 deleted file mode 100755 index 7c9fcd3..0000000 --- a/fritzbox_helper.py +++ /dev/null @@ -1,137 +0,0 @@ -#!/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 From e34cd24e3343425edab331c14d06f043f6817c24 Mon Sep 17 00:00:00 2001 From: oe73773 Date: Sat, 11 Jul 2020 16:55:26 +0200 Subject: [PATCH 03/17] test multi box support --- fritzbox_helper.py | 137 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 137 insertions(+) create mode 100755 fritzbox_helper.py diff --git a/fritzbox_helper.py b/fritzbox_helper.py new file mode 100755 index 0000000..876300d --- /dev/null +++ b/fritzbox_helper.py @@ -0,0 +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 From 2f1c80fcb5377fce0dbbbb4999340cc740d82b11 Mon Sep 17 00:00:00 2001 From: oe73773 Date: Sat, 11 Jul 2020 16:56:32 +0200 Subject: [PATCH 04/17] test multi box support --- fritzbox__connection_uptime.py | 4 +++- fritzbox__cpu_temperature.py | 2 ++ fritzbox__cpu_usage.py | 4 +++- fritzbox__memory_usage.py | 2 ++ fritzbox__power_consumption.py | 2 ++ fritzbox__traffic.py | 2 ++ fritzbox__uptime.py | 2 ++ fritzbox__wifi_devices.py | 2 ++ 8 files changed, 18 insertions(+), 2 deletions(-) diff --git a/fritzbox__connection_uptime.py b/fritzbox__connection_uptime.py index 9721fa6..b71106c 100755 --- a/fritzbox__connection_uptime.py +++ b/fritzbox__connection_uptime.py @@ -28,7 +28,7 @@ from fritzconnection.lib.fritzstatus import FritzStatus def print_values(): try: conn = FritzStatus(address=os.environ['fritzbox_ip'], password=os.environ['fritzbox_password']) - except Exception as e: + except Exception: sys.exit("Couldn't get connection uptime") uptime = conn.uptime @@ -36,6 +36,8 @@ def print_values(): def print_config(): + hostname = os.path.basename(__file__).split('_')[1] + 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 index d38015a..02670c1 100755 --- a/fritzbox__cpu_temperature.py +++ b/fritzbox__cpu_temperature.py @@ -36,6 +36,8 @@ def get_cpu_temperature(): def print_config(): + hostname = os.path.basename(__file__).split('_')[1] + 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 index 4f56321..5ac8a0d 100755 --- a/fritzbox__cpu_usage.py +++ b/fritzbox__cpu_usage.py @@ -20,7 +20,7 @@ import os import sys import fritzbox_helper as fh -PAGE = 'ecoStat' +PAGE = { '7': 'ecoStat', '6': 'system/ecostat.lua' } def get_cpu_usage(): @@ -36,6 +36,8 @@ def get_cpu_usage(): def print_config(): + hostname = os.path.basename(__file__).split('_')[1] + 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 index a73d13b..d91bc3f 100755 --- a/fritzbox__memory_usage.py +++ b/fritzbox__memory_usage.py @@ -38,6 +38,8 @@ def get_memory_usage(): def print_config(): + hostname = os.path.basename(__file__).split('_')[1] + 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 index 9d71a76..f7c290f 100755 --- a/fritzbox__power_consumption.py +++ b/fritzbox__power_consumption.py @@ -41,6 +41,8 @@ def get_power_consumption(): def print_config(): + hostname = os.path.basename(__file__).split('_')[1] + 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 index a8122fd..810196b 100755 --- a/fritzbox__traffic.py +++ b/fritzbox__traffic.py @@ -52,6 +52,8 @@ def print_config(): max_traffic = conn.max_bit_rate + hostname = os.path.basename(__file__).split('_')[1] + 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}") diff --git a/fritzbox__uptime.py b/fritzbox__uptime.py index 649c0d0..1a71c5d 100755 --- a/fritzbox__uptime.py +++ b/fritzbox__uptime.py @@ -59,6 +59,8 @@ def get_uptime(): def print_config(): + hostname = os.path.basename(__file__).split('_')[1] + 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 index 180eb73..c47cd96 100755 --- a/fritzbox__wifi_devices.py +++ b/fritzbox__wifi_devices.py @@ -40,6 +40,8 @@ def get_connected_wifi_devices(): def print_config(): + hostname = os.path.basename(__file__).split('_')[1] + 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') From aa12d83859691d1f9f70e4cad2365b56d097990e Mon Sep 17 00:00:00 2001 From: oe73773 Date: Sat, 11 Jul 2020 17:16:00 +0200 Subject: [PATCH 05/17] current traffic value fixed --- fritzbox__traffic.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/fritzbox__traffic.py b/fritzbox__traffic.py index 810196b..d55a4aa 100755 --- a/fritzbox__traffic.py +++ b/fritzbox__traffic.py @@ -31,8 +31,8 @@ def print_values(): 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) @@ -62,7 +62,7 @@ def print_config(): print("down.label received") print("down.type DERIVE") 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)) @@ -70,7 +70,7 @@ def print_config(): print("up.label bps") print("up.type DERIVE") 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") From 5c48631405720d46dce0611f7be79a879274e7db Mon Sep 17 00:00:00 2001 From: oe73773 Date: Sat, 11 Jul 2020 18:00:44 +0200 Subject: [PATCH 06/17] hostname fixed --- README.md | 2 +- fritzbox__connection_uptime.py | 4 ++-- fritzbox__cpu_temperature.py | 4 ++-- fritzbox__cpu_usage.py | 6 +++--- fritzbox__memory_usage.py | 4 ++-- fritzbox__power_consumption.py | 5 ++--- fritzbox__traffic.py | 9 ++++++--- fritzbox__uptime.py | 4 ++-- fritzbox__wifi_devices.py | 5 +++-- 9 files changed, 23 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 690c5ae..9c3b821 100644 --- a/README.md +++ b/README.md @@ -74,7 +74,7 @@ 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) diff --git a/fritzbox__connection_uptime.py b/fritzbox__connection_uptime.py index b71106c..b36d76f 100755 --- a/fritzbox__connection_uptime.py +++ b/fritzbox__connection_uptime.py @@ -24,10 +24,11 @@ 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: sys.exit("Couldn't get connection uptime") @@ -36,7 +37,6 @@ def print_values(): def print_config(): - hostname = os.path.basename(__file__).split('_')[1] print("host_name %s" % hostname) print("graph_title AVM Fritz!Box Connection Uptime") print("graph_args --base 1000 -l 0") diff --git a/fritzbox__cpu_temperature.py b/fritzbox__cpu_temperature.py index 02670c1..e608c72 100755 --- 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,7 +37,6 @@ def get_cpu_temperature(): def print_config(): - hostname = os.path.basename(__file__).split('_')[1] print("host_name %s" % hostname) print("graph_title AVM Fritz!Box CPU temperature") print("graph_vlabel degrees Celsius") diff --git a/fritzbox__cpu_usage.py b/fritzbox__cpu_usage.py index 5ac8a0d..9109844 100755 --- a/fritzbox__cpu_usage.py +++ b/fritzbox__cpu_usage.py @@ -20,13 +20,14 @@ import os import sys import fritzbox_helper as fh -PAGE = { '7': 'ecoStat', '6': 'system/ecostat.lua' } +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,7 +37,6 @@ def get_cpu_usage(): def print_config(): - hostname = os.path.basename(__file__).split('_')[1] print("host_name %s" % hostname) print("graph_title AVM Fritz!Box CPU usage") print("graph_vlabel %") diff --git a/fritzbox__memory_usage.py b/fritzbox__memory_usage.py index d91bc3f..868ce43 100755 --- 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,7 +39,6 @@ def get_memory_usage(): def print_config(): - hostname = os.path.basename(__file__).split('_')[1] print("host_name %s" % hostname) print("graph_title AVM Fritz!Box Memory") print("graph_vlabel %") diff --git a/fritzbox__power_consumption.py b/fritzbox__power_consumption.py index f7c290f..8f1a143 100755 --- 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,7 +41,6 @@ def get_power_consumption(): def print_config(): - hostname = os.path.basename(__file__).split('_')[1] print("host_name %s" % hostname) print("graph_title AVM Fritz!Box Power Consumption") print("graph_vlabel %") diff --git a/fritzbox__traffic.py b/fritzbox__traffic.py index d55a4aa..2c6c83a 100755 --- a/fritzbox__traffic.py +++ b/fritzbox__traffic.py @@ -24,10 +24,13 @@ 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 @@ -46,13 +49,13 @@ 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 - hostname = os.path.basename(__file__).split('_')[1] print("host_name %s" % hostname) print("graph_title AVM Fritz!Box WAN traffic") print("graph_args --base 1000") diff --git a/fritzbox__uptime.py b/fritzbox__uptime.py index 1a71c5d..6463626 100755 --- 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,7 +60,6 @@ def get_uptime(): def print_config(): - hostname = os.path.basename(__file__).split('_')[1] print("host_name %s" % hostname) print("graph_title AVM Fritz!Box Uptime") print("graph_args --base 1000 -l 0") diff --git a/fritzbox__wifi_devices.py b/fritzbox__wifi_devices.py index c47cd96..f9efb9a 100755 --- 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,7 +42,6 @@ def get_connected_wifi_devices(): def print_config(): - hostname = os.path.basename(__file__).split('_')[1] print("host_name %s" % hostname) print('graph_title AVM Fritz!Box Connected Wifi Devices') print('graph_vlabel Number of devices') From 4edc011e48d85063d1d7f914e95d581a724d67a5 Mon Sep 17 00:00:00 2001 From: oe73773 Date: Sun, 12 Jul 2020 19:40:21 +0200 Subject: [PATCH 07/17] traffic type fixed --- fritzbox__connection_uptime.py | 0 fritzbox__cpu_temperature.py | 0 fritzbox__cpu_usage.py | 0 fritzbox__memory_usage.py | 0 fritzbox__power_consumption.py | 0 fritzbox__traffic.py | 4 +- fritzbox__traffic_down.py | 92 ++++++++++++++++++++++++++++++++++ fritzbox__traffic_up.py | 91 +++++++++++++++++++++++++++++++++ fritzbox__uptime.py | 0 fritzbox__wifi_devices.py | 0 fritzbox_helper.py | 0 11 files changed, 185 insertions(+), 2 deletions(-) mode change 100755 => 100644 fritzbox__connection_uptime.py mode change 100755 => 100644 fritzbox__cpu_temperature.py mode change 100755 => 100644 fritzbox__cpu_usage.py mode change 100755 => 100644 fritzbox__memory_usage.py mode change 100755 => 100644 fritzbox__power_consumption.py mode change 100755 => 100644 fritzbox__traffic.py create mode 100644 fritzbox__traffic_down.py create mode 100644 fritzbox__traffic_up.py mode change 100755 => 100644 fritzbox__uptime.py mode change 100755 => 100644 fritzbox__wifi_devices.py mode change 100755 => 100644 fritzbox_helper.py diff --git a/fritzbox__connection_uptime.py b/fritzbox__connection_uptime.py old mode 100755 new mode 100644 diff --git a/fritzbox__cpu_temperature.py b/fritzbox__cpu_temperature.py old mode 100755 new mode 100644 diff --git a/fritzbox__cpu_usage.py b/fritzbox__cpu_usage.py old mode 100755 new mode 100644 diff --git a/fritzbox__memory_usage.py b/fritzbox__memory_usage.py old mode 100755 new mode 100644 diff --git a/fritzbox__power_consumption.py b/fritzbox__power_consumption.py old mode 100755 new mode 100644 diff --git a/fritzbox__traffic.py b/fritzbox__traffic.py old mode 100755 new mode 100644 index 2c6c83a..0d2e041 --- a/fritzbox__traffic.py +++ b/fritzbox__traffic.py @@ -63,7 +63,7 @@ def print_config(): 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.min 0") @@ -71,7 +71,7 @@ def print_config(): #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.min 0") diff --git a/fritzbox__traffic_down.py b/fritzbox__traffic_down.py new file mode 100644 index 0000000..2a48423 --- /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 up (-) / 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 diff --git a/fritzbox__wifi_devices.py b/fritzbox__wifi_devices.py old mode 100755 new mode 100644 diff --git a/fritzbox_helper.py b/fritzbox_helper.py old mode 100755 new mode 100644 From dea1895ad65b64b2ab28d8958fd04e791abbfc4e Mon Sep 17 00:00:00 2001 From: root Date: Sun, 12 Jul 2020 19:51:56 +0200 Subject: [PATCH 08/17] chmod fixed --- fritzbox__connection_uptime.py | 0 fritzbox__cpu_temperature.py | 0 fritzbox__cpu_usage.py | 0 fritzbox__memory_usage.py | 0 fritzbox__power_consumption.py | 0 fritzbox__traffic.py | 0 fritzbox__traffic_down.py | 0 fritzbox__traffic_up.py | 0 fritzbox__uptime.py | 0 fritzbox__wifi_devices.py | 0 fritzbox_helper.py | 0 11 files changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 fritzbox__connection_uptime.py mode change 100644 => 100755 fritzbox__cpu_temperature.py mode change 100644 => 100755 fritzbox__cpu_usage.py mode change 100644 => 100755 fritzbox__memory_usage.py mode change 100644 => 100755 fritzbox__power_consumption.py mode change 100644 => 100755 fritzbox__traffic.py mode change 100644 => 100755 fritzbox__traffic_down.py mode change 100644 => 100755 fritzbox__traffic_up.py mode change 100644 => 100755 fritzbox__uptime.py mode change 100644 => 100755 fritzbox__wifi_devices.py mode change 100644 => 100755 fritzbox_helper.py diff --git a/fritzbox__connection_uptime.py b/fritzbox__connection_uptime.py old mode 100644 new mode 100755 diff --git a/fritzbox__cpu_temperature.py b/fritzbox__cpu_temperature.py old mode 100644 new mode 100755 diff --git a/fritzbox__cpu_usage.py b/fritzbox__cpu_usage.py old mode 100644 new mode 100755 diff --git a/fritzbox__memory_usage.py b/fritzbox__memory_usage.py old mode 100644 new mode 100755 diff --git a/fritzbox__power_consumption.py b/fritzbox__power_consumption.py old mode 100644 new mode 100755 diff --git a/fritzbox__traffic.py b/fritzbox__traffic.py old mode 100644 new mode 100755 diff --git a/fritzbox__traffic_down.py b/fritzbox__traffic_down.py old mode 100644 new mode 100755 diff --git a/fritzbox__traffic_up.py b/fritzbox__traffic_up.py old mode 100644 new mode 100755 diff --git a/fritzbox__uptime.py b/fritzbox__uptime.py old mode 100644 new mode 100755 diff --git a/fritzbox__wifi_devices.py b/fritzbox__wifi_devices.py old mode 100644 new mode 100755 diff --git a/fritzbox_helper.py b/fritzbox_helper.py old mode 100644 new mode 100755 From f9b0eb9db9251f82806ab73ef247818a60967727 Mon Sep 17 00:00:00 2001 From: oe73773 Date: Sun, 12 Jul 2020 20:03:29 +0200 Subject: [PATCH 09/17] set executeable --- fritzbox__connection_uptime.py | 0 fritzbox__cpu_temperature.py | 0 fritzbox__cpu_usage.py | 0 fritzbox__memory_usage.py | 0 fritzbox__power_consumption.py | 0 fritzbox__traffic.py | 0 fritzbox__traffic_down.py | 0 fritzbox__traffic_up.py | 0 fritzbox__uptime.py | 0 fritzbox__wifi_devices.py | 0 fritzbox_helper.py | 0 11 files changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 fritzbox__connection_uptime.py mode change 100755 => 100644 fritzbox__cpu_temperature.py mode change 100755 => 100644 fritzbox__cpu_usage.py mode change 100755 => 100644 fritzbox__memory_usage.py mode change 100755 => 100644 fritzbox__power_consumption.py mode change 100755 => 100644 fritzbox__traffic.py mode change 100755 => 100644 fritzbox__traffic_down.py mode change 100755 => 100644 fritzbox__traffic_up.py mode change 100755 => 100644 fritzbox__uptime.py mode change 100755 => 100644 fritzbox__wifi_devices.py mode change 100755 => 100644 fritzbox_helper.py diff --git a/fritzbox__connection_uptime.py b/fritzbox__connection_uptime.py old mode 100755 new mode 100644 diff --git a/fritzbox__cpu_temperature.py b/fritzbox__cpu_temperature.py old mode 100755 new mode 100644 diff --git a/fritzbox__cpu_usage.py b/fritzbox__cpu_usage.py old mode 100755 new mode 100644 diff --git a/fritzbox__memory_usage.py b/fritzbox__memory_usage.py old mode 100755 new mode 100644 diff --git a/fritzbox__power_consumption.py b/fritzbox__power_consumption.py old mode 100755 new mode 100644 diff --git a/fritzbox__traffic.py b/fritzbox__traffic.py old mode 100755 new mode 100644 diff --git a/fritzbox__traffic_down.py b/fritzbox__traffic_down.py old mode 100755 new mode 100644 diff --git a/fritzbox__traffic_up.py b/fritzbox__traffic_up.py old mode 100755 new mode 100644 diff --git a/fritzbox__uptime.py b/fritzbox__uptime.py old mode 100755 new mode 100644 diff --git a/fritzbox__wifi_devices.py b/fritzbox__wifi_devices.py old mode 100755 new mode 100644 diff --git a/fritzbox_helper.py b/fritzbox_helper.py old mode 100755 new mode 100644 From b728737bb019c2f760bd505da93bf9657ea3094f Mon Sep 17 00:00:00 2001 From: root Date: Sun, 12 Jul 2020 20:06:58 +0200 Subject: [PATCH 10/17] set x --- fritzbox__connection_uptime.py | 0 fritzbox__cpu_temperature.py | 0 fritzbox__cpu_usage.py | 0 fritzbox__memory_usage.py | 0 fritzbox__power_consumption.py | 0 fritzbox__traffic.py | 0 fritzbox__traffic_down.py | 0 fritzbox__traffic_up.py | 0 fritzbox__uptime.py | 0 fritzbox__wifi_devices.py | 0 fritzbox_helper.py | 0 11 files changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 fritzbox__connection_uptime.py mode change 100644 => 100755 fritzbox__cpu_temperature.py mode change 100644 => 100755 fritzbox__cpu_usage.py mode change 100644 => 100755 fritzbox__memory_usage.py mode change 100644 => 100755 fritzbox__power_consumption.py mode change 100644 => 100755 fritzbox__traffic.py mode change 100644 => 100755 fritzbox__traffic_down.py mode change 100644 => 100755 fritzbox__traffic_up.py mode change 100644 => 100755 fritzbox__uptime.py mode change 100644 => 100755 fritzbox__wifi_devices.py mode change 100644 => 100755 fritzbox_helper.py diff --git a/fritzbox__connection_uptime.py b/fritzbox__connection_uptime.py old mode 100644 new mode 100755 diff --git a/fritzbox__cpu_temperature.py b/fritzbox__cpu_temperature.py old mode 100644 new mode 100755 diff --git a/fritzbox__cpu_usage.py b/fritzbox__cpu_usage.py old mode 100644 new mode 100755 diff --git a/fritzbox__memory_usage.py b/fritzbox__memory_usage.py old mode 100644 new mode 100755 diff --git a/fritzbox__power_consumption.py b/fritzbox__power_consumption.py old mode 100644 new mode 100755 diff --git a/fritzbox__traffic.py b/fritzbox__traffic.py old mode 100644 new mode 100755 diff --git a/fritzbox__traffic_down.py b/fritzbox__traffic_down.py old mode 100644 new mode 100755 diff --git a/fritzbox__traffic_up.py b/fritzbox__traffic_up.py old mode 100644 new mode 100755 diff --git a/fritzbox__uptime.py b/fritzbox__uptime.py old mode 100644 new mode 100755 diff --git a/fritzbox__wifi_devices.py b/fritzbox__wifi_devices.py old mode 100644 new mode 100755 diff --git a/fritzbox_helper.py b/fritzbox_helper.py old mode 100644 new mode 100755 From ace93c079cb0a3e6cd400fbbe0ef997ef86df9bb Mon Sep 17 00:00:00 2001 From: oe73773 Date: Sun, 12 Jul 2020 20:26:10 +0200 Subject: [PATCH 11/17] fix traffic --- fritzbox__connection_uptime.py | 0 fritzbox__cpu_temperature.py | 0 fritzbox__cpu_usage.py | 0 fritzbox__memory_usage.py | 0 fritzbox__power_consumption.py | 0 fritzbox__traffic.py | 2 +- fritzbox__traffic_down.py | 2 +- fritzbox__traffic_up.py | 0 fritzbox__uptime.py | 0 fritzbox__wifi_devices.py | 0 fritzbox_helper.py | 0 11 files changed, 2 insertions(+), 2 deletions(-) mode change 100755 => 100644 fritzbox__connection_uptime.py mode change 100755 => 100644 fritzbox__cpu_temperature.py mode change 100755 => 100644 fritzbox__cpu_usage.py mode change 100755 => 100644 fritzbox__memory_usage.py mode change 100755 => 100644 fritzbox__power_consumption.py mode change 100755 => 100644 fritzbox__traffic.py mode change 100755 => 100644 fritzbox__traffic_down.py mode change 100755 => 100644 fritzbox__traffic_up.py mode change 100755 => 100644 fritzbox__uptime.py mode change 100755 => 100644 fritzbox__wifi_devices.py mode change 100755 => 100644 fritzbox_helper.py diff --git a/fritzbox__connection_uptime.py b/fritzbox__connection_uptime.py old mode 100755 new mode 100644 diff --git a/fritzbox__cpu_temperature.py b/fritzbox__cpu_temperature.py old mode 100755 new mode 100644 diff --git a/fritzbox__cpu_usage.py b/fritzbox__cpu_usage.py old mode 100755 new mode 100644 diff --git a/fritzbox__memory_usage.py b/fritzbox__memory_usage.py old mode 100755 new mode 100644 diff --git a/fritzbox__power_consumption.py b/fritzbox__power_consumption.py old mode 100755 new mode 100644 diff --git a/fritzbox__traffic.py b/fritzbox__traffic.py old mode 100755 new mode 100644 index 0d2e041..73fe90a --- a/fritzbox__traffic.py +++ b/fritzbox__traffic.py @@ -59,7 +59,7 @@ def print_config(): 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") diff --git a/fritzbox__traffic_down.py b/fritzbox__traffic_down.py old mode 100755 new mode 100644 index 2a48423..3d8ecd0 --- a/fritzbox__traffic_down.py +++ b/fritzbox__traffic_down.py @@ -59,7 +59,7 @@ def print_config(): 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 down per ${graph_period}") print("graph_category network") print("graph_order down maxdown") print("down.label bps") diff --git a/fritzbox__traffic_up.py b/fritzbox__traffic_up.py old mode 100755 new mode 100644 diff --git a/fritzbox__uptime.py b/fritzbox__uptime.py old mode 100755 new mode 100644 diff --git a/fritzbox__wifi_devices.py b/fritzbox__wifi_devices.py old mode 100755 new mode 100644 diff --git a/fritzbox_helper.py b/fritzbox_helper.py old mode 100755 new mode 100644 From aa3e8e7739651127ee195885da37131f4998ab43 Mon Sep 17 00:00:00 2001 From: oe73773 Date: Sun, 12 Jul 2020 20:27:16 +0200 Subject: [PATCH 12/17] set unix mode --- fritzbox__connection_uptime.py | 122 +++++++++---------- fritzbox__cpu_temperature.py | 124 +++++++++---------- fritzbox__cpu_usage.py | 130 ++++++++++---------- fritzbox__memory_usage.py | 146 +++++++++++------------ fritzbox__power_consumption.py | 198 +++++++++++++++---------------- fritzbox__traffic.py | 210 ++++++++++++++++----------------- fritzbox__traffic_down.py | 184 ++++++++++++++--------------- fritzbox__traffic_up.py | 182 ++++++++++++++-------------- fritzbox__uptime.py | 170 +++++++++++++------------- fritzbox__wifi_devices.py | 138 +++++++++++----------- fritzbox_helper.py | 0 11 files changed, 802 insertions(+), 802 deletions(-) mode change 100644 => 100755 fritzbox__connection_uptime.py mode change 100644 => 100755 fritzbox__cpu_temperature.py mode change 100644 => 100755 fritzbox__cpu_usage.py mode change 100644 => 100755 fritzbox__memory_usage.py mode change 100644 => 100755 fritzbox__power_consumption.py mode change 100644 => 100755 fritzbox__traffic.py mode change 100644 => 100755 fritzbox__traffic_down.py mode change 100644 => 100755 fritzbox__traffic_up.py mode change 100644 => 100755 fritzbox__uptime.py mode change 100644 => 100755 fritzbox__wifi_devices.py mode change 100644 => 100755 fritzbox_helper.py diff --git a/fritzbox__connection_uptime.py b/fritzbox__connection_uptime.py old mode 100644 new mode 100755 index b36d76f..846fa66 --- 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 old mode 100644 new mode 100755 index e608c72..53e0024 --- 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 old mode 100644 new mode 100755 index 9109844..1575408 --- 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 old mode 100644 new mode 100755 index 868ce43..d6fb1e8 --- 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 old mode 100644 new mode 100755 index 8f1a143..1972480 --- 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 old mode 100644 new mode 100755 index 73fe90a..dfc2013 --- 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 old mode 100644 new mode 100755 index 3d8ecd0..273611b --- 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 old mode 100644 new mode 100755 index 42fe5c4..6370b38 --- 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 old mode 100644 new mode 100755 index 6463626..a7ac41d --- 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 old mode 100644 new mode 100755 index f9efb9a..44875ad --- 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 old mode 100644 new mode 100755 From 4128959dba733cf8fd708f5991c2cfd916da0e0a Mon Sep 17 00:00:00 2001 From: oe73773 Date: Sun, 12 Jul 2020 20:43:21 +0200 Subject: [PATCH 13/17] Executable! --- fritzbox__connection_uptime.py | 0 fritzbox__cpu_temperature.py | 0 fritzbox__cpu_usage.py | 0 fritzbox__memory_usage.py | 0 fritzbox__power_consumption.py | 0 fritzbox__traffic.py | 0 fritzbox__traffic_down.py | 0 fritzbox__traffic_up.py | 0 fritzbox__uptime.py | 0 fritzbox__wifi_devices.py | 0 fritzbox_helper.py | 0 11 files changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 fritzbox__connection_uptime.py mode change 100755 => 100644 fritzbox__cpu_temperature.py mode change 100755 => 100644 fritzbox__cpu_usage.py mode change 100755 => 100644 fritzbox__memory_usage.py mode change 100755 => 100644 fritzbox__power_consumption.py mode change 100755 => 100644 fritzbox__traffic.py mode change 100755 => 100644 fritzbox__traffic_down.py mode change 100755 => 100644 fritzbox__traffic_up.py mode change 100755 => 100644 fritzbox__uptime.py mode change 100755 => 100644 fritzbox__wifi_devices.py mode change 100755 => 100644 fritzbox_helper.py diff --git a/fritzbox__connection_uptime.py b/fritzbox__connection_uptime.py old mode 100755 new mode 100644 diff --git a/fritzbox__cpu_temperature.py b/fritzbox__cpu_temperature.py old mode 100755 new mode 100644 diff --git a/fritzbox__cpu_usage.py b/fritzbox__cpu_usage.py old mode 100755 new mode 100644 diff --git a/fritzbox__memory_usage.py b/fritzbox__memory_usage.py old mode 100755 new mode 100644 diff --git a/fritzbox__power_consumption.py b/fritzbox__power_consumption.py old mode 100755 new mode 100644 diff --git a/fritzbox__traffic.py b/fritzbox__traffic.py old mode 100755 new mode 100644 diff --git a/fritzbox__traffic_down.py b/fritzbox__traffic_down.py old mode 100755 new mode 100644 diff --git a/fritzbox__traffic_up.py b/fritzbox__traffic_up.py old mode 100755 new mode 100644 diff --git a/fritzbox__uptime.py b/fritzbox__uptime.py old mode 100755 new mode 100644 diff --git a/fritzbox__wifi_devices.py b/fritzbox__wifi_devices.py old mode 100755 new mode 100644 diff --git a/fritzbox_helper.py b/fritzbox_helper.py old mode 100755 new mode 100644 From 164d386e913bb353495b2425d1ea7c6c8448846e Mon Sep 17 00:00:00 2001 From: oe73773 Date: Sun, 12 Jul 2020 21:17:00 +0200 Subject: [PATCH 14/17] Line breaks and readme fixed --- README.md | 70 ++++++--- fritzbox__connection_uptime.py | 122 +++++++-------- fritzbox__cpu_temperature.py | 124 +++++++-------- fritzbox__cpu_usage.py | 130 ++++++++-------- fritzbox__memory_usage.py | 146 +++++++++--------- fritzbox__power_consumption.py | 198 ++++++++++++------------ fritzbox__traffic.py | 210 ++++++++++++------------- fritzbox__traffic_down.py | 184 +++++++++++----------- fritzbox__traffic_up.py | 182 +++++++++++----------- fritzbox__uptime.py | 170 ++++++++++---------- fritzbox__wifi_devices.py | 138 ++++++++--------- fritzbox_helper.py | 274 ++++++++++++++++----------------- 12 files changed, 989 insertions(+), 959 deletions(-) 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 From 8a6b82a06f01f6cddd64891ac8838ca6b8451e47 Mon Sep 17 00:00:00 2001 From: oe73773 Date: Sun, 12 Jul 2020 21:31:04 +0200 Subject: [PATCH 15/17] Update README.md --- README.md | 75 ++++++++++++++++++++++--------------------------------- 1 file changed, 30 insertions(+), 45 deletions(-) diff --git a/README.md b/README.md index 05020e6..d2f3f1b 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. @@ -83,46 +66,48 @@ If you are using the scripts on a different Fritz!Box model please let me know b 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`: + 1. only one fritzbox or all fritz boxes use the same password: - a. only one fritzbox or all fritz boxes use the same password: - [fritzbox_*] + [fritzbox_*] + env.fritzbox_password + env.traffic_remove_max true # if you do not want the possible max values + + 2. multible fritz boxes: + + [fritzbox__*] env.fritzbox_password env.traffic_remove_max true # if you do not want the possible max values - b. multble fritz boxes: - [fritzbox__*] - env.fritzbox_password - env.traffic_remove_max true # if you do not want the possible max values - - [fritzbox__*] + [fritzbox__*] env.fritzbox_password env.traffic_remove_max true # if you do not want the possible max values 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 + + 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__` + + 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 - ... + 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 - ... + 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`. From 2c59120ec241a71ed18cb4ce30535ff69782d8ea Mon Sep 17 00:00:00 2001 From: oe73773 Date: Sun, 12 Jul 2020 21:34:28 +0200 Subject: [PATCH 16/17] Update README.md --- README.md | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index d2f3f1b..257ae10 100644 --- a/README.md +++ b/README.md @@ -66,21 +66,21 @@ If you are using the scripts on a different Fritz!Box model please let me know b 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`: - 1. only one fritzbox or all fritz boxes use the same password: + 1. only one fritzbox or all fritz boxes use the same password: - [fritzbox_*] - env.fritzbox_password - env.traffic_remove_max true # if you do not want the possible max values + [fritzbox_*] + env.fritzbox_password + env.traffic_remove_max true # if you do not want the possible max values - 2. multible fritz boxes: + 2. multiple fritz boxes: - [fritzbox__*] - env.fritzbox_password - env.traffic_remove_max true # if you do not want the possible max values + [fritzbox__*] + env.fritzbox_password + env.traffic_remove_max true # if you do not want the possible max values - [fritzbox__*] - env.fritzbox_password - env.traffic_remove_max true # if you do not want the possible max values + [fritzbox__*] + env.fritzbox_password + env.traffic_remove_max true # if you do not want the possible max values 6. Create symbolic link in `/etc/munin/plugins` for `fritzbox_helper.py`. @@ -97,7 +97,7 @@ If you are using the scripts on a different Fritz!Box model please let me know b 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. + if you have multiple fritz box just create multiple sets of links with a different fqdn or ip. example cd /etc/munin/plugins From 08f1cc71260ef9a29789b8b506e789d6e91361ad Mon Sep 17 00:00:00 2001 From: oe73773 Date: Sun, 12 Jul 2020 21:36:17 +0200 Subject: [PATCH 17/17] Update README.md --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 257ae10..e08b648 100644 --- a/README.md +++ b/README.md @@ -66,13 +66,13 @@ If you are using the scripts on a different Fritz!Box model please let me know b 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`: - 1. only one fritzbox or all fritz boxes use the same password: + 1. only one fritzbox or all fritzboxes use the same password: [fritzbox_*] env.fritzbox_password env.traffic_remove_max true # if you do not want the possible max values - 2. multiple fritz boxes: + 2. multiple fritzboxes: [fritzbox__*] env.fritzbox_password @@ -125,7 +125,7 @@ You can change the used locale by setting an environment variable in your plugin env.locale en -## Set a group for your fritz boxes +## Set a group for your fritzboxes You can group the graphs of your fritzbox: @@ -135,7 +135,7 @@ You can group the graphs of your fritzbox: address 127.0.0.1 use_node_name no - example: + example: [Network;fritz.box] address 127.0.0.1 use_node_name no