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')