1
0
mirror of https://github.com/Tafkas/fritzbox-munin.git synced 2023-10-10 11:36:55 +00:00

Merge fabad1fdd51a39617f21894c2e592f8cda5bfcc7 into eee98feeacb0266e31a509cbb34abaa6c2a5f12c

This commit is contained in:
Olivier Mehani 2021-03-26 12:17:31 +01:00 committed by GitHub
commit 24934ec839
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 132 additions and 81 deletions

View File

@ -85,7 +85,8 @@ If you are using the scripts on a different Fritz!Box model please let me know b
[fritzbox_*] [fritzbox_*]
env.fritzbox_ip <ip_address_to_your_fritzbox> env.fritzbox_ip <ip_address_to_your_fritzbox>
env.fritzbox_password <fritzbox_password> env.FRITZ_USERNAME <optional: fritzbox username>
env.FRITZ_PASSWORD <FRITZ_PASSWORD>
env.traffic_remove_max true # if you do not want the possible max values env.traffic_remove_max true # if you do not want the possible max values
host_name fritzbox host_name fritzbox

View File

@ -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
@ -22,15 +22,19 @@ from fritzconnection import FritzConnection
def print_values(): def print_values():
try: try:
conn = FritzConnection(address=os.environ['fritzbox_ip']) conn = FritzConnection(address=os.getenv('fritzbox_ip'))
except Exception as e: except Exception as e:
sys.exit("Couldn't get connection uptime") sys.exit(f"Couldn't get connection uptime: {e}")
uptime = conn.call_action('WANIPConnection', 'GetStatusInfo')['NewUptime'] uptime = conn.call_action('WANIPConnection', 'GetStatusInfo')['NewUptime']
print('uptime.value %.2f' % (int(uptime) / 86400.0)) print('uptime.value %.2f' % (int(uptime) / 86400.0))
def print_config(): def print_config():
if os.environ.get('host_name'):
print("host_name " + os.getenv('host_name'))
print("graph_title Connection Uptime")
else:
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')
@ -38,8 +42,6 @@ def print_config():
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__":
@ -50,5 +52,5 @@ if __name__ == "__main__":
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 Exception as e:
sys.exit("Couldn't retrieve fritzbox connection uptime") sys.exit(f"Couldn't retrieve fritzbox connection uptime: {e}")

View File

@ -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,7 +9,8 @@
[fritzbox_*] [fritzbox_*]
env.fritzbox_ip [ip address of the fritzbox] env.fritzbox_ip [ip address of the fritzbox]
env.fritzbox_password [fritzbox password] env.FRITZ_PASSWORD [fritzbox password]
env.FRITZ_USERNAME [optional: fritzbox username]
This plugin supports the following munin configuration parameters: This plugin supports the following munin configuration parameters:
#%# family=auto contrib #%# family=auto contrib
@ -26,9 +27,13 @@ PAGE = 'ecoStat'
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.getenv('fritzbox_ip')
password = os.environ['fritzbox_password'] password = os.getenv('FRITZ_PASSWORD')
if "FRITZ_USERNAME" in os.environ:
fritzuser = os.getenv('FRITZ_USERNAME')
session_id = fh.get_session_id(server, password, fritzuser)
else:
session_id = fh.get_session_id(server, password) session_id = fh.get_session_id(server, password)
xhr_data = fh.get_xhr_content(server, session_id, PAGE) xhr_data = fh.get_xhr_content(server, session_id, PAGE)
data = json.loads(xhr_data) data = json.loads(xhr_data)
@ -36,6 +41,10 @@ def get_cpu_temperature():
def print_config(): def print_config():
if os.environ.get('host_name'):
print("host_name " + os.getenv('host_name'))
print("graph_title Temperatures")
else:
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")
@ -46,8 +55,6 @@ def print_config():
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__':

View File

