mirror of
https://github.com/Tafkas/fritzbox-munin.git
synced 2023-10-10 13:36:55 +02:00
Python3 compat and cleanup
Signed-off-by: Olivier Mehani <shtrom@ssji.net> Show exception message on error Signed-off-by: Olivier Mehani <shtrom@ssji.net> (cherry picked from commit 98d41e311c3c04f9ea87fc1e93104be8ef503762)
This commit is contained in:
parent
15cc928242
commit
f14ecaa4b3
@ -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,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 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))
|
||||||
@ -39,7 +39,7 @@ def print_config():
|
|||||||
print("uptime.label uptime")
|
print("uptime.label uptime")
|
||||||
print("uptime.draw AREA")
|
print("uptime.draw AREA")
|
||||||
if os.environ.get('host_name'):
|
if os.environ.get('host_name'):
|
||||||
print("host_name " + os.environ['host_name'])
|
print("host_name " + os.getenv('host_name'))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
@ -50,5 +50,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}")
|
||||||
|
@ -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
|
||||||
@ -27,11 +27,11 @@ 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['FRITZ_PASSWORD']
|
password = os.getenv('FRITZ_PASSWORD')
|
||||||
|
|
||||||
if "FRITZ_USERNAME" in os.environ:
|
if "FRITZ_USERNAME" in os.environ:
|
||||||
fritzuser = os.environ['FRITZ_USERNAME']
|
fritzuser = os.getenv('FRITZ_USERNAME')
|
||||||
session_id = fh.get_session_id(server, password, fritzuser)
|
session_id = fh.get_session_id(server, password, fritzuser)
|
||||||
else:
|
else:
|
||||||
session_id = fh.get_session_id(server, password)
|
session_id = fh.get_session_id(server, password)
|
||||||
@ -52,7 +52,7 @@ def print_config():
|
|||||||
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'):
|
if os.environ.get('host_name'):
|
||||||
print("host_name " + os.environ['host_name'])
|
print("host_name " + os.getenv('host_name'))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
@ -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
|
||||||
@ -27,11 +27,11 @@ 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['FRITZ_PASSWORD']
|
password = os.getenv('FRITZ_PASSWORD')
|
||||||
|
|
||||||
if "FRITZ_USERNAME" in os.environ:
|
if "FRITZ_USERNAME" in os.environ:
|
||||||
fritzuser = os.environ['FRITZ_USERNAME']
|
fritzuser = os.getenv('FRITZ_USERNAME')
|
||||||
session_id = fh.get_session_id(server, password, fritzuser)
|
session_id = fh.get_session_id(server, password, fritzuser)
|
||||||
else:
|
else:
|
||||||
session_id = fh.get_session_id(server, password)
|
session_id = fh.get_session_id(server, password)
|
||||||
@ -52,7 +52,7 @@ def print_config():
|
|||||||
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'):
|
if os.environ.get('host_name'):
|
||||||
print("host_name " + os.environ['host_name'])
|
print("host_name " + os.getenv('host_name'))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
@ -64,5 +64,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}")
|
||||||
|
@ -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
|
||||||
@ -28,11 +28,11 @@ 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['FRITZ_PASSWORD']
|
password = os.getenv('FRITZ_PASSWORD')
|
||||||
|
|
||||||
if "FRITZ_USERNAME" in os.environ:
|
if "FRITZ_USERNAME" in os.environ:
|
||||||
fritzuser = os.environ['FRITZ_USERNAME']
|
fritzuser = os.getenv('FRITZ_USERNAME')
|
||||||
session_id = fh.get_session_id(server, password, fritzuser)
|
session_id = fh.get_session_id(server, password, fritzuser)
|
||||||
else:
|
else:
|
||||||
session_id = fh.get_session_id(server, password)
|
session_id = fh.get_session_id(server, password)
|
||||||
@ -60,7 +60,7 @@ def print_config():
|
|||||||
print("free.type GAUGE")
|
print("free.type GAUGE")
|
||||||
print("free.draw STACK")
|
print("free.draw STACK")
|
||||||
if os.environ.get('host_name'):
|
if os.environ.get('host_name'):
|
||||||
print("host_name " + os.environ['host_name'])
|
print("host_name " + os.getenv('host_name'))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
@ -72,5 +72,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}")
|
||||||
|
@ -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
|
||||||
@ -30,11 +30,11 @@ 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['FRITZ_PASSWORD']
|
password = os.getenv('FRITZ_PASSWORD')
|
||||||
|
|
||||||
if "FRITZ_USERNAME" in os.environ:
|
if "FRITZ_USERNAME" in os.environ:
|
||||||
fritzuser = os.environ['FRITZ_USERNAME']
|
fritzuser = os.getenv('FRITZ_USERNAME')
|
||||||
session_id = fh.get_session_id(server, password, fritzuser)
|
session_id = fh.get_session_id(server, password, fritzuser)
|
||||||
else:
|
else:
|
||||||
session_id = fh.get_session_id(server, password)
|
session_id = fh.get_session_id(server, password)
|
||||||
@ -87,7 +87,7 @@ def print_config():
|
|||||||
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'):
|
if os.environ.get('host_name'):
|
||||||
print("host_name " + os.environ['host_name'])
|
print("host_name " + os.getenv('host_name'))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
@ -99,5 +99,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}")
|
||||||
|
@ -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)
|
||||||
@ -72,7 +72,7 @@ def print_config():
|
|||||||
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'):
|
if os.environ.get('host_name'):
|
||||||
print("host_name " + os.environ['host_name'])
|
print("host_name " + os.getenv('host_name'))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
@ -83,5 +83,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}")
|
||||||
|
@ -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
|
||||||
@ -37,11 +37,11 @@ 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['FRITZ_PASSWORD']
|
password = os.getenv('FRITZ_PASSWORD')
|
||||||
|
|
||||||
if "FRITZ_USERNAME" in os.environ:
|
if "FRITZ_USERNAME" in os.environ:
|
||||||
fritzuser = os.environ['FRITZ_USERNAME']
|
fritzuser = os.getenv('FRITZ_USERNAME')
|
||||||
session_id = fh.get_session_id(server, password, fritzuser)
|
session_id = fh.get_session_id(server, password, fritzuser)
|
||||||
else:
|
else:
|
||||||
session_id = fh.get_session_id(server, password)
|
session_id = fh.get_session_id(server, password)
|
||||||
@ -72,7 +72,7 @@ def print_config():
|
|||||||
print("uptime.label uptime")
|
print("uptime.label uptime")
|
||||||
print("uptime.draw AREA")
|
print("uptime.draw AREA")
|
||||||
if os.environ.get('host_name'):
|
if os.environ.get('host_name'):
|
||||||
print("host_name " + os.environ['host_name'])
|
print("host_name " + os.getenv('host_name'))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
@ -84,5 +84,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}")
|
||||||
|
@ -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
|
||||||
@ -34,11 +34,11 @@ 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 wifi devices"""
|
||||||
|
|
||||||
server = os.environ['fritzbox_ip']
|
server = os.getenv('fritzbox_ip')
|
||||||
password = os.environ['FRITZ_PASSWORD']
|
password = os.getenv('FRITZ_PASSWORD')
|
||||||
|
|
||||||
if "FRITZ_USERNAME" in os.environ:
|
if "FRITZ_USERNAME" in os.environ:
|
||||||
fritzuser = os.environ['FRITZ_USERNAME']
|
fritzuser = os.getenv('FRITZ_USERNAME')
|
||||||
session_id = fh.get_session_id(server, password, fritzuser)
|
session_id = fh.get_session_id(server, password, fritzuser)
|
||||||
else:
|
else:
|
||||||
session_id = fh.get_session_id(server, password)
|
session_id = fh.get_session_id(server, password)
|
||||||
@ -61,7 +61,7 @@ def print_config():
|
|||||||
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'):
|
if os.environ.get('host_name'):
|
||||||
print("host_name " + os.environ['host_name'])
|
print("host_name " + os.getenv('host_name'))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
@ -73,5 +73,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}")
|
||||||
|
Loading…
Reference in New Issue
Block a user