diff --git a/README.md b/README.md index fea63f6..ca590fb 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,7 @@ If you are using FRITZ!OS 6.30 use the master branch. [fritzbox_*] env.fritzbox_ip + env.fritzbox_username env.fritzbox_password 3. Create symbolic links to /etc/munin/plugins. @@ -75,3 +76,19 @@ If you are using FRITZ!OS 6.30 use the master branch. Do not forget to restart the munin-node daemon as described in step 3 of the installation instructions above. + +## Multiple Fritz!Boxes + + To generate graphs for additional boxes create new symbolic links (like in step 3) but chgange the first part of th + e.g.: ```ln -s /usr/share/munin/plugins/fritzbox_uptime.py /etc/munin/plugins/freetz_uptime``` + + And create a new section in ```/etc/munin/plugin-cond.d/munin-node``` with the alternative name. + +``` +[freetz_*] +env.fritzbox_ip +env.fritzbox_username +env.fritzbox_password +``` + +Restart the munin-node daemon. \ No newline at end of file diff --git a/fritzbox_connection_uptime.py b/fritzbox_connection_uptime.py index c16229c..2f01474 100755 --- a/fritzbox_connection_uptime.py +++ b/fritzbox_connection_uptime.py @@ -19,6 +19,9 @@ from fritzconnection import FritzConnection +# bet box name from first part before '_' in (symlink) file name +boxname = os.path.basename(__file__).rsplit('_')[0] + def print_values(): try: @@ -31,6 +34,7 @@ def print_values(): def print_config(): + print "host_name %s" % boxname print "graph_title AVM Fritz!Box Connection Uptime" print "graph_args --base 1000 -l 0" print 'graph_vlabel uptime in days' diff --git a/fritzbox_cpu_temperature.py b/fritzbox_cpu_temperature.py index 1d6d9c7..90c6362 100755 --- a/fritzbox_cpu_temperature.py +++ b/fritzbox_cpu_temperature.py @@ -9,6 +9,7 @@ [fritzbox_*] env.fritzbox_ip [ip address of the fritzbox] + env.fritzbox_username [fritzbox username] env.fritzbox_password [fritzbox password] This plugin supports the following munin configuration parameters: @@ -24,14 +25,18 @@ PAGE = '/system/ecostat.lua' pattern = re.compile('Query\s=\s"(\d{1,3})') +# bet box name from first part before '_' in (symlink) file name +boxname = os.path.basename(__file__).rsplit('_')[0] + def get_cpu_temperature(): """get the current cpu temperature""" server = os.environ['fritzbox_ip'] + username = os.getenv('fritzbox_username', "None") password = os.environ['fritzbox_password'] - sid = fh.get_sid(server, password) + sid = fh.get_sid(server, username, password) data = fh.get_page(server, sid, PAGE) m = re.search(pattern, data) @@ -40,6 +45,7 @@ def get_cpu_temperature(): def print_config(): + print "host_name %s" % boxname 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 8bb1a4e..fa3217b 100755 --- a/fritzbox_cpu_usage.py +++ b/fritzbox_cpu_usage.py @@ -9,6 +9,7 @@ [fritzbox_*] env.fritzbox_ip [ip address of the fritzbox] + env.fritzbox_username[fritzbox username] env.fritzbox_password [fritzbox password] This plugin supports the following munin configuration parameters: @@ -24,14 +25,18 @@ PAGE = '/system/ecostat.lua' pattern = re.compile('Query1\s=\s"(\d{1,3})') +# bet box name from first part before '_' in (symlink) file name +boxname = os.path.basename(__file__).rsplit('_')[0] + def get_cpu_usage(): """get the current cpu usage""" server = os.environ['fritzbox_ip'] + username = os.getenv('fritzbox_username', "None") password = os.environ['fritzbox_password'] - sid = fh.get_sid(server, password) + sid = fh.get_sid(server, username, password) data = fh.get_page(server, sid, PAGE) m = re.search(pattern, data) @@ -40,6 +45,7 @@ def get_cpu_usage(): def print_config(): + print "host_name %s" % boxname print "graph_title AVM Fritz!Box CPU usage" print "graph_vlabel %" print "graph_category system" diff --git a/fritzbox_helper.py b/fritzbox_helper.py index c13c19c..991e29b 100755 --- a/fritzbox_helper.py +++ b/fritzbox_helper.py @@ -25,7 +25,7 @@ USER_AGENT = "Mozilla/5.0 (U; Windows NT 5.1; rv:5.0) Gecko/20100101 Firefox/5.0" -def get_sid(server, password, port=80): +def get_sid(server, username, password, port=80): """Obtains the sid after login into the fritzbox""" conn = httplib.HTTPConnection(server + ':' + str(port)) @@ -58,7 +58,10 @@ def get_sid(server, password, port=80): "Content-Type": "application/x-www-form-urlencoded", "User-Agent": USER_AGENT} - login_page = "/login_sid.lua?&response=" + response_bf + if username == '' or username == 'None': + login_page = "/login_sid.lua?&response=" + response_bf + else: + login_page = "/login_sid.lua?username=" + username + "&response=" + response_bf conn.request("GET", login_page, '', headers) response = conn.getresponse() data = response.read() @@ -69,6 +72,7 @@ def get_sid(server, password, port=80): sid = re.search("(.*?)", data).group(1) if sid == "0000000000000000": print "ERROR - No SID received because of invalid password" + sys.exit(0) return sid diff --git a/fritzbox_memory_usage.py b/fritzbox_memory_usage.py index a366af3..34bbff8 100755 --- a/fritzbox_memory_usage.py +++ b/fritzbox_memory_usage.py @@ -9,6 +9,7 @@ [fritzbox_*] env.fritzbox_ip [ip address of the fritzbox] + env.fritzbox_username [fritzbox username] env.fritzbox_password [fritzbox password] This plugin supports the following munin configuration parameters: @@ -25,14 +26,18 @@ pattern = re.compile('Query[1-3]\s="(\d{1,3})') USAGE = ['free', 'cache', 'strict'] +# bet box name from first part before '_' in (symlink) file name +boxname = os.path.basename(__file__).rsplit('_')[0] + def get_memory_usage(): """get the current memory usage""" server = os.environ['fritzbox_ip'] + username = os.getenv('fritzbox_username', "None") password = os.environ['fritzbox_password'] - sid = fh.get_sid(server, password) + sid = fh.get_sid(server, username, password) data = fh.get_page(server, sid, PAGE) matches = re.finditer(pattern, data) if matches: @@ -42,6 +47,7 @@ def get_memory_usage(): def print_config(): + print "host_name %s" % boxname 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 bbe06a8..2cbbac3 100755 --- a/fritzbox_power_consumption.py +++ b/fritzbox_power_consumption.py @@ -9,6 +9,7 @@ [fritzbox_*] env.fritzbox_ip [ip address of the fritzbox] + env.fritzbox_username [fritzbox username] env.fritzbox_password [fritzbox password] This plugin supports the following munin configuration parameters: @@ -25,14 +26,18 @@ pattern = re.compile('(.+?)"bar\s(act|fillonly)"(.+?)\s(\d{1,3})\s%') DEVICES = ['system', 'cpu', 'wifi', 'dsl', 'ab', 'usb'] +# bet box name from first part before '_' in (symlink) file name +boxname = os.path.basename(__file__).rsplit('_')[0] + def get_power_consumption(): """get the current power consumption usage""" server = os.environ['fritzbox_ip'] + username = os.getenv('fritzbox_username', "None") password = os.environ['fritzbox_password'] - sid = fh.get_sid(server, password) + sid = fh.get_sid(server, username, password) data = fh.get_page(server, sid, PAGE) matches = re.finditer(pattern, data) if matches: @@ -42,6 +47,7 @@ def get_power_consumption(): def print_config(): + print "host_name %s" % boxname print "graph_title AVM Fritz!Box Power Consumption" print "graph_vlabel %" print "graph_category network" diff --git a/fritzbox_traffic.py b/fritzbox_traffic.py index 256d4be..79d6c6b 100755 --- a/fritzbox_traffic.py +++ b/fritzbox_traffic.py @@ -19,6 +19,9 @@ from fritzconnection import FritzConnection +# bet box name from first part before '_' in (symlink) file name +boxname = os.path.basename(__file__).rsplit('_')[0] + def print_values(): try: @@ -42,6 +45,7 @@ def print_values(): def print_config(): + print "host_name %s" % boxname print "graph_title AVM Fritz!Box WAN traffic" print "graph_args --base 1000" print "graph_vlabel bits in (-) / out (+) per \${graph_period}" diff --git a/fritzbox_uptime.py b/fritzbox_uptime.py index d6e2878..582b348 100755 --- a/fritzbox_uptime.py +++ b/fritzbox_uptime.py @@ -9,6 +9,7 @@ [fritzbox_*] env.fritzbox_ip [ip address of the fritzbox] + env.fritzbox_username [fritzbox username] env.fritzbox_password [fritzbox password] This plugin supports the following munin configuration parameters: @@ -24,14 +25,18 @@ PAGE = '/system/energy.lua' pattern = re.compile("(\d+)\s(Tag|Stunden|Minuten)") +# bet box name from first part before '_' in (symlink) file name +boxname = os.path.basename(__file__).rsplit('_')[0] + def get_uptime(): """get the current uptime""" server = os.environ['fritzbox_ip'] + username = os.getenv('fritzbox_username', "None") password = os.environ['fritzbox_password'] - sid = fh.get_sid(server, password) + sid = fh.get_sid(server, username, password) data = fh.get_page(server, sid, PAGE) matches = re.finditer(pattern, data) if matches: @@ -48,6 +53,7 @@ def get_uptime(): def print_config(): + print "host_name %s" % boxname 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 8d9fded..fe4f5d1 100755 --- a/fritzbox_wifi_devices.py +++ b/fritzbox_wifi_devices.py @@ -9,6 +9,7 @@ [fritzbox_*] env.fritzbox_ip [ip address of the fritzbox] + env.fritzbox_username [fritzbox username] env.fritzbox_password [fritzbox password] This plugin supports the following munin configuration parameters: @@ -24,14 +25,18 @@ PAGE = '/system/energy.lua' pattern = re.compile("(\d+) WLAN") +# bet box name from first part before '_' in (symlink) file name +boxname = os.path.basename(__file__).rsplit('_')[0] + def get_connected_wifi_devices(): """gets the numbrer of currently connected wifi devices""" server = os.environ['fritzbox_ip'] + username = os.getenv('fritzbox_username', "None") password = os.environ['fritzbox_password'] - sid = fh.get_sid(server, password) + sid = fh.get_sid(server, username, password) data = fh.get_page(server, sid, PAGE) m = re.search(pattern, data) if m: @@ -40,6 +45,7 @@ def get_connected_wifi_devices(): def print_config(): + print "host_name %s" % boxname print 'graph_title AVM Fritz!Box Connected Wifi Devices' print 'graph_vlabel Number of devices' print 'graph_args --base 1000'