@ -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,7 +9,8 @@
[fritzbox_*] [fritzbox_*]
env.fritzbox_ip [ip address of the fritzbox] env.fritzbox_ip [ip address of the fritzbox]
env.fritzbox_password [fritzbox password] env.FRITZ_PASSWORD [fritzbox password]
env.FRITZ_USERNAME [optional: fritzbox username]
This plugin supports the following munin configuration parameters: This plugin supports the following munin configuration parameters:
#%# family=auto contrib #%# family=auto contrib
@ -26,9 +27,13 @@ PAGE = 'ecoStat'
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.getenv('fritzbox_ip')
password = os.environ['fritzbox_password'] password = os.getenv('FRITZ_PASSWORD')
if "FRITZ_USERNAME" in os.environ:
fritzuser = os.getenv('FRITZ_USERNAME')
session_id = fh.get_session_id(server, password, fritzuser)
else:
session_id = fh.get_session_id(server, password) session_id = fh.get_session_id(server, password)
xhr_data = fh.get_xhr_content(server, session_id, PAGE) xhr_data = fh.get_xhr_content(server, session_id, PAGE)
data = json.loads(xhr_data) data = json.loads(xhr_data)
@ -36,6 +41,10 @@ def get_cpu_usage():
def print_config(): def print_config():
if os.environ.get('host_name'):
print("host_name " + os.getenv('host_name'))
print("graph_title CPU usage")
else :
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")
@ -46,8 +55,6 @@ def print_config():
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__':
@ -59,5 +66,5 @@ if __name__ == '__main__':
# 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()
except: except Exception as e:
sys.exit("Couldn't retrieve fritzbox cpu usage") sys.exit(f"Couldn't retrieve fritzbox cpu usage: {e}")

View File

@ -9,7 +9,8 @@
[fritzbox_*] [fritzbox_*]
env.fritzbox_ip [ip address of the fritzbox] env.fritzbox_ip [ip address of the fritzbox]
env.fritzbox_password [fritzbox password] env.FRITZ_PASSWORD [fritzbox password]
env.FRITZ_USERNAME [optional: fritzbox username]
This plugin supports the following munin configuration parameters: This plugin supports the following munin configuration parameters:
#%# family=auto contrib #%# 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" 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. """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 See https://avm.de/fileadmin/user_upload/Global/Service/Schnittstellen/AVM_Technical_Note_-_Session_ID.pdf
for deteils (in German). for deteils (in German).
:param server: the ip address of the Fritzbox :param server: the ip address of the Fritzbox
:param password: the password to log into the Fritzbox webinterface :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 :param port: the port the Fritzbox webserver runs on
:return: the session id :return: the session id
""" """
userpar = '' if username is None else '?username={}'.format(username)
headers = {"Accept": "application/xml", headers = {"Accept": "application/xml",
"Content-Type": "text/plain", "Content-Type": "text/plain",
"User-Agent": USER_AGENT} "User-Agent": USER_AGENT}
url = 'http://{}:{}/login_sid.lua'.format(server, port) url = 'http://{}:{}/login_sid.lua{}'.format(server, port, userpar)
try: try:
r = requests.get(url, headers=headers) r = requests.get(url, headers=headers)
r.raise_for_status() r.raise_for_status()
@ -67,7 +71,7 @@ def get_session_id(server, password, port=80):
"Content-Type": "application/x-www-form-urlencoded", "Content-Type": "application/x-www-form-urlencoded",
"User-Agent": USER_AGENT} "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: try:
r = requests.get(url, headers=headers) r = requests.get(url, headers=headers)
r.raise_for_status() r.raise_for_status()

View File

