diff --git a/fritzbox_cpu_temperature.py b/fritzbox_cpu_temperature.py index ec5930d..53c6a53 100755 --- a/fritzbox_cpu_temperature.py +++ b/fritzbox_cpu_temperature.py @@ -22,21 +22,21 @@ import sys import fritzbox_helper as fh PAGE = '/system/ecostat.lua' -pattern = re.compile('.*\/(StatTemperature)".*=.*"(.*?)"') +pattern = re.compile(".*/(StatTemperature)\".*=.*\"(.*?)\"") def get_cpu_temperature(): """get the current cpu temperature""" - + server = os.environ['fritzbox_ip'] password = os.environ['fritzbox_password'] - + sid = fh.get_sid(server, password) data = fh.get_page(server, sid, PAGE) - + m = re.search(pattern, data) if m: - print 'temp.value %d' %(int(m.group(2).split(',')[0])) + print 'temp.value %d' % (int(m.group(2).split(',')[0])) def print_config(): @@ -58,7 +58,7 @@ if __name__ == '__main__': 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 + # Some docs say it'll be called with fetch, some say no arg at all try: get_cpu_temperature() except: diff --git a/fritzbox_cpu_usage.py b/fritzbox_cpu_usage.py index 4e780e4..72d76d5 100755 --- a/fritzbox_cpu_usage.py +++ b/fritzbox_cpu_usage.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +##!/usr/bin/env python """ fritzbox_cpu_usage - A munin plugin for Linux to monitor AVM Fritzbox Copyright (C) 2015 Christian Stade-Schuldt @@ -22,21 +22,21 @@ import sys import fritzbox_helper as fh PAGE = '/system/ecostat.lua' -pattern = re.compile('.*\/(StatCPU)".*=.*"(.*?)"') +pattern = re.compile(".*/(StatCPU)\".*=.*\"(.*?)\"") def get_cpu_usage(): """get the current cpu usage""" - + server = os.environ['fritzbox_ip'] password = os.environ['fritzbox_password'] - + sid = fh.get_sid(server, password) data = fh.get_page(server, sid, PAGE) - + m = re.search(pattern, data) if m: - print 'cpu.value %d' %(int(m.group(2).split(',')[0])) + print 'cpu.value %d' % (int(m.group(2).split(',')[0])) def print_config(): @@ -58,7 +58,7 @@ if __name__ == '__main__': 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 + # Some docs say it'll be called with fetch, some say no arg at all try: get_cpu_usage() except: diff --git a/fritzbox_memory_usage.py b/fritzbox_memory_usage.py index 9483b57..99e5f44 100755 --- a/fritzbox_memory_usage.py +++ b/fritzbox_memory_usage.py @@ -22,22 +22,22 @@ import sys import fritzbox_helper as fh PAGE = '/system/ecostat.lua' -pattern = re.compile('.*\/(StatRAM.*?)".*=.*"(.*?)"') +pattern = re.compile(".*/(StatRAM.*?)\".*=.*\"(.*?)\"") USAGE_MAPPING = {'StatRAMCacheUsed': 'cache', 'StatRAMPhysFree': 'free', 'StatRAMStrictlyUsed': 'strict'} def get_memory_usage(): """get the current memory usage""" - + server = os.environ['fritzbox_ip'] password = os.environ['fritzbox_password'] - + sid = fh.get_sid(server, password) data = fh.get_page(server, sid, PAGE) matches = re.finditer(pattern, data) if matches: for m in matches: - print'%s.value %d' % (USAGE_MAPPING[m.group(1)], int(m.group(2).split(',')[0])) + print'%s.value %d' % (USAGE_MAPPING[m.group(1)], int(m.group(2).split(',')[0])) def print_config(): @@ -65,7 +65,7 @@ if __name__ == '__main__': 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 + # Some docs say it'll be called with fetch, some say no arg at all try: get_memory_usage() except: diff --git a/fritzbox_power_consumption.py b/fritzbox_power_consumption.py index 467e9a0..220db67 100755 --- a/fritzbox_power_consumption.py +++ b/fritzbox_power_consumption.py @@ -22,22 +22,23 @@ import sys import fritzbox_helper as fh PAGE = '/system/energy.lua' -pattern = re.compile('.*\/(.*act?)".*=.*"(.*?)"') -DEVICE_MAPPING = { 'rate_abact' : 'ab', 'rate_dspact': 'dsl' , 'rate_sumact': 'system', - 'rate_systemact': 'cpu', 'rate_usbhostact': 'usb', 'rate_wlanact': 'wifi'} +pattern = re.compile(".*/(.*act?)\".*=.*\"(.*?)\"") +DEVICE_MAPPING = {'rate_abact': 'ab', 'rate_dspact': 'dsl', 'rate_sumact': 'system', + 'rate_systemact': 'cpu', 'rate_usbhostact': 'usb', 'rate_wlanact': 'wifi'} + def get_power_consumption(): """get the current power consumption usage""" - + server = os.environ['fritzbox_ip'] password = os.environ['fritzbox_password'] - + sid = fh.get_sid(server, password) data = fh.get_page(server, sid, PAGE) matches = re.finditer(pattern, data) if matches: for m in matches: - print'%s.value %d' % (DEVICE_MAPPING[m.group(1)], int(m.group(2))) + print'%s.value %d' % (DEVICE_MAPPING[m.group(1)], int(m.group(2))) def print_config(): @@ -89,7 +90,7 @@ if __name__ == '__main__': 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 + # Some docs say it'll be called with fetch, some say no arg at all try: get_power_consumption() except: diff --git a/fritzbox_traffic.py b/fritzbox_traffic.py index 411c537..8fbd73a 100755 --- a/fritzbox_traffic.py +++ b/fritzbox_traffic.py @@ -14,26 +14,31 @@ #%# capabilities=autoconf """ -import sys, os +import sys + from fritzconnection import FritzConnection + def print_values(): try: - connection = FritzConnection() + con = FritzConnection() except Exception as e: sys.exit("Couldn't get WAN traffic") - - down_traffic = connection.call_action('WANCommonInterfaceConfig', 'GetTotalBytesReceived')['NewTotalBytesReceived'] + + down_traffic = con.call_action('WANCommonInterfaceConfig', 'GetTotalBytesReceived')['NewTotalBytesReceived'] print ('down.value %d' % down_traffic) - - up_traffic = connection.call_action('WANCommonInterfaceConfig', 'GetTotalBytesSent')['NewTotalBytesSent'] + + up_traffic = con.call_action('WANCommonInterfaceConfig', 'GetTotalBytesSent')['NewTotalBytesSent'] print ('up.value %d' % up_traffic) - - max_down_traffic = connection.call_action('WANCommonInterfaceConfig', 'GetCommonLinkProperties')['NewLayer1DownstreamMaxBitRate'] + + max_down_traffic = con.call_action('WANCommonInterfaceConfig', 'GetCommonLinkProperties')[ + 'NewLayer1DownstreamMaxBitRate'] print ('maxdown.value %d' % max_down_traffic) - - max_up_traffic = connection.call_action('WANCommonInterfaceConfig', 'GetCommonLinkProperties')['NewLayer1UpstreamMaxBitRate'] - print ('maxup.value %d' % max_up_traffic) + + max_up_traffic = con.call_action('WANCommonInterfaceConfig', 'GetCommonLinkProperties')[ + 'NewLayer1UpstreamMaxBitRate'] + print ('maxup.value %d' % max_up_traffic) + def print_config(): print "graph_title AVM Fritz!Box WAN traffic" @@ -64,13 +69,14 @@ def print_config(): print "maxup.draw LINE1" print "maxup.info Maximum speed of the WAN interface." + 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 + 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") \ No newline at end of file + sys.exit("Couldn't retrieve fritzbox traffic") diff --git a/fritzbox_uptime.py b/fritzbox_uptime.py index 4149bd0..f1d7249 100755 --- a/fritzbox_uptime.py +++ b/fritzbox_uptime.py @@ -14,18 +14,21 @@ #%# capabilities=autoconf """ -import sys, os +import sys + from fritzconnection import FritzConnection + def print_values(): try: connection = FritzConnection() except Exception as e: sys.exit("Couldn't get connection uptime") - + uptime = connection.call_action('WANIPConnection', 'GetStatusInfo')['NewUptime'] - print ('uptime.value %.2f' % (int(uptime)/86400.0)) - + print ('uptime.value %.2f' % (int(uptime) / 86400.0)) + + def print_config(): print "graph_title AVM Fritz!Box Connection Uptime" print "graph_args --base 1000 -l 0" @@ -35,13 +38,14 @@ def print_config(): print "uptime.label uptime" print "uptime.draw AREA" + 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 + 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") \ No newline at end of file + sys.exit("Couldn't retrieve fritzbox connection uptime") diff --git a/fritzbox_wifi_devices.py b/fritzbox_wifi_devices.py index 41c629a..8d9fded 100755 --- a/fritzbox_wifi_devices.py +++ b/fritzbox_wifi_devices.py @@ -22,7 +22,7 @@ import sys import fritzbox_helper as fh PAGE = '/system/energy.lua' -pattern = re.compile('(\d+) WLAN') +pattern = re.compile("(\d+) WLAN") def get_connected_wifi_devices(): @@ -57,7 +57,7 @@ if __name__ == '__main__': 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 + # Some docs say it'll be called with fetch, some say no arg at all try: get_connected_wifi_devices() except: