diff --git a/fritzbox_cpu_temperature.py b/fritzbox_cpu_temperature.py index d38015a..e22423a 100755 --- a/fritzbox_cpu_temperature.py +++ b/fritzbox_cpu_temperature.py @@ -10,6 +10,7 @@ [fritzbox_*] env.fritzbox_ip [ip address of the fritzbox] env.fritzbox_password [fritzbox password] + env.fritzbox_username [optional: fritzbox username] This plugin supports the following munin configuration parameters: #%# family=auto contrib @@ -29,7 +30,11 @@ def get_cpu_temperature(): server = os.environ['fritzbox_ip'] password = os.environ['fritzbox_password'] - session_id = fh.get_session_id(server, password) + if "fritzbox_username" in os.environ: + fritzuser = os.environ['fritzbox_username'] + session_id = fh.get_session_id(server, password, fritzuser) + else: + session_id = fh.get_session_id(server, password) xhr_data = fh.get_xhr_content(server, session_id, PAGE) data = json.loads(xhr_data) print('temp.value %d' % (int(data['data']['cputemp']['series'][0][-1]))) diff --git a/fritzbox_cpu_usage.py b/fritzbox_cpu_usage.py index 4f56321..bca1cd8 100755 --- a/fritzbox_cpu_usage.py +++ b/fritzbox_cpu_usage.py @@ -10,6 +10,7 @@ [fritzbox_*] env.fritzbox_ip [ip address of the fritzbox] env.fritzbox_password [fritzbox password] + env.fritzbox_username [optional: fritzbox username] This plugin supports the following munin configuration parameters: #%# family=auto contrib @@ -29,7 +30,11 @@ def get_cpu_usage(): server = os.environ['fritzbox_ip'] password = os.environ['fritzbox_password'] - session_id = fh.get_session_id(server, password) + if "fritzbox_username" in os.environ: + fritzuser = os.environ['fritzbox_username'] + session_id = fh.get_session_id(server, password, fritzuser) + else: + session_id = fh.get_session_id(server, password) xhr_data = fh.get_xhr_content(server, session_id, PAGE) data = json.loads(xhr_data) print('cpu.value %d' % (int(data['data']['cpuutil']['series'][0][-1]))) diff --git a/fritzbox_helper.py b/fritzbox_helper.py index 7c9fcd3..92a41c4 100755 --- a/fritzbox_helper.py +++ b/fritzbox_helper.py @@ -10,6 +10,7 @@ [fritzbox_*] env.fritzbox_ip [ip address of the fritzbox] env.fritzbox_password [fritzbox password] + env.fritzbox_username [optional: fritzbox username] This plugin supports the following munin configuration parameters: #%# family=auto contrib @@ -29,22 +30,25 @@ from lxml import etree USER_AGENT = "Mozilla/5.0 (Macintosh; Intel Mac OS X x.y; rv:10.0) Gecko/20100101 Firefox/10.0" -def get_session_id(server, password, port=80): +def get_session_id(server, password, username=None, port=80): """Obtains the session id after login into the Fritzbox. See https://avm.de/fileadmin/user_upload/Global/Service/Schnittstellen/AVM_Technical_Note_-_Session_ID.pdf for deteils (in German). :param server: the ip address of the Fritzbox :param password: the password to log into the Fritzbox webinterface + :param username: (optional) the username with which to log into the Fritzbox webinterface :param port: the port the Fritzbox webserver runs on :return: the session id """ + userpar = '' if username is None else '?username={}'.format(username) + headers = {"Accept": "application/xml", "Content-Type": "text/plain", "User-Agent": USER_AGENT} - url = 'http://{}:{}/login_sid.lua'.format(server, port) + url = 'http://{}:{}/login_sid.lua{}'.format(server, port, userpar) try: r = requests.get(url, headers=headers) r.raise_for_status() @@ -67,7 +71,7 @@ def get_session_id(server, password, port=80): "Content-Type": "application/x-www-form-urlencoded", "User-Agent": USER_AGENT} - url = 'http://{}:{}/login_sid.lua?&response={}'.format(server, port, response_bf) + url = 'http://{}:{}/login_sid.lua?{}&response={}'.format(server, port, userpar[1:], response_bf) try: r = requests.get(url, headers=headers) r.raise_for_status() diff --git a/fritzbox_memory_usage.py b/fritzbox_memory_usage.py index a73d13b..0965d66 100755 --- a/fritzbox_memory_usage.py +++ b/fritzbox_memory_usage.py @@ -10,6 +10,7 @@ [fritzbox_*] env.fritzbox_ip [ip address of the fritzbox] env.fritzbox_password [fritzbox password] + env.fritzbox_username [optional: fritzbox username] This plugin supports the following munin configuration parameters: #%# family=auto contrib @@ -30,7 +31,11 @@ def get_memory_usage(): server = os.environ['fritzbox_ip'] password = os.environ['fritzbox_password'] - session_id = fh.get_session_id(server, password) + if "fritzbox_username" in os.environ: + fritzuser = os.environ['fritzbox_username'] + session_id = fh.get_session_id(server, password, fritzuser) + else: + session_id = fh.get_session_id(server, password) xhr_data = fh.get_xhr_content(server, session_id, PAGE) data = json.loads(xhr_data) for i, usage in enumerate(USAGE): diff --git a/fritzbox_power_consumption.py b/fritzbox_power_consumption.py index 9d71a76..a9ae572 100755 --- a/fritzbox_power_consumption.py +++ b/fritzbox_power_consumption.py @@ -11,6 +11,7 @@ [fritzbox_*] env.fritzbox_ip [ip address of the fritzbox] env.fritzbox_password [fritzbox password] + env.fritzbox_username [optional: fritzbox username] This plugin supports the following munin configuration parameters: #%# family=auto contrib @@ -32,7 +33,11 @@ def get_power_consumption(): server = os.environ['fritzbox_ip'] password = os.environ['fritzbox_password'] - session_id = fh.get_session_id(server, password) + if "fritzbox_username" in os.environ: + fritzuser = os.environ['fritzbox_username'] + session_id = fh.get_session_id(server, password, fritzuser) + else: + session_id = fh.get_session_id(server, password) xhr_data = fh.get_xhr_content(server, session_id, PAGE) data = json.loads(xhr_data) devices = data['data']['drain'] diff --git a/fritzbox_uptime.py b/fritzbox_uptime.py index 649c0d0..e0f5e7c 100755 --- a/fritzbox_uptime.py +++ b/fritzbox_uptime.py @@ -10,6 +10,7 @@ [fritzbox_*] env.fritzbox_ip [ip address of the fritzbox] env.fritzbox_password [fritzbox password] + env.fritzbox_username [optional: fritzbox username] This plugin supports the following munin configuration parameters: #%# family=auto contrib @@ -39,7 +40,11 @@ def get_uptime(): server = os.environ['fritzbox_ip'] password = os.environ['fritzbox_password'] - session_id = fh.get_session_id(server, password) + if "fritzbox_username" in os.environ: + fritzuser = os.environ['fritzbox_username'] + session_id = fh.get_session_id(server, password, fritzuser) + else: + session_id = fh.get_session_id(server, password) xhr_data = fh.get_xhr_content(server, session_id, PAGE) data = json.loads(xhr_data) for d in data['data']['drain']: diff --git a/fritzbox_wifi_devices.py b/fritzbox_wifi_devices.py index bc8e24c..b3a087c 100755 --- a/fritzbox_wifi_devices.py +++ b/fritzbox_wifi_devices.py @@ -10,6 +10,7 @@ [fritzbox_*] env.fritzbox_ip [ip address of the fritzbox] env.fritzbox_password [fritzbox password] + env.fritzbox_username [optional: fritzbox username] This plugin supports the following munin configuration parameters: #%# family=auto contrib @@ -36,7 +37,11 @@ def get_connected_wifi_devices(): server = os.environ['fritzbox_ip'] password = os.environ['fritzbox_password'] - session_id = fh.get_session_id(server, password) + if "fritzbox_username" in os.environ: + fritzuser = os.environ['fritzbox_username'] + session_id = fh.get_session_id(server, password, fritzuser) + else: + session_id = fh.get_session_id(server, password) xhr_data = fh.get_xhr_content(server, session_id, PAGE) data = json.loads(xhr_data) m = re.search(pattern, data['data']['drain'][2]['statuses'][-1])