@ -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,7 +9,8 @@
[fritzbox_*] [fritzbox_*]
env.fritzbox_ip [ip address of the fritzbox] env.fritzbox_ip [ip address of the fritzbox]
env.fritzbox_password [fritzbox password] env.FRITZ_PASSWORD [fritzbox password]
env.FRITZ_USERNAME [optional: fritzbox username]
This plugin supports the following munin configuration parameters: This plugin supports the following munin configuration parameters:
#%# family=auto contrib #%# family=auto contrib
@ -27,9 +28,13 @@ USAGE = ['strict', 'cache', 'free']
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.getenv('fritzbox_ip')
password = os.environ['fritzbox_password'] password = os.getenv('FRITZ_PASSWORD')
if "FRITZ_USERNAME" in os.environ:
fritzuser = os.getenv('FRITZ_USERNAME')
session_id = fh.get_session_id(server, password, fritzuser)
else:
session_id = fh.get_session_id(server, password) session_id = fh.get_session_id(server, password)
xhr_data = fh.get_xhr_content(server, session_id, PAGE) xhr_data = fh.get_xhr_content(server, session_id, PAGE)
data = json.loads(xhr_data) data = json.loads(xhr_data)
@ -38,6 +43,10 @@ def get_memory_usage():
def print_config(): def print_config():
if os.environ.get('host_name'):
print("host_name " + os.getenv('host_name'))
print("graph_title Memory usage in percent")
else:
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")
@ -54,8 +63,6 @@ def print_config():
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__':
@ -67,5 +74,5 @@ if __name__ == '__main__':
# 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()
except: except Exception as e:
sys.exit("Couldn't retrieve fritzbox memory usage") sys.exit(f"Couldn't retrieve fritzbox memory usage: {e}")

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python3
# coding=utf-8 # 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
@ -10,7 +10,8 @@
[fritzbox_*] [fritzbox_*]
env.fritzbox_ip [ip address of the fritzbox] env.fritzbox_ip [ip address of the fritzbox]
env.fritzbox_password [fritzbox password] env.FRITZ_PASSWORD [fritzbox password]
env.FRITZ_USERNAME [optional: fritzbox username]
This plugin supports the following munin configuration parameters: This plugin supports the following munin configuration parameters:
#%# family=auto contrib #%# family=auto contrib
@ -29,9 +30,13 @@ 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.getenv('fritzbox_ip')
password = os.environ['fritzbox_password'] password = os.getenv('FRITZ_PASSWORD')
if "FRITZ_USERNAME" in os.environ:
fritzuser = os.getenv('FRITZ_USERNAME')
session_id = fh.get_session_id(server, password, fritzuser)
else:
session_id = fh.get_session_id(server, password) session_id = fh.get_session_id(server, password)
xhr_data = fh.get_xhr_content(server, session_id, PAGE) xhr_data = fh.get_xhr_content(server, session_id, PAGE)
data = json.loads(xhr_data) data = json.loads(xhr_data)
@ -41,9 +46,13 @@ def get_power_consumption():
def print_config(): def print_config():
if os.environ.get('host_name'):
print("host_name " + os.getenv('host_name'))
print("graph_title Power consumption")
else:
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 system") print("graph_category sensors")
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")
@ -81,8 +90,6 @@ def print_config():
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__':
@ -94,5 +101,5 @@ if __name__ == '__main__':
# 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()
except: except Exception as e:
sys.exit("Couldn't retrieve fritzbox power consumption") sys.exit(f"Couldn't retrieve fritzbox power consumption: {e}")

View File

@ -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
@ -22,9 +22,9 @@ from fritzconnection import FritzConnection
def print_values(): def print_values():
try: try:
conn = FritzConnection(address=os.environ['fritzbox_ip']) conn = FritzConnection(address=os.getenv('fritzbox_ip'))
except Exception as e: except Exception as e:
sys.exit("Couldn't get WAN traffic") sys.exit(f"Couldn't get WAN traffic: {e}")
down_traffic = conn.call_action('WANCommonInterfaceConfig', 'GetTotalBytesReceived')['NewTotalBytesReceived'] down_traffic = conn.call_action('WANCommonInterfaceConfig', 'GetTotalBytesReceived')['NewTotalBytesReceived']
print('down.value %d' % down_traffic) print('down.value %d' % down_traffic)
@ -43,6 +43,10 @@ def print_values():
def print_config(): def print_config():
if os.environ.get('host_name'):
print("host_name " + os.getenv('host_name'))
print("graph_title Uplink traffic")
else:
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}")
@ -56,7 +60,7 @@ def print_config():
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 LINE")
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")
@ -71,8 +75,6 @@ def print_config():
print("maxup.negative maxdown") print("maxup.negative maxdown")
print("maxup.draw LINE1") print("maxup.draw LINE1")
print("maxup.info Maximum speed of the WAN interface.") 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__":
@ -83,5 +85,5 @@ if __name__ == "__main__":
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 Exception as e:
sys.exit("Couldn't retrieve fritzbox traffic") sys.exit(f"Couldn't retrieve fritzbox traffic: {e}")

