mirror of
				https://github.com/Tafkas/fritzbox-munin.git
				synced 2023-10-10 11:36:55 +00:00 
			
		
		
		
	Compare commits
	
		
			35 Commits
		
	
	
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|  | 1e3e718d64 | ||
|  | eee98feeac | ||
|  | 8ce50dfeb6 | ||
|  | a9058f9c74 | ||
|  | c82e99a4b4 | ||
|  | d5b7a2eb64 | ||
|  | 2dd4e07013 | ||
|  | 883c61e498 | ||
|  | ef6f81b426 | ||
|  | cd269783bd | ||
|  | 3364b29ec1 | ||
|  | ee66451dcc | ||
|  | 34ee94ce1d | ||
|  | 666e3d0a0a | ||
|  | bfdeb190f3 | ||
|  | a2fb8f7dc7 | ||
|  | 5f64d24d9c | ||
|  | 9264e49e27 | ||
|  | c5cdb516d7 | ||
|  | 42c1d2461d | ||
|  | 213a64abe7 | ||
|  | 78a5a202cf | ||
|  | 9fe16979b7 | ||
|  | 4e5ede6d12 | ||
|  | ca82415b78 | ||
|  | 209eed91ae | ||
|  | 523b83ce17 | ||
|  | 27ea9ea8eb | ||
|  | c1b1d4bffa | ||
|  | 7291edc724 | ||
|  | 4e7a583b7a | ||
|  | 2c05d20602 | ||
|  | 7a051bc5b8 | ||
|  | d8d37e9d91 | ||
|  | b8a8e2c343 | 
							
								
								
									
										4
									
								
								CONTRIBUTORS.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								CONTRIBUTORS.md
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,4 @@ | |||||||
|  | ## fritzbox-munin contributors | ||||||
|  |  | ||||||
|  |  - Bob van de Vijver ([bobvandevijver](https://github.com/bobvandevijver)) | ||||||
|  |  - Framps ([framps](https://github.com/framps)) | ||||||
							
								
								
									
										17
									
								
								Changelog.md
									
									
									
									
									
								
							
							
						
						
									
										17
									
								
								Changelog.md
									
									
									
									
									
								
							| @@ -1,5 +1,22 @@ | |||||||
| # Changelog | # Changelog | ||||||
|  |  | ||||||
|  | ## 7.25.0 | ||||||
|  | *2021-03-26* | ||||||
|  |  | ||||||
|  | - Support for FritzOS!7.25 including log in via username password | ||||||
|  |  | ||||||
|  | ## 7.0.0 | ||||||
|  | *2018-09-11* | ||||||
|  |  | ||||||
|  | - Support for FritzOS!7.00 | ||||||
|  |  | ||||||
|  | ## 6.83.2 | ||||||
|  | *2017-09-05* | ||||||
|  |  | ||||||
|  | - Support for German and English user interface (by: [@bobvandevijver](https://github.com/bobvandevijver)) | ||||||
|  | - Support for running Fritzbox as separate host (by: [@bobvandevijver](https://github.com/bobvandevijver)) | ||||||
|  | - Make maximum download and upload optional by config (by: [@bobvandevijver](https://github.com/bobvandevijver)) | ||||||
|  |  | ||||||
| ## 6.83.1 | ## 6.83.1 | ||||||
| *2017-06-11* | *2017-06-11* | ||||||
|  |  | ||||||
|   | |||||||
							
								
								
									
										93
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										93
									
								
								README.md
									
									
									
									
									
								
							| @@ -1,11 +1,27 @@ | |||||||
| # fritzbox-munin | # fritzbox-munin | ||||||
|  |  | ||||||
| A collection of munin plugins to monitor your AVM FRITZ!Box router. The scripts have been developed using a [FRITZ!Box 7362 SL](http://geni.us/fTyoY)(Amazon link) running FRITZ!OS 06.83. This script also only works if the language of the Fritz!Box is set to German. | 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.25. | ||||||
|  |  | ||||||
| If you are using the scripts on a different Fritz!Box model please let me know by | If you are using the scripts on a different Fritz!Box model please let me know by | ||||||
|  |  | ||||||
|  - opening an issue | - opening an issue | ||||||
|  - submitting a pull request | - 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 7530](https://geni.us/h8oqYd) | ||||||
|  | - [FRITZ!Box 7530 AX](https://geni.us/a4dS5)   | ||||||
|  | - [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 an older Fritz!OS version check out the [releases section](https://github.com/Tafkas/fritzbox-munin/releases/). | ||||||
|  |  | ||||||
| ## Introduction | ## Introduction | ||||||
|  |  | ||||||
| @@ -16,6 +32,10 @@ If you are using the scripts on a different Fritz!Box model please let me know b | |||||||
|   fritzbox\_traffic shows you the traffic of the WAN interface (requires fritzconnection) |   fritzbox\_traffic shows you the traffic of the WAN interface (requires fritzconnection) | ||||||
|    |    | ||||||
|  |  | ||||||
|  |   If you do not want to show the interface maximum values, add the following to your plugin-configuration: | ||||||
|  |  | ||||||
|  |     env.traffic_remove_max true | ||||||
|  |  | ||||||
| ## fritzbox\_connection\_uptime | ## fritzbox\_connection\_uptime | ||||||
|  |  | ||||||
|   fritzbox\_connection\_uptime shows you the connection uptime in days (requires fritzconnection) |   fritzbox\_connection\_uptime shows you the connection uptime in days (requires fritzconnection) | ||||||
| @@ -23,54 +43,93 @@ If you are using the scripts on a different Fritz!Box model please let me know b | |||||||
|  |  | ||||||
| ## fritzbox\_cpu\_usage | ## fritzbox\_cpu\_usage | ||||||
|  |  | ||||||
|   fritzbox\_cpu\_usage shows you the cpu usage (requires password)   |   fritzbox\_cpu\_usage shows you the cpu usage (requires username & password) | ||||||
|    |    | ||||||
|  |  | ||||||
| ## fritzbox\_cpu\_temperature | ## fritzbox\_cpu\_temperature | ||||||
|  |  | ||||||
|   fritzbox\_cpu\_temperature shows you the cpu temperature (requires password)   |   fritzbox\_cpu\_temperature shows you the cpu temperature (requires username & password) | ||||||
|    |    | ||||||
|  |  | ||||||
| ## fritzbox\_memory\_usage | ## fritzbox\_memory\_usage | ||||||
|  |  | ||||||
|   fritzbox\_memory\_usage shows you the memory usage (requires password)   |   fritzbox\_memory\_usage shows you the memory usage (requires username & password) | ||||||
|    |    | ||||||
|  |  | ||||||
| ##  fritzbox\_power\_consumption | ##  fritzbox\_power\_consumption | ||||||
|  |  | ||||||
|   fritzbox\_power\_consumption shows you the power consumption (requires password)   |   fritzbox\_power\_consumption shows you the power consumption (requires username & password) | ||||||
|    |    | ||||||
|  |  | ||||||
| ## fritzbox\_uptime | ## fritzbox\_uptime | ||||||
|  |  | ||||||
|   fritzbox\_uptime shows you the uptime in days (requires password)   |   fritzbox\_uptime shows you the uptime in days (requires username & password) (language dependant, see below). | ||||||
|    |    | ||||||
|  |  | ||||||
| ## fritzbox\_wifi\_devices | ## fritzbox\_wifi\_devices | ||||||
|  |  | ||||||
|   fritzbox\_wifi\_devices shows you the number of connected wifi clients (requires password) |   fritzbox\_wifi\_devices shows you the number of connected wifi clients (requires username & password) (language dependant, see below). | ||||||
|    |    | ||||||
|  |  | ||||||
|  |  | ||||||
| ## Installation & Configuration | ## Installation & Configuration | ||||||
|  |  | ||||||
| 0. Pre-requesites for the fritzbox\_traffic and fritzbox\_uptime plugins is the [fritzconnection](https://pypi.python.org/pypi/fritzconnection) package. To install it   | 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 -r requirements.txt | ||||||
|   |   | ||||||
| 1. Copy all the scripts to =/usr/share/munin/plugins |  fritzconnection requires python3. Make sure python --version is >= 3.6.   | ||||||
|  |  | ||||||
| 2. Create entry in /etc/munin/plugin-conf.d/munin-node:   | 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` | ||||||
|  |  | ||||||
|  | 4. Create entry in `/etc/munin/plugin-conf.d/munin-node`: | ||||||
|  |  | ||||||
|         [fritzbox_*] |         [fritzbox_*] | ||||||
|         env.fritzbox_ip <ip_address_to_your_fritzbox> |         env.fritzbox_ip <ip_address_to_your_fritzbox> | ||||||
|  |         env.fritzbox_username <fritzbox_username> | ||||||
|         env.fritzbox_password <fritzbox_password> |         env.fritzbox_password <fritzbox_password> | ||||||
|  |         env.traffic_remove_max true # if you do not want the possible max values | ||||||
|  |         host_name fritzbox | ||||||
|  |  | ||||||
| 3. Create symbolic links to /etc/munin/plugins. | 5. Create symbolic links to `/etc/munin/plugins`. | ||||||
|  |  | ||||||
| 4. Restart the munin-node daemon: /etc/init.d/munin-node restart. | 6. Restart the munin-node daemon: `/etc/init.d/munin-node restart`. | ||||||
|  |  | ||||||
| 5. Done. You should now start to see the charts on the Munin pages. | 7. Done. You should now start to see the charts on the Munin pages. | ||||||
|  |  | ||||||
|  | ## Localization | ||||||
|  |  | ||||||
|  | Two scripts depend on the language selected in your fritzbox: the uptime and wifi\_devices. Currently, two locales are | ||||||
|  | supported: | ||||||
|  |  | ||||||
|  | 1. German: `de` (default) | ||||||
|  | 2. English: `en` | ||||||
|  |  | ||||||
|  | You can change the used locale by setting an environment variable in your plugin configuration: | ||||||
|  |  | ||||||
|  |     env.locale en | ||||||
|  |  | ||||||
|  | ## Different hosts for the fritzbox and your system | ||||||
|  |  | ||||||
|  | You can split the graphs of your fritzbox from the localhost graphs by following the next steps: | ||||||
|  |  | ||||||
|  | 1. Use the following as your host configuration in `/etc/munin/munin.conf` | ||||||
|  |  | ||||||
|  |         [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 | ||||||
|  |  | ||||||
|  |     env.host_name fritzbox | ||||||
|  |  | ||||||
|  | 3. Restart your munin-node: `systemctl restart munin-node` | ||||||
|  |  | ||||||
| ## Environment Settings | ## Environment Settings | ||||||
|  |  | ||||||
|   | |||||||
| @@ -1,4 +1,4 @@ | |||||||
| #!/usr/bin/env python | #!/usr/bin/env python3 | ||||||
| """ | """ | ||||||
|   fritzbox_connection_uptime - A munin plugin for Linux to monitor AVM Fritzbox connection uptime |   fritzbox_connection_uptime - A munin plugin for Linux to monitor AVM Fritzbox connection uptime | ||||||
|   Copyright (C) 2015 Christian Stade-Schuldt |   Copyright (C) 2015 Christian Stade-Schuldt | ||||||
| @@ -10,6 +10,12 @@ | |||||||
|   This plugin requires the fritzconnection plugin. To install it using pip: |   This plugin requires the fritzconnection plugin. To install it using pip: | ||||||
|   pip install fritzconnection |   pip install fritzconnection | ||||||
|   This plugin supports the following munin configuration parameters: |   This plugin supports the following munin configuration parameters: | ||||||
|  |  | ||||||
|  |   [fritzbox_*] | ||||||
|  |   env.fritzbox_ip [ip address of the fritzbox] | ||||||
|  |   env.fritzbox_username [fritzbox username] | ||||||
|  |   env.fritzbox_password [fritzbox password] | ||||||
|  |  | ||||||
|   #%# family=auto contrib |   #%# family=auto contrib | ||||||
|   #%# capabilities=autoconf |   #%# capabilities=autoconf | ||||||
| """ | """ | ||||||
| @@ -17,35 +23,41 @@ | |||||||
| import os | import os | ||||||
| import sys | import sys | ||||||
|  |  | ||||||
| from fritzconnection import FritzConnection | from fritzconnection.lib.fritzstatus import FritzStatus | ||||||
|  |  | ||||||
|  | server = os.environ["fritzbox_ip"] | ||||||
|  | username = os.environ["fritzbox_username"] | ||||||
|  | password = os.environ["fritzbox_password"] | ||||||
|  |  | ||||||
|  |  | ||||||
| def print_values(): | def print_values(): | ||||||
|     try: |     try: | ||||||
|         conn = FritzConnection(address=os.environ['fritzbox_ip']) |         fs = FritzStatus(address=server, user=username, password=password) | ||||||
|     except Exception as e: |     except Exception as e: | ||||||
|         sys.exit("Couldn't get connection uptime") |         sys.exit("Couldn't get connection uptime") | ||||||
|  |  | ||||||
|     uptime = conn.call_action('WANIPConnection', 'GetStatusInfo')['NewUptime'] |     uptime = fs.uptime | ||||||
|     print ('uptime.value %.2f' % (int(uptime) / 86400.0)) |     print("uptime.value %.2f" % (int(uptime) / 86400.0)) | ||||||
|  |  | ||||||
|  |  | ||||||
| def print_config(): | def print_config(): | ||||||
|     print "graph_title AVM Fritz!Box Connection Uptime" |     print("graph_title AVM Fritz!Box Connection Uptime") | ||||||
|     print "graph_args --base 1000 -l 0" |     print("graph_args --base 1000 -l 0") | ||||||
|     print 'graph_vlabel uptime in days' |     print("graph_vlabel uptime in days") | ||||||
|     print "graph_scale no'" |     print("graph_scale no'") | ||||||
|     print "graph_category network" |     print("graph_category network") | ||||||
|     print "uptime.label uptime" |     print("uptime.label uptime") | ||||||
|     print "uptime.draw AREA" |     print("uptime.draw AREA") | ||||||
|  |     if os.environ.get("host_name"): | ||||||
|  |         print("host_name " + os.environ["host_name"]) | ||||||
|  |  | ||||||
|  |  | ||||||
| if __name__ == "__main__": | if __name__ == "__main__": | ||||||
|     if len(sys.argv) == 2 and sys.argv[1] == 'config': |     if len(sys.argv) == 2 and sys.argv[1] == "config": | ||||||
|         print_config() |         print_config() | ||||||
|     elif len(sys.argv) == 2 and sys.argv[1] == 'autoconf': |     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 |         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'): |     elif len(sys.argv) == 1 or (len(sys.argv) == 2 and sys.argv[1] == "fetch"): | ||||||
|         try: |         try: | ||||||
|             print_values() |             print_values() | ||||||
|         except: |         except: | ||||||
|   | |||||||
| @@ -1,4 +1,4 @@ | |||||||
| #!/usr/bin/env python | #!/usr/bin/env python3 | ||||||
| """ | """ | ||||||
|   fritzbox_cpu_temperature - A munin plugin for Linux to monitor AVM Fritzbox |   fritzbox_cpu_temperature - A munin plugin for Linux to monitor AVM Fritzbox | ||||||
|   Copyright (C) 2015 Christian Stade-Schuldt |   Copyright (C) 2015 Christian Stade-Schuldt | ||||||
| @@ -9,57 +9,54 @@ | |||||||
|  |  | ||||||
|   [fritzbox_*] |   [fritzbox_*] | ||||||
|   env.fritzbox_ip [ip address of the fritzbox] |   env.fritzbox_ip [ip address of the fritzbox] | ||||||
|  |   env.fritzbox_username [fritzbox username] | ||||||
|   env.fritzbox_password [fritzbox password] |   env.fritzbox_password [fritzbox password] | ||||||
|    |    | ||||||
|   This plugin supports the following munin configuration parameters: |   This plugin supports the following munin configuration parameters: | ||||||
|   #%# family=auto contrib |   #%# family=auto contrib | ||||||
|   #%# capabilities=autoconf |   #%# capabilities=autoconf | ||||||
| """ | """ | ||||||
|  | import json | ||||||
| import os | import os | ||||||
| import re |  | ||||||
| import sys | import sys | ||||||
| import fritzbox_helper as fh | import fritzbox_helper as fh | ||||||
|  |  | ||||||
| PAGE = '/system/ecostat.lua' | PAGE = "ecoStat" | ||||||
| pattern = re.compile('Query\s=\s"(\d{1,3})') |  | ||||||
|  |  | ||||||
|  |  | ||||||
| def get_cpu_temperature(): | def get_cpu_temperature(): | ||||||
|     """get the current cpu temperature""" |     """get the current cpu temperature""" | ||||||
|  |  | ||||||
|     server = os.environ['fritzbox_ip'] |     server = os.environ["fritzbox_ip"] | ||||||
|     password = os.environ['fritzbox_password'] |     username = os.environ["fritzbox_username"] | ||||||
|  |     password = os.environ["fritzbox_password"] | ||||||
|  |  | ||||||
|     sid = fh.get_sid(server, password) |     session_id = fh.get_session_id(server, username, password) | ||||||
|     data = fh.get_page(server, sid, PAGE) |     xhr_data = fh.get_xhr_content(server, session_id, PAGE) | ||||||
|  |     data = json.loads(xhr_data) | ||||||
|     m = re.search(pattern, data) |     print("temp.value %d" % (int(data["data"]["cputemp"]["series"][0][-1]))) | ||||||
|     if m: |  | ||||||
|         print 'temp.value %d' % (int(m.group(1))) |  | ||||||
|  |  | ||||||
|  |  | ||||||
| def print_config(): | def print_config(): | ||||||
|     print "graph_title AVM Fritz!Box CPU temperature" |     print("graph_title AVM Fritz!Box CPU temperature") | ||||||
|     print "graph_vlabel degrees Celsius" |     print("graph_vlabel degrees Celsius") | ||||||
|     print "graph_category sensors" |     print("graph_category sensors") | ||||||
|     print "graph_order tmp" |     print("graph_order tmp") | ||||||
|     print "graph_scale no" |     print("graph_scale no") | ||||||
|     print "temp.label CPU temperature" |     print("temp.label CPU temperature") | ||||||
|     print "temp.type GAUGE" |     print("temp.type GAUGE") | ||||||
|     print "temp.graph LINE1" |     print("temp.graph LINE1") | ||||||
|     print "temp.min 0" |     print("temp.min 0") | ||||||
|     print "temp.info Fritzbox CPU temperature" |     print("temp.info Fritzbox CPU temperature") | ||||||
|  |     if os.environ.get("host_name"): | ||||||
|  |         print("host_name " + os.environ["host_name"]) | ||||||
|  |  | ||||||
|  |  | ||||||
| if __name__ == '__main__': | if __name__ == "__main__": | ||||||
|     if len(sys.argv) == 2 and sys.argv[1] == 'config': |     if len(sys.argv) == 2 and sys.argv[1] == "config": | ||||||
|         print_config() |         print_config() | ||||||
|     elif len(sys.argv) == 2 and sys.argv[1] == 'autoconf': |     elif len(sys.argv) == 2 and sys.argv[1] == "autoconf": | ||||||
|         print 'yes' |         print("yes") | ||||||
|     elif len(sys.argv) == 1 or len(sys.argv) == 2 and sys.argv[1] == 'fetch': |     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 |         # Some docs say it'll be called with fetch, some say no arg at all | ||||||
|         try: |         get_cpu_temperature() | ||||||
|             get_cpu_temperature() |  | ||||||
|         except: |  | ||||||
|             sys.exit("Couldn't retrieve fritzbox cpu temperature") |  | ||||||
|   | |||||||
| @@ -1,4 +1,4 @@ | |||||||
| #!/usr/bin/env python | #!/usr/bin/env python3 | ||||||
| """ | """ | ||||||
|   fritzbox_cpu_usage - A munin plugin for Linux to monitor AVM Fritzbox |   fritzbox_cpu_usage - A munin plugin for Linux to monitor AVM Fritzbox | ||||||
|   Copyright (C) 2015 Christian Stade-Schuldt |   Copyright (C) 2015 Christian Stade-Schuldt | ||||||
| @@ -9,55 +9,55 @@ | |||||||
|  |  | ||||||
|   [fritzbox_*] |   [fritzbox_*] | ||||||
|   env.fritzbox_ip [ip address of the fritzbox] |   env.fritzbox_ip [ip address of the fritzbox] | ||||||
|  |   env.fritzbox_username [fritzbox username] | ||||||
|   env.fritzbox_password [fritzbox password] |   env.fritzbox_password [fritzbox password] | ||||||
|    |    | ||||||
|   This plugin supports the following munin configuration parameters: |   This plugin supports the following munin configuration parameters: | ||||||
|   #%# family=auto contrib |   #%# family=auto contrib | ||||||
|   #%# capabilities=autoconf |   #%# capabilities=autoconf | ||||||
| """ | """ | ||||||
|  | import json | ||||||
| import os | import os | ||||||
| import re |  | ||||||
| import sys | import sys | ||||||
| import fritzbox_helper as fh | import fritzbox_helper as fh | ||||||
|  |  | ||||||
| PAGE = '/system/ecostat.lua' | PAGE = "ecoStat" | ||||||
| pattern = re.compile('Query1\s=\s"(\d{1,3})') |  | ||||||
|  |  | ||||||
|  |  | ||||||
| def get_cpu_usage(): | def get_cpu_usage(): | ||||||
|     """get the current cpu usage""" |     """get the current cpu usage""" | ||||||
|  |  | ||||||
|     server = os.environ['fritzbox_ip'] |     server = os.environ["fritzbox_ip"] | ||||||
|     password = os.environ['fritzbox_password'] |     username = os.environ["fritzbox_username"] | ||||||
|  |     password = os.environ["fritzbox_password"] | ||||||
|  |  | ||||||
|     sid = fh.get_sid(server, password) |     session_id = fh.get_session_id(server, username, password) | ||||||
|     data = fh.get_page(server, sid, PAGE) |     xhr_data = fh.get_xhr_content(server, session_id, PAGE) | ||||||
|  |     data = json.loads(xhr_data) | ||||||
|     m = re.search(pattern, data) |     print("cpu.value %d" % (int(data["data"]["cpuutil"]["series"][0][-1]))) | ||||||
|     if m: |  | ||||||
|         print 'cpu.value %d' % (int(m.group(1))) |  | ||||||
|  |  | ||||||
|  |  | ||||||
| def print_config(): | def print_config(): | ||||||
|     print "graph_title AVM Fritz!Box CPU usage" |     print("graph_title AVM Fritz!Box CPU usage") | ||||||
|     print "graph_vlabel %" |     print("graph_vlabel %") | ||||||
|     print "graph_category system" |     print("graph_category system") | ||||||
|     print "graph_order cpu" |     print("graph_order cpu") | ||||||
|     print "graph_scale no" |     print("graph_scale no") | ||||||
|     print "cpu.label system" |     print("cpu.label system") | ||||||
|     print "cpu.type GAUGE" |     print("cpu.type GAUGE") | ||||||
|     print "cpu.graph AREA" |     print("cpu.graph AREA") | ||||||
|     print "cpu.min 0" |     print("cpu.min 0") | ||||||
|     print "cpu.info Fritzbox CPU usage" |     print("cpu.info Fritzbox CPU usage") | ||||||
|  |     if os.environ.get("host_name"): | ||||||
|  |         print("host_name " + os.environ["host_name"]) | ||||||
|  |  | ||||||
|  |  | ||||||
| if __name__ == '__main__': | if __name__ == "__main__": | ||||||
|     if len(sys.argv) == 2 and sys.argv[1] == 'config': |     if len(sys.argv) == 2 and sys.argv[1] == "config": | ||||||
|         print_config() |         print_config() | ||||||
|     elif len(sys.argv) == 2 and sys.argv[1] == 'autoconf': |     elif len(sys.argv) == 2 and sys.argv[1] == "autoconf": | ||||||
|         print 'yes' |         print("yes") | ||||||
|     elif len(sys.argv) == 1 or len(sys.argv) == 2 and sys.argv[1] == 'fetch': |     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 |         # Some docs say it'll be called with fetch, some say no arg at all | ||||||
|         try: |         try: | ||||||
|             get_cpu_usage() |             get_cpu_usage() | ||||||
|   | |||||||
| @@ -1,4 +1,4 @@ | |||||||
| #!/usr/bin/env python | #!/usr/bin/env python3 | ||||||
| """ | """ | ||||||
|   fritzbox_helper - A munin plugin for Linux to monitor AVM Fritzbox |   fritzbox_helper - A munin plugin for Linux to monitor AVM Fritzbox | ||||||
|   Copyright (C) 2015 Christian Stade-Schuldt |   Copyright (C) 2015 Christian Stade-Schuldt | ||||||
| @@ -9,85 +9,157 @@ | |||||||
|  |  | ||||||
|   [fritzbox_*] |   [fritzbox_*] | ||||||
|   env.fritzbox_ip [ip address of the fritzbox] |   env.fritzbox_ip [ip address of the fritzbox] | ||||||
|  |   env.fritzbox_username [fritzbox username] | ||||||
|   env.fritzbox_password [fritzbox password] |   env.fritzbox_password [fritzbox password] | ||||||
|    |    | ||||||
|   This plugin supports the following munin configuration parameters: |   This plugin supports the following munin configuration parameters: | ||||||
|   #%# family=auto contrib |   #%# family=auto contrib | ||||||
|   #%# capabilities=autoconf |   #%# 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 | ||||||
|  |  | ||||||
|  |   New authentication supporting username and password, as well as PBKDF2 support, has been inspired by | ||||||
|  |   https://avm.de/fileadmin/user_upload/Global/Service/Schnittstellen/AVM%20Technical%20Note%20-%20Session%20ID_englisch.pdf | ||||||
| """ | """ | ||||||
|  |  | ||||||
| import hashlib | import hashlib | ||||||
| import httplib |  | ||||||
| import re |  | ||||||
| import sys | import sys | ||||||
| from xml.dom import minidom | import time | ||||||
|  |  | ||||||
| USER_AGENT = "Mozilla/5.0 (U; Windows NT 5.1; rv:5.0) Gecko/20100101 Firefox/5.0" | 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" | ||||||
|  |  | ||||||
|  | LOGIN_SID_ROUTE = "/login_sid.lua?version=2" | ||||||
|  |  | ||||||
|  |  | ||||||
| def get_sid(server, password, port=80): | class LoginState: | ||||||
|     """Obtains the sid after login into the fritzbox""" |     def __init__(self, challenge, blocktime): | ||||||
|     conn = httplib.HTTPConnection(server + ':' + str(port)) |         self.challenge = challenge | ||||||
|  |         self.blocktime = blocktime | ||||||
|  |         self.is_pbkdf2 = challenge.startswith("2$") | ||||||
|  |  | ||||||
|     headers = {"Accept": "application/xml", |  | ||||||
|                "Content-Type": "text/plain", |  | ||||||
|                "User-Agent": USER_AGENT} |  | ||||||
|  |  | ||||||
|     initial_page = '/login_sid.lua' | def get_session_id(server, username, password, port=80): | ||||||
|     conn.request("GET", initial_page, '', headers) |     """ Get a sid by solving the PBKDF2 (or MD5) challenge-response process. """ | ||||||
|     response = conn.getresponse() |     box_url = "http://{}:{}".format(server, port) | ||||||
|     data = response.read() |     try: | ||||||
|     if response.status != 200: |         state = get_login_state(box_url) | ||||||
|         print "%s %s" % (response.status, response.reason) |     except Exception as ex: | ||||||
|         sys.exit(0) |         raise Exception("failed to get challenge") | ||||||
|  |     if state.is_pbkdf2: | ||||||
|  |         # print("PBKDF2 supported") | ||||||
|  |         challenge_response = calculate_pbkdf2_response(state.challenge, password) | ||||||
|     else: |     else: | ||||||
|         xml_data = minidom.parseString(data) |         # print("Falling back to MD5") | ||||||
|         sid_info = xml_data.getElementsByTagName('SID') |         challenge_response = calculate_md5_response(state.challenge, password) | ||||||
|         sid = sid_info[0].firstChild.data |     if state.blocktime > 0: | ||||||
|         if sid == "0000000000000000": |         # print(f"Waiting for {state.blocktime} seconds...") | ||||||
|             challenge_info = xml_data.getElementsByTagName('Challenge') |         time.sleep(state.blocktime) | ||||||
|             challenge = challenge_info[0].firstChild.data |     try: | ||||||
|             challenge_bf = (challenge + '-' + password).decode('iso-8859-1').encode('utf-16le') |         sid = send_response(box_url, username, challenge_response) | ||||||
|             m = hashlib.md5() |     except Exception as ex: | ||||||
|             m.update(challenge_bf) |         raise Exception("failed to login") from ex | ||||||
|             response_bf = challenge + '-' + m.hexdigest().lower() |     if sid == "0000000000000000": | ||||||
|         else: |         raise Exception("wrong username or password") | ||||||
|             return sid |     return sid | ||||||
|  |  | ||||||
|     headers = {"Accept": "text/html,application/xhtml+xml,application/xml", |  | ||||||
|                "Content-Type": "application/x-www-form-urlencoded", |  | ||||||
|                "User-Agent": USER_AGENT} |  | ||||||
|  |  | ||||||
|     login_page = "/login_sid.lua?&response=" + response_bf |  | ||||||
|     conn.request("GET", login_page, '', headers) |  | ||||||
|     response = conn.getresponse() |  | ||||||
|     data = response.read() |  | ||||||
|     if response.status != 200: |  | ||||||
|         print "%s %s" % (response.status, response.reason) |  | ||||||
|         sys.exit(0) |  | ||||||
|     else: |  | ||||||
|         sid = re.search("<SID>(.*?)</SID>", data).group(1) |  | ||||||
|         if sid == "0000000000000000": |  | ||||||
|             print "ERROR - No SID received because of invalid password" |  | ||||||
|             sys.exit(0) |  | ||||||
|         return sid |  | ||||||
|  |  | ||||||
|  |  | ||||||
| def get_page(server, sid, page, port=80): | def get_login_state(box_url): | ||||||
|     """Fetches a page from the Fritzbox and returns its content""" |     """ Get login state from FRITZ!Box using login_sid.lua?version=2 """ | ||||||
|     conn = httplib.HTTPConnection(server + ':' + str(port)) |     url = box_url + LOGIN_SID_ROUTE | ||||||
|  |     r = requests.get(url) | ||||||
|  |     xml = etree.fromstring(r.content) | ||||||
|  |     challenge = xml.find("Challenge").text | ||||||
|  |     blocktime = int(xml.find("BlockTime").text) | ||||||
|  |     return LoginState(challenge, blocktime) | ||||||
|  |  | ||||||
|     headers = {"Accept": "application/xml", |  | ||||||
|                "Content-Type": "text/plain", |  | ||||||
|                "User-Agent": USER_AGENT} |  | ||||||
|  |  | ||||||
|     page_with_sid = page + "?sid=" + sid | def calculate_pbkdf2_response(challenge, password): | ||||||
|     conn.request("GET", page_with_sid, '', headers) |     """ Calculate the response for a given challenge via PBKDF2 """ | ||||||
|     response = conn.getresponse() |     challenge_parts = challenge.split("$") | ||||||
|     data = response.read() |     # Extract all necessary values encoded into the challenge | ||||||
|     if response.status != 200: |     iter1 = int(challenge_parts[1]) | ||||||
|         print "%s %s" % (response.status, response.reason) |     salt1 = bytes.fromhex(challenge_parts[2]) | ||||||
|         print data |     iter2 = int(challenge_parts[3]) | ||||||
|         sys.exit(0) |     salt2 = bytes.fromhex(challenge_parts[4]) | ||||||
|     else: |     # Hash twice, once with static salt... | ||||||
|         return data |     # Once with dynamic salt. | ||||||
|  |     hash1 = hashlib.pbkdf2_hmac("sha256", password.encode(), salt1, iter1) | ||||||
|  |     hash2 = hashlib.pbkdf2_hmac("sha256", hash1, salt2, iter2) | ||||||
|  |     return f"{challenge_parts[4]}${hash2.hex()}" | ||||||
|  |  | ||||||
|  |  | ||||||
|  | def calculate_md5_response(challenge, password): | ||||||
|  |     """ Calculate the response for a challenge using legacy MD5 """ | ||||||
|  |     response = challenge + "-" + password | ||||||
|  |     # the legacy response needs utf_16_le encoding | ||||||
|  |     response = response.encode("utf_16_le") | ||||||
|  |     md5_sum = hashlib.md5() | ||||||
|  |     md5_sum.update(response) | ||||||
|  |     response = challenge + "-" + md5_sum.hexdigest() | ||||||
|  |     return response | ||||||
|  |  | ||||||
|  |  | ||||||
|  | def send_response(box_url, username, challenge_response): | ||||||
|  |     """ Send the response and return the parsed sid. raises an Exception on error """ | ||||||
|  |     # Build response params | ||||||
|  |     post_data = {"username": username, "response": challenge_response} | ||||||
|  |     # post_data = urllib.parse.urlencode(post_data_dict).encode() | ||||||
|  |     headers = {"Content-Type": "application/x-www-form-urlencoded"} | ||||||
|  |     url = box_url + LOGIN_SID_ROUTE | ||||||
|  |     r = requests.post(url, headers=headers, data=post_data) | ||||||
|  |     # Parse SID from resulting XML. | ||||||
|  |     xml = etree.fromstring(r.content) | ||||||
|  |     return xml.find("SID").text | ||||||
|  |  | ||||||
|  |  | ||||||
|  | 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 | ||||||
|   | |||||||
| @@ -1,4 +1,4 @@ | |||||||
| #!/usr/bin/env python | #!/usr/bin/env python3 | ||||||
| """ | """ | ||||||
|   fritzbox_memory_usage - A munin plugin for Linux to monitor AVM Fritzbox |   fritzbox_memory_usage - A munin plugin for Linux to monitor AVM Fritzbox | ||||||
|   Copyright (C) 2015 Christian Stade-Schuldt |   Copyright (C) 2015 Christian Stade-Schuldt | ||||||
| @@ -9,63 +9,63 @@ | |||||||
|  |  | ||||||
|   [fritzbox_*] |   [fritzbox_*] | ||||||
|   env.fritzbox_ip [ip address of the fritzbox] |   env.fritzbox_ip [ip address of the fritzbox] | ||||||
|  |   env.fritzbox_username [fritzbox username] | ||||||
|   env.fritzbox_password [fritzbox password] |   env.fritzbox_password [fritzbox password] | ||||||
|    |    | ||||||
|   This plugin supports the following munin configuration parameters: |   This plugin supports the following munin configuration parameters: | ||||||
|   #%# family=auto contrib |   #%# family=auto contrib | ||||||
|   #%# capabilities=autoconf |   #%# capabilities=autoconf | ||||||
| """ | """ | ||||||
|  | import json | ||||||
| import os | import os | ||||||
| import re |  | ||||||
| import sys | import sys | ||||||
| import fritzbox_helper as fh | import fritzbox_helper as fh | ||||||
|  |  | ||||||
| PAGE = '/system/ecostat.lua' | PAGE = "ecoStat" | ||||||
| pattern = re.compile('Query[1-3]\s="(\d{1,3})') | USAGE = ["strict", "cache", "free"] | ||||||
| USAGE = ['free', 'cache', 'strict'] |  | ||||||
|  |  | ||||||
|  |  | ||||||
| def get_memory_usage(): | def get_memory_usage(): | ||||||
|     """get the current memory usage""" |     """get the current memory usage""" | ||||||
|  |  | ||||||
|     server = os.environ['fritzbox_ip'] |     server = os.environ["fritzbox_ip"] | ||||||
|     password = os.environ['fritzbox_password'] |     username = os.environ["fritzbox_username"] | ||||||
|  |     password = os.environ["fritzbox_password"] | ||||||
|  |  | ||||||
|     sid = fh.get_sid(server, password) |     session_id = fh.get_session_id(server, username, password) | ||||||
|     data = fh.get_page(server, sid, PAGE) |     xhr_data = fh.get_xhr_content(server, session_id, PAGE) | ||||||
|     matches = re.finditer(pattern, data) |     data = json.loads(xhr_data) | ||||||
|     if matches: |     for i, usage in enumerate(USAGE): | ||||||
|         data = zip(USAGE, [m.group(1) for m in matches]) |         print("%s.value %s" % (usage, data["data"]["ramusage"]["series"][i][-1])) | ||||||
|         for d in data: |  | ||||||
|             print'%s.value %s' % (d[0], d[1]) |  | ||||||
|  |  | ||||||
|  |  | ||||||
| def print_config(): | def print_config(): | ||||||
|     print "graph_title AVM Fritz!Box Memory" |     print("graph_title AVM Fritz!Box Memory") | ||||||
|     print "graph_vlabel %" |     print("graph_vlabel %") | ||||||
|     print "graph_args --base 1000 -r --lower-limit 0 --upper-limit 100" |     print("graph_args --base 1000 -r --lower-limit 0 --upper-limit 100") | ||||||
|     print "graph_category system" |     print("graph_category system") | ||||||
|     print "graph_order strict cache free" |     print("graph_order strict cache free") | ||||||
|     print "graph_info This graph shows what the Fritzbox uses memory for." |     print("graph_info This graph shows what the Fritzbox uses memory for.") | ||||||
|     print "graph_scale no" |     print("graph_scale no") | ||||||
|     print "strict.label strict" |     print("strict.label strict") | ||||||
|     print "strict.type GAUGE" |     print("strict.type GAUGE") | ||||||
|     print "strict.draw AREA" |     print("strict.draw AREA") | ||||||
|     print "cache.label cache" |     print("cache.label cache") | ||||||
|     print "cache.type GAUGE" |     print("cache.type GAUGE") | ||||||
|     print "cache.draw STACK" |     print("cache.draw STACK") | ||||||
|     print "free.label free" |     print("free.label free") | ||||||
|     print "free.type GAUGE" |     print("free.type GAUGE") | ||||||
|     print "free.draw STACK" |     print("free.draw STACK") | ||||||
|  |     if os.environ.get("host_name"): | ||||||
|  |         print("host_name " + os.environ["host_name"]) | ||||||
|  |  | ||||||
|  |  | ||||||
| if __name__ == '__main__': | if __name__ == "__main__": | ||||||
|     if len(sys.argv) == 2 and sys.argv[1] == 'config': |     if len(sys.argv) == 2 and sys.argv[1] == "config": | ||||||
|         print_config() |         print_config() | ||||||
|     elif len(sys.argv) == 2 and sys.argv[1] == 'autoconf': |     elif len(sys.argv) == 2 and sys.argv[1] == "autoconf": | ||||||
|         print 'yes' |         print("yes") | ||||||
|     elif len(sys.argv) == 1 or len(sys.argv) == 2 and sys.argv[1] == 'fetch': |     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 |         # Some docs say it'll be called with fetch, some say no arg at all | ||||||
|         try: |         try: | ||||||
|             get_memory_usage() |             get_memory_usage() | ||||||
|   | |||||||
| @@ -1,4 +1,5 @@ | |||||||
| #!/usr/bin/env python | #!/usr/bin/env python3 | ||||||
|  | # coding=utf-8 | ||||||
| """ | """ | ||||||
|   fritzbox_power_consumption - A munin plugin for Linux to monitor AVM Fritzbox |   fritzbox_power_consumption - A munin plugin for Linux to monitor AVM Fritzbox | ||||||
|   Copyright (C) 2015 Christian Stade-Schuldt |   Copyright (C) 2015 Christian Stade-Schuldt | ||||||
| @@ -9,87 +10,89 @@ | |||||||
|  |  | ||||||
|   [fritzbox_*] |   [fritzbox_*] | ||||||
|   env.fritzbox_ip [ip address of the fritzbox] |   env.fritzbox_ip [ip address of the fritzbox] | ||||||
|  |   env.fritzbox_username [fritzbox username] | ||||||
|   env.fritzbox_password [fritzbox password] |   env.fritzbox_password [fritzbox password] | ||||||
|    |    | ||||||
|   This plugin supports the following munin configuration parameters: |   This plugin supports the following munin configuration parameters: | ||||||
|   #%# family=auto contrib |   #%# family=auto contrib | ||||||
|   #%# capabilities=autoconf |   #%# capabilities=autoconf | ||||||
| """ | """ | ||||||
|  | import json | ||||||
| import os | import os | ||||||
| import re |  | ||||||
| import sys | import sys | ||||||
|  |  | ||||||
| import fritzbox_helper as fh | import fritzbox_helper as fh | ||||||
|  |  | ||||||
| PAGE = '/system/energy.lua' | PAGE = "energy" | ||||||
| pattern = re.compile('<td>(.+?)"bar\s(act|fillonly)"(.+?)\s(\d{1,3})\s%') | DEVICES = ["system", "cpu", "wifi", "dsl", "ab", "usb"] | ||||||
| DEVICES = ['system', 'cpu', 'wifi', 'dsl', 'ab', 'usb'] |  | ||||||
|  |  | ||||||
|  |  | ||||||
| def get_power_consumption(): | def get_power_consumption(): | ||||||
|     """get the current power consumption usage""" |     """get the current power consumption usage""" | ||||||
|  |  | ||||||
|     server = os.environ['fritzbox_ip'] |     server = os.environ["fritzbox_ip"] | ||||||
|     password = os.environ['fritzbox_password'] |     username = os.environ["fritzbox_username"] | ||||||
|  |     password = os.environ["fritzbox_password"] | ||||||
|  |  | ||||||
|     sid = fh.get_sid(server, password) |     session_id = fh.get_session_id(server, username, password) | ||||||
|     data = fh.get_page(server, sid, PAGE) |     xhr_data = fh.get_xhr_content(server, session_id, PAGE) | ||||||
|     matches = re.finditer(pattern, data) |     data = json.loads(xhr_data) | ||||||
|     if matches: |     devices = data["data"]["drain"] | ||||||
|         data = zip(DEVICES, [m.group(4) for m in matches]) |     for i, device in enumerate(DEVICES): | ||||||
|         for d in data: |         print("%s.value %s" % (device, devices[i]["actPerc"])) | ||||||
|             print'%s.value %s' % (d[0], d[1]) |  | ||||||
|  |  | ||||||
|  |  | ||||||
| def print_config(): | def print_config(): | ||||||
|     print "graph_title AVM Fritz!Box Power Consumption" |     print("graph_title AVM Fritz!Box Power Consumption") | ||||||
|     print "graph_vlabel %" |     print("graph_vlabel %") | ||||||
|     print "graph_category network" |     print("graph_category system") | ||||||
|     print "graph_order system cpu wifi dsl ab usb" |     print("graph_order system cpu wifi dsl ab usb") | ||||||
|     print "system.label system" |     print("system.label system") | ||||||
|     print "system.type GAUGE" |     print("system.type GAUGE") | ||||||
|     print "system.graph LINE12" |     print("system.graph LINE12") | ||||||
|     print "system.min 0" |     print("system.min 0") | ||||||
|     print "system.max 100" |     print("system.max 100") | ||||||
|     print "system.info Fritzbox overall power consumption" |     print("system.info Fritzbox overall power consumption") | ||||||
|     print "cpu.label cpu" |     print("cpu.label cpu") | ||||||
|     print "cpu.type GAUGE" |     print("cpu.type GAUGE") | ||||||
|     print "cpu.graph LINE1" |     print("cpu.graph LINE1") | ||||||
|     print "cpu.min 0" |     print("cpu.min 0") | ||||||
|     print "cpu.max 100" |     print("cpu.max 100") | ||||||
|     print "cpu.info Fritzbox central processor power consumption" |     print("cpu.info Fritzbox central processor power consumption") | ||||||
|     print "wifi.label wifi" |     print("wifi.label wifi") | ||||||
|     print "wifi.type GAUGE" |     print("wifi.type GAUGE") | ||||||
|     print "wifi.graph LINE1" |     print("wifi.graph LINE1") | ||||||
|     print "wifi.min 0" |     print("wifi.min 0") | ||||||
|     print "wifi.max 100" |     print("wifi.max 100") | ||||||
|     print "wifi.info Fritzbox wifi power consumption" |     print("wifi.info Fritzbox wifi power consumption") | ||||||
|     print "dsl.label dsl" |     print("dsl.label dsl") | ||||||
|     print "dsl.type GAUGE" |     print("dsl.type GAUGE") | ||||||
|     print "dsl.graph LINE1" |     print("dsl.graph LINE1") | ||||||
|     print "dsl.min 0" |     print("dsl.min 0") | ||||||
|     print "dsl.max 100" |     print("dsl.max 100") | ||||||
|     print "dsl.info Fritzbox dsl power consumption" |     print("dsl.info Fritzbox dsl power consumption") | ||||||
|     print "ab.label ab" |     print("ab.label ab") | ||||||
|     print "ab.type GAUGE" |     print("ab.type GAUGE") | ||||||
|     print "ab.graph LINE1" |     print("ab.graph LINE1") | ||||||
|     print "ab.min 0" |     print("ab.min 0") | ||||||
|     print "ab.max 100" |     print("ab.max 100") | ||||||
|     print "ab.info Fritzbox analog phone ports power consumption" |     print("ab.info Fritzbox analog phone ports power consumption") | ||||||
|     print "usb.label usb" |     print("usb.label usb") | ||||||
|     print "usb.type GAUGE" |     print("usb.type GAUGE") | ||||||
|     print "usb.graph LINE1" |     print("usb.graph LINE1") | ||||||
|     print "usb.min 0" |     print("usb.min 0") | ||||||
|     print "usb.max 100" |     print("usb.max 100") | ||||||
|     print "usb.info Fritzbox usb devices power consumption" |     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 __name__ == "__main__": | ||||||
|     if len(sys.argv) == 2 and sys.argv[1] == 'config': |     if len(sys.argv) == 2 and sys.argv[1] == "config": | ||||||
|         print_config() |         print_config() | ||||||
|     elif len(sys.argv) == 2 and sys.argv[1] == 'autoconf': |     elif len(sys.argv) == 2 and sys.argv[1] == "autoconf": | ||||||
|         print 'yes' |         print("yes") | ||||||
|     elif len(sys.argv) == 1 or len(sys.argv) == 2 and sys.argv[1] == 'fetch': |     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 |         # Some docs say it'll be called with fetch, some say no arg at all | ||||||
|         try: |         try: | ||||||
|             get_power_consumption() |             get_power_consumption() | ||||||
|   | |||||||
| @@ -1,4 +1,4 @@ | |||||||
| #!/usr/bin/env python | #!/usr/bin/env python3 | ||||||
| """ | """ | ||||||
|   fritzbox_traffic - A munin plugin for Linux to monitor AVM Fritzbox WAN traffic |   fritzbox_traffic - A munin plugin for Linux to monitor AVM Fritzbox WAN traffic | ||||||
|   Copyright (C) 2015 Christian Stade-Schuldt |   Copyright (C) 2015 Christian Stade-Schuldt | ||||||
| @@ -10,6 +10,12 @@ | |||||||
|   This plugin requires the fritzconnection plugin. To install it using pip: |   This plugin requires the fritzconnection plugin. To install it using pip: | ||||||
|   pip install fritzconnection |   pip install fritzconnection | ||||||
|   This plugin supports the following munin configuration parameters: |   This plugin supports the following munin configuration parameters: | ||||||
|  |  | ||||||
|  |   [fritzbox_*] | ||||||
|  |   env.fritzbox_ip [ip address of the fritzbox] | ||||||
|  |   env.fritzbox_username [fritzbox username] | ||||||
|  |   env.fritzbox_password [fritzbox password] | ||||||
|  |  | ||||||
|   #%# family=auto contrib |   #%# family=auto contrib | ||||||
|   #%# capabilities=autoconf |   #%# capabilities=autoconf | ||||||
| """ | """ | ||||||
| @@ -17,66 +23,74 @@ | |||||||
| import os | import os | ||||||
| import sys | import sys | ||||||
|  |  | ||||||
| from fritzconnection import FritzConnection | from fritzconnection.lib.fritzstatus import FritzStatus | ||||||
|  |  | ||||||
|  | server = os.environ["fritzbox_ip"] | ||||||
|  | username = os.environ["fritzbox_username"] | ||||||
|  | password = os.environ["fritzbox_password"] | ||||||
|  |  | ||||||
|  |  | ||||||
| def print_values(): | def print_values(): | ||||||
|     try: |     try: | ||||||
|         conn = FritzConnection(address=os.environ['fritzbox_ip']) |         fs = FritzStatus(address=server, user=username, password=password) | ||||||
|     except Exception as e: |     except Exception as e: | ||||||
|         sys.exit("Couldn't get WAN traffic") |         sys.exit("Couldn't get WAN traffic") | ||||||
|  |  | ||||||
|     down_traffic = conn.call_action('WANCommonInterfaceConfig', 'GetTotalBytesReceived')['NewTotalBytesReceived'] |     traffic = fs.transmission_rate | ||||||
|     print ('down.value %d' % down_traffic) |     down_traffic = traffic[1] | ||||||
|  |     print("down.value %d" % down_traffic) | ||||||
|  |  | ||||||
|     up_traffic = conn.call_action('WANCommonInterfaceConfig', 'GetTotalBytesSent')['NewTotalBytesSent'] |     up_traffic = traffic[0] | ||||||
|     print ('up.value %d' % up_traffic) |     print("up.value %d" % up_traffic) | ||||||
|  |  | ||||||
|     max_down_traffic = conn.call_action('WANCommonInterfaceConfig', 'GetCommonLinkProperties')[ |     if not os.environ.get("traffic_remove_max"): | ||||||
|         'NewLayer1DownstreamMaxBitRate'] |         max_traffic = fs.max_bit_rate | ||||||
|     print ('maxdown.value %d' % max_down_traffic) |         max_down_traffic = max_traffic[1] | ||||||
|  |         print("maxdown.value %d" % max_down_traffic) | ||||||
|  |  | ||||||
|     max_up_traffic = conn.call_action('WANCommonInterfaceConfig', 'GetCommonLinkProperties')[ |         max_up_traffic = max_traffic[0] | ||||||
|         'NewLayer1UpstreamMaxBitRate'] |         print("maxup.value %d" % max_up_traffic) | ||||||
|     print ('maxup.value %d' % max_up_traffic) |  | ||||||
|  |  | ||||||
|  |  | ||||||
| def print_config(): | def print_config(): | ||||||
|     print "graph_title AVM Fritz!Box WAN traffic" |     print("graph_title AVM Fritz!Box WAN traffic") | ||||||
|     print "graph_args --base 1000" |     print("graph_args --base 1000") | ||||||
|     print "graph_vlabel bits in (-) / out (+) per \${graph_period}" |     print("graph_vlabel bits in (-) / out (+) per \${graph_period}") | ||||||
|     print "graph_category network" |     print("graph_category network") | ||||||
|     print "graph_order down up maxdown maxup" |     print("graph_order down up maxdown maxup") | ||||||
|     print "down.label received" |     print("down.label received") | ||||||
|     print "down.type DERIVE" |     print("down.type DERIVE") | ||||||
|     print "down.graph no" |     print("down.graph no") | ||||||
|     print "down.cdef down,8,*" |     print("down.cdef down,8,*") | ||||||
|     print "down.min 0" |     print("down.min 0") | ||||||
|     print "down.max 1000000000" |     print("down.max 1000000000") | ||||||
|     print "up.label bps" |     print("up.label bps") | ||||||
|     print "up.type DERIVE" |     print("up.type DERIVE") | ||||||
|     print "up.draw AREA" |     print("up.draw AREA") | ||||||
|     print "up.cdef up,8,*" |     print("up.cdef up,8,*") | ||||||
|     print "up.min 0" |     print("up.min 0") | ||||||
|     print "up.max 1000000000" |     print("up.max 1000000000") | ||||||
|     print "up.negative down" |     print("up.negative down") | ||||||
|     print "up.info Traffic of the WAN interface." |     print("up.info Traffic of the WAN interface.") | ||||||
|     print "maxdown.label received" |     if not os.environ.get("traffic_remove_max"): | ||||||
|     print "maxdown.type GAUGE" |         print("maxdown.label received") | ||||||
|     print "maxdown.graph no" |         print("maxdown.type GAUGE") | ||||||
|     print "maxup.label MAX" |         print("maxdown.graph no") | ||||||
|     print "maxup.type GAUGE" |         print("maxup.label MAX") | ||||||
|     print "maxup.negative maxdown" |         print("maxup.type GAUGE") | ||||||
|     print "maxup.draw LINE1" |         print("maxup.negative maxdown") | ||||||
|     print "maxup.info Maximum speed of the WAN interface." |         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 __name__ == "__main__": | ||||||
|     if len(sys.argv) == 2 and sys.argv[1] == 'config': |     if len(sys.argv) == 2 and sys.argv[1] == "config": | ||||||
|         print_config() |         print_config() | ||||||
|     elif len(sys.argv) == 2 and sys.argv[1] == 'autoconf': |     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 |         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'): |     elif len(sys.argv) == 1 or (len(sys.argv) == 2 and sys.argv[1] == "fetch"): | ||||||
|         try: |         try: | ||||||
|             print_values() |             print_values() | ||||||
|         except: |         except: | ||||||
|   | |||||||
| @@ -1,4 +1,4 @@ | |||||||
| #!/usr/bin/env python | #!/usr/bin/env python3 | ||||||
| """ | """ | ||||||
|   fritzbox_uptime - A munin plugin for Linux to monitor AVM Fritzbox |   fritzbox_uptime - A munin plugin for Linux to monitor AVM Fritzbox | ||||||
|   Copyright (C) 2015 Christian Stade-Schuldt |   Copyright (C) 2015 Christian Stade-Schuldt | ||||||
| @@ -9,60 +9,74 @@ | |||||||
|  |  | ||||||
|   [fritzbox_*] |   [fritzbox_*] | ||||||
|   env.fritzbox_ip [ip address of the fritzbox] |   env.fritzbox_ip [ip address of the fritzbox] | ||||||
|  |   env.fritzbox_username [fritzbox username] | ||||||
|   env.fritzbox_password [fritzbox password] |   env.fritzbox_password [fritzbox password] | ||||||
|  |  | ||||||
|   This plugin supports the following munin configuration parameters: |   This plugin supports the following munin configuration parameters: | ||||||
|   #%# family=auto contrib |   #%# family=auto contrib | ||||||
|   #%# capabilities=autoconf |   #%# capabilities=autoconf | ||||||
| """ | """ | ||||||
|  | import json | ||||||
| import os | import os | ||||||
| import re | import re | ||||||
| import sys | import sys | ||||||
|  |  | ||||||
| import fritzbox_helper as fh | import fritzbox_helper as fh | ||||||
|  |  | ||||||
| PAGE = '/system/energy.lua' | locale = os.environ.get("locale", "de") | ||||||
| pattern = re.compile("(\d+)\s(Tag|Stunden|Minuten)") | 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(): | def get_uptime(): | ||||||
|     """get the current uptime""" |     """get the current uptime""" | ||||||
|  |  | ||||||
|     server = os.environ['fritzbox_ip'] |     server = os.environ["fritzbox_ip"] | ||||||
|     password = os.environ['fritzbox_password'] |     username = os.environ["fritzbox_username"] | ||||||
|  |     password = os.environ["fritzbox_password"] | ||||||
|  |  | ||||||
|     sid = fh.get_sid(server, password) |     session_id = fh.get_session_id(server, username, password) | ||||||
|     data = fh.get_page(server, sid, PAGE) |     xhr_data = fh.get_xhr_content(server, session_id, PAGE) | ||||||
|     matches = re.finditer(pattern, data) |     data = json.loads(xhr_data) | ||||||
|     if matches: |     for d in data["data"]["drain"]: | ||||||
|         hours = 0.0 |         if "aktiv" in d["statuses"]: | ||||||
|         for m in matches: |             matches = re.finditer(pattern, d["statuses"]) | ||||||
|             if m.group(2) == 'Tag': |             if matches: | ||||||
|                 hours += 24 * int(m.group(1)) |                 hours = 0.0 | ||||||
|             if m.group(2) == "Stunden": |                 for m in matches: | ||||||
|                 hours += int(m.group(1)) |                     if m.group(2) == dayLoc[locale]: | ||||||
|             if m.group(2) == "Minuten": |                         hours += 24 * int(m.group(1)) | ||||||
|                 hours += int(m.group(1)) / 60.0 |                     if m.group(2) == hourLoc[locale]: | ||||||
|         uptime = hours / 24 |                         hours += int(m.group(1)) | ||||||
|         print "uptime.value %.2f" % uptime |                     if m.group(2) == minutesLoc[locale]: | ||||||
|  |                         hours += int(m.group(1)) / 60.0 | ||||||
|  |                 uptime = hours / 24 | ||||||
|  |                 print("uptime.value %.2f" % uptime) | ||||||
|  |  | ||||||
|  |  | ||||||
| def print_config(): | def print_config(): | ||||||
|     print "graph_title AVM Fritz!Box Uptime" |     print("graph_title AVM Fritz!Box Uptime") | ||||||
|     print "graph_args --base 1000 -l 0" |     print("graph_args --base 1000 -l 0") | ||||||
|     print 'graph_vlabel uptime in days' |     print("graph_vlabel uptime in days") | ||||||
|     print "graph_scale no'" |     print("graph_scale no'") | ||||||
|     print "graph_category system" |     print("graph_category system") | ||||||
|     print "uptime.label uptime" |     print("uptime.label uptime") | ||||||
|     print "uptime.draw AREA" |     print("uptime.draw AREA") | ||||||
|  |     if os.environ.get("host_name"): | ||||||
|  |         print("host_name " + os.environ["host_name"]) | ||||||
|  |  | ||||||
|  |  | ||||||
| if __name__ == '__main__': | if __name__ == "__main__": | ||||||
|     if len(sys.argv) == 2 and sys.argv[1] == 'config': |     if len(sys.argv) == 2 and sys.argv[1] == "config": | ||||||
|         print_config() |         print_config() | ||||||
|     elif len(sys.argv) == 2 and sys.argv[1] == 'autoconf': |     elif len(sys.argv) == 2 and sys.argv[1] == "autoconf": | ||||||
|         print 'yes' |         print("yes") | ||||||
|     elif len(sys.argv) == 1 or len(sys.argv) == 2 and sys.argv[1] == 'fetch': |     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 |         # Some docs say it'll be called with fetch, some say no arg at all | ||||||
|         try: |         try: | ||||||
|             get_uptime() |             get_uptime() | ||||||
|   | |||||||
| @@ -1,4 +1,4 @@ | |||||||
| #!/usr/bin/env python | #!/usr/bin/env python3 | ||||||
| """ | """ | ||||||
|   fritzbox_wifi_devices - A munin plugin for Linux to monitor AVM Fritzbox |   fritzbox_wifi_devices - A munin plugin for Linux to monitor AVM Fritzbox | ||||||
|   Copyright (C) 2015 Christian Stade-Schuldt |   Copyright (C) 2015 Christian Stade-Schuldt | ||||||
| @@ -9,54 +9,63 @@ | |||||||
|  |  | ||||||
|   [fritzbox_*] |   [fritzbox_*] | ||||||
|   env.fritzbox_ip [ip address of the fritzbox] |   env.fritzbox_ip [ip address of the fritzbox] | ||||||
|  |   env.fritzbox_username [fritzbox username] | ||||||
|   env.fritzbox_password [fritzbox password] |   env.fritzbox_password [fritzbox password] | ||||||
|    |    | ||||||
|   This plugin supports the following munin configuration parameters: |   This plugin supports the following munin configuration parameters: | ||||||
|   #%# family=auto contrib |   #%# family=auto contrib | ||||||
|   #%# capabilities=autoconf |   #%# capabilities=autoconf | ||||||
| """ | """ | ||||||
|  | import json | ||||||
| import os | import os | ||||||
| import re | import re | ||||||
| import sys | import sys | ||||||
|  |  | ||||||
| import fritzbox_helper as fh | import fritzbox_helper as fh | ||||||
|  |  | ||||||
| PAGE = '/system/energy.lua' | locale = os.environ.get("locale", "de") | ||||||
| pattern = re.compile("(\d+) WLAN") | patternLoc = {"de": r"(\d+) WLAN", "en": r"(\d+) wireless LAN"} | ||||||
|  |  | ||||||
|  | PAGE = "energy" | ||||||
|  | pattern = re.compile(patternLoc[locale]) | ||||||
|  |  | ||||||
|  |  | ||||||
| def get_connected_wifi_devices(): | def get_connected_wifi_devices(): | ||||||
|     """gets the numbrer of currently connected wifi devices""" |     """gets the numbrer of currently connected wifi devices""" | ||||||
|  |  | ||||||
|     server = os.environ['fritzbox_ip'] |     server = os.environ["fritzbox_ip"] | ||||||
|     password = os.environ['fritzbox_password'] |     username = os.environ["fritzbox_username"] | ||||||
|  |     password = os.environ["fritzbox_password"] | ||||||
|  |  | ||||||
|     sid = fh.get_sid(server, password) |     session_id = fh.get_session_id(server, username, password) | ||||||
|     data = fh.get_page(server, sid, PAGE) |     xhr_data = fh.get_xhr_content(server, session_id, PAGE) | ||||||
|     m = re.search(pattern, data) |     data = json.loads(xhr_data) | ||||||
|  |     m = re.search(pattern, data["data"]["drain"][2]["statuses"][-1]) | ||||||
|     if m: |     if m: | ||||||
|         connected_devices = int(m.group(1)) |         connected_devices = int(m.group(1)) | ||||||
|         print 'wifi.value %d' % connected_devices |         print("wifi.value %d" % connected_devices) | ||||||
|  |  | ||||||
|  |  | ||||||
| def print_config(): | def print_config(): | ||||||
|     print 'graph_title AVM Fritz!Box Connected Wifi Devices' |     print("graph_title AVM Fritz!Box Connected Wifi Devices") | ||||||
|     print 'graph_vlabel Number of devices' |     print("graph_vlabel Number of devices") | ||||||
|     print 'graph_args --base 1000' |     print("graph_args --base 1000") | ||||||
|     print 'graph_category network' |     print("graph_category network") | ||||||
|     print 'graph_order wifi' |     print("graph_order wifi") | ||||||
|     print 'wifi.label Wifi Connections on 2.4 & 5 Ghz' |     print("wifi.label Wifi Connections on 2.4 & 5 Ghz") | ||||||
|     print 'wifi.type GAUGE' |     print("wifi.type GAUGE") | ||||||
|     print 'wifi.graph LINE1' |     print("wifi.graph LINE1") | ||||||
|     print 'wifi.info Wifi Connections on 2.4 & 5 Ghz' |     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 __name__ == "__main__": | ||||||
|     if len(sys.argv) == 2 and sys.argv[1] == 'config': |     if len(sys.argv) == 2 and sys.argv[1] == "config": | ||||||
|         print_config() |         print_config() | ||||||
|     elif len(sys.argv) == 2 and sys.argv[1] == 'autoconf': |     elif len(sys.argv) == 2 and sys.argv[1] == "autoconf": | ||||||
|         print 'yes' |         print("yes") | ||||||
|     elif len(sys.argv) == 1 or len(sys.argv) == 2 and sys.argv[1] == 'fetch': |     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 |         # Some docs say it'll be called with fetch, some say no arg at all | ||||||
|         try: |         try: | ||||||
|             get_connected_wifi_devices() |             get_connected_wifi_devices() | ||||||
|   | |||||||
							
								
								
									
										3
									
								
								requirements.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								requirements.txt
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,3 @@ | |||||||
|  | fritzconnection | ||||||
|  | lxml | ||||||
|  | requests | ||||||
		Reference in New Issue
	
	Block a user