View File

@ -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,7 +9,8 @@
[fritzbox_*] [fritzbox_*]
env.fritzbox_ip [ip address of the fritzbox] env.fritzbox_ip [ip address of the fritzbox]
env.fritzbox_password [fritzbox password] env.FRITZ_PASSWORD [fritzbox password]
env.FRITZ_USERNAME [optional: fritzbox username]
This plugin supports the following munin configuration parameters: This plugin supports the following munin configuration parameters:
#%# family=auto contrib #%# family=auto contrib
@ -36,9 +37,13 @@ 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.getenv('fritzbox_ip')
password = os.environ['fritzbox_password'] password = os.getenv('FRITZ_PASSWORD')
if "FRITZ_USERNAME" in os.environ:
fritzuser = os.getenv('FRITZ_USERNAME')
session_id = fh.get_session_id(server, password, fritzuser)
else:
session_id = fh.get_session_id(server, password) session_id = fh.get_session_id(server, password)
xhr_data = fh.get_xhr_content(server, session_id, PAGE) xhr_data = fh.get_xhr_content(server, session_id, PAGE)
data = json.loads(xhr_data) data = json.loads(xhr_data)
@ -59,6 +64,10 @@ def get_uptime():
def print_config(): def print_config():
if os.environ.get('host_name'):
print("host_name " + os.getenv('host_name'))
print("graph_title Uptime")
else:
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')
@ -66,8 +75,6 @@ def print_config():
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__':
@ -79,5 +86,5 @@ if __name__ == '__main__':
# 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()
except: except Exception as e:
sys.exit("Couldn't retrieve fritzbox uptime") sys.exit(f"Couldn't retrieve fritzbox uptime; {e}")

View File

@ -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,7 +9,8 @@
[fritzbox_*] [fritzbox_*]
env.fritzbox_ip [ip address of the fritzbox] env.fritzbox_ip [ip address of the fritzbox]
env.fritzbox_password [fritzbox password] env.FRITZ_PASSWORD [fritzbox password]
env.FRITZ_USERNAME [optional: fritzbox username]
This plugin supports the following munin configuration parameters: This plugin supports the following munin configuration parameters:
#%# family=auto contrib #%# family=auto contrib
@ -31,11 +32,15 @@ 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 wi-fi devices"""
server = os.environ['fritzbox_ip'] server = os.getenv('fritzbox_ip')
password = os.environ['fritzbox_password'] password = os.getenv('FRITZ_PASSWORD')
if "FRITZ_USERNAME" in os.environ:
fritzuser = os.getenv('FRITZ_USERNAME')
session_id = fh.get_session_id(server, password, fritzuser)
else:
session_id = fh.get_session_id(server, password) session_id = fh.get_session_id(server, password)
xhr_data = fh.get_xhr_content(server, session_id, PAGE) xhr_data = fh.get_xhr_content(server, session_id, PAGE)
data = json.loads(xhr_data) data = json.loads(xhr_data)
@ -46,7 +51,11 @@ def get_connected_wifi_devices():
def print_config(): def print_config():
print('graph_title AVM Fritz!Box Connected Wifi Devices') if os.environ.get('host_name'):
print("host_name " + os.getenv('host_name'))
print('graph_title Connected Wi-Fi Devices')
else:
print('graph_title AVM Fritz!Box Connected Wi-Fi 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')
@ -55,8 +64,6 @@ def print_config():
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__':
@ -68,5 +75,5 @@ if __name__ == '__main__':
# 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()
except: except Exception as e:
sys.exit("Couldn't retrieve connected fritzbox wifi devices") sys.exit(f"Couldn't retrieve connected fritzbox wifi devices: {e}")