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

set unix mode

This commit is contained in:
oe73773 2020-07-12 20:27:16 +02:00
parent ace93c079c
commit aa3e8e7739
11 changed files with 802 additions and 802 deletions

122
fritzbox__connection_uptime.py Normal file → Executable file
View File

@ -1,61 +1,61 @@
#!/usr/bin/env python #!/usr/bin/env python
""" """
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
Author: Christian Stade-Schuldt Author: Christian Stade-Schuldt
Updated to fritzconnection library version 1.3.1 Updated to fritzconnection library version 1.3.1
Copyright (C) 2020 Oliver Edelamnn Copyright (C) 2020 Oliver Edelamnn
Author: Oliver Edelmann Author: Oliver Edelmann
Like Munin, this plugin is licensed under the GNU GPL v2 license Like Munin, this plugin is licensed under the GNU GPL v2 license
http://www.opensource.org/licenses/GPL-2.0 http://www.opensource.org/licenses/GPL-2.0
Like Munin, this plugin is licensed under the GNU GPL v2 license Like Munin, this plugin is licensed under the GNU GPL v2 license
http://www.opensource.org/licenses/GPL-2.0 http://www.opensource.org/licenses/GPL-2.0
This plugin requires the fritzconnection plugin. To install it using pip: This plugin requires the fritzconnection plugin. To install it using pip:
pip install fritzconnection pip install fritzconnection
This plugin supports the following munin configuration parameters: This plugin supports the following munin configuration parameters:
#%# family=auto contrib #%# family=auto contrib
#%# capabilities=autoconf #%# capabilities=autoconf
""" """
import os import os
import sys import sys
from fritzconnection.lib.fritzstatus import FritzStatus from fritzconnection.lib.fritzstatus import FritzStatus
hostname = os.path.basename(__file__).split('_')[1] hostname = os.path.basename(__file__).split('_')[1]
def print_values(): def print_values():
try: try:
conn = FritzStatus(address=hostname, password=os.environ['fritzbox_password']) conn = FritzStatus(address=hostname, password=os.environ['fritzbox_password'])
except Exception: except Exception:
sys.exit("Couldn't get connection uptime") sys.exit("Couldn't get connection uptime")
uptime = conn.uptime uptime = conn.uptime
print('uptime.value %.2f' % (int(uptime) / 3600.0)) print('uptime.value %.2f' % (int(uptime) / 3600.0))
def print_config(): def print_config():
print("host_name %s" % hostname) print("host_name %s" % hostname)
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 hours') print('graph_vlabel uptime in hours')
print("graph_scale no'") print("graph_scale no'")
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'): if os.environ.get('host_name'):
print("host_name " + os.environ['host_name']) print("host_name " + os.environ['host_name'])
if __name__ == "__main__": if __name__ == "__main__":
if len(sys.argv) == 2 and sys.argv[1] == 'config': if len(sys.argv) == 2 and sys.argv[1] == 'config':
print_config() print_config()
elif len(sys.argv) == 2 and sys.argv[1] == 'autoconf': elif len(sys.argv) == 2 and sys.argv[1] == 'autoconf':
print("yes") # Some docs say it'll be called with fetch, some say no arg at all print("yes") # Some docs say it'll be called with fetch, some say no arg at all
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:
sys.exit("Couldn't retrieve fritzbox connection uptime") sys.exit("Couldn't retrieve fritzbox connection uptime")

124
fritzbox__cpu_temperature.py Normal file → Executable file
View File

@ -1,62 +1,62 @@
#!/usr/bin/env python #!/usr/bin/env python
""" """
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
Author: Christian Stade-Schuldt Author: Christian Stade-Schuldt
Like Munin, this plugin is licensed under the GNU GPL v2 license Like Munin, this plugin is licensed under the GNU GPL v2 license
http://www.opensource.org/licenses/GPL-2.0 http://www.opensource.org/licenses/GPL-2.0
Add the following section to your munin-node's plugin configuration: Add the following section to your munin-node's plugin configuration:
[fritzbox_*] [fritzbox_*]
env.fritzbox_ip [ip address of the fritzbox] env.fritzbox_ip [ip address of the fritzbox]
env.fritzbox_password [fritzbox password] env.fritzbox_password [fritzbox password]
This plugin supports the following munin configuration parameters: This plugin supports the following munin configuration parameters:
#%# family=auto contrib #%# family=auto contrib
#%# capabilities=autoconf #%# capabilities=autoconf
""" """
import json import json
import os import os
import sys import sys
import fritzbox_helper as fh import fritzbox_helper as fh
PAGE = 'ecoStat' PAGE = 'ecoStat'
hostname = os.path.basename(__file__).split('_')[1] hostname = os.path.basename(__file__).split('_')[1]
def get_cpu_temperature(): def get_cpu_temperature():
"""get the current cpu temperature""" """get the current cpu temperature"""
server = hostname server = hostname
password = os.environ['fritzbox_password'] password = os.environ['fritzbox_password']
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)
print('temp.value %d' % (int(data['data']['cputemp']['series'][0][-1]))) print('temp.value %d' % (int(data['data']['cputemp']['series'][0][-1])))
def print_config(): def print_config():
print("host_name %s" % hostname) print("host_name %s" % hostname)
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")
print("graph_order tmp") print("graph_order tmp")
print("graph_scale no") print("graph_scale no")
print("temp.label CPU temperature") print("temp.label CPU temperature")
print("temp.type GAUGE") print("temp.type GAUGE")
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'): if os.environ.get('host_name'):
print("host_name " + os.environ['host_name']) print("host_name " + os.environ['host_name'])
if __name__ == '__main__': if __name__ == '__main__':
if len(sys.argv) == 2 and sys.argv[1] == 'config': if len(sys.argv) == 2 and sys.argv[1] == 'config':
print_config() print_config()
elif len(sys.argv) == 2 and sys.argv[1] == 'autoconf': elif len(sys.argv) == 2 and sys.argv[1] == 'autoconf':
print('yes') print('yes')
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':
# 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
get_cpu_temperature() get_cpu_temperature()

130
fritzbox__cpu_usage.py Normal file → Executable file
View File

@ -1,65 +1,65 @@
#!/usr/bin/env python #!/usr/bin/env python
""" """
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
Author: Christian Stade-Schuldt Author: Christian Stade-Schuldt
Like Munin, this plugin is licensed under the GNU GPL v2 license Like Munin, this plugin is licensed under the GNU GPL v2 license
http://www.opensource.org/licenses/GPL-2.0 http://www.opensource.org/licenses/GPL-2.0
Add the following section to your munin-node's plugin configuration: Add the following section to your munin-node's plugin configuration:
[fritzbox_*] [fritzbox_*]
env.fritzbox_ip [ip address of the fritzbox] env.fritzbox_ip [ip address of the fritzbox]
env.fritzbox_password [fritzbox password] env.fritzbox_password [fritzbox password]
This plugin supports the following munin configuration parameters: This plugin supports the following munin configuration parameters:
#%# family=auto contrib #%# family=auto contrib
#%# capabilities=autoconf #%# capabilities=autoconf
""" """
import json import json
import os import os
import sys import sys
import fritzbox_helper as fh import fritzbox_helper as fh
PAGE = 'ecoStat' PAGE = 'ecoStat'
hostname = os.path.basename(__file__).split('_')[1] hostname = os.path.basename(__file__).split('_')[1]
def get_cpu_usage(): def get_cpu_usage():
"""get the current cpu usage""" """get the current cpu usage"""
server = hostname server = hostname
password = os.environ['fritzbox_password'] password = os.environ['fritzbox_password']
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)
print('cpu.value %d' % (int(data['data']['cpuutil']['series'][0][-1]))) print('cpu.value %d' % (int(data['data']['cpuutil']['series'][0][-1])))
def print_config(): def print_config():
print("host_name %s" % hostname) print("host_name %s" % hostname)
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")
print("graph_order cpu") print("graph_order cpu")
print("graph_scale no") print("graph_scale no")
print("cpu.label system") print("cpu.label system")
print("cpu.type GAUGE") print("cpu.type GAUGE")
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'): if os.environ.get('host_name'):
print("host_name " + os.environ['host_name']) print("host_name " + os.environ['host_name'])
if __name__ == '__main__': if __name__ == '__main__':
if len(sys.argv) == 2 and sys.argv[1] == 'config': if len(sys.argv) == 2 and sys.argv[1] == 'config':
print_config() print_config()
elif len(sys.argv) == 2 and sys.argv[1] == 'autoconf': elif len(sys.argv) == 2 and sys.argv[1] == 'autoconf':
print('yes') print('yes')
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':
# 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:
sys.exit("Couldn't retrieve fritzbox cpu usage") sys.exit("Couldn't retrieve fritzbox cpu usage")

146
fritzbox__memory_usage.py Normal file → Executable file
View File

@ -1,73 +1,73 @@
#!/usr/bin/env python #!/usr/bin/env python
""" """
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
Author: Christian Stade-Schuldt Author: Christian Stade-Schuldt
Like Munin, this plugin is licensed under the GNU GPL v2 license Like Munin, this plugin is licensed under the GNU GPL v2 license
http://www.opensource.org/licenses/GPL-2.0 http://www.opensource.org/licenses/GPL-2.0
Add the following section to your munin-node's plugin configuration: Add the following section to your munin-node's plugin configuration:
[fritzbox_*] [fritzbox_*]
env.fritzbox_ip [ip address of the fritzbox] env.fritzbox_ip [ip address of the fritzbox]
env.fritzbox_password [fritzbox password] env.fritzbox_password [fritzbox password]
This plugin supports the following munin configuration parameters: This plugin supports the following munin configuration parameters:
#%# family=auto contrib #%# family=auto contrib
#%# capabilities=autoconf #%# capabilities=autoconf
""" """
import json import json
import os import os
import sys import sys
import fritzbox_helper as fh import fritzbox_helper as fh
PAGE = 'ecoStat' PAGE = 'ecoStat'
USAGE = ['strict', 'cache', 'free'] USAGE = ['strict', 'cache', 'free']
hostname = os.path.basename(__file__).split('_')[1] hostname = os.path.basename(__file__).split('_')[1]
def get_memory_usage(): def get_memory_usage():
"""get the current memory usage""" """get the current memory usage"""
server = hostname server = hostname
password = os.environ['fritzbox_password'] password = os.environ['fritzbox_password']
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)
for i, usage in enumerate(USAGE): for i, usage in enumerate(USAGE):
print('%s.value %s' % (usage, data['data']['ramusage']['series'][i][-1])) print('%s.value %s' % (usage, data['data']['ramusage']['series'][i][-1]))
def print_config(): def print_config():
print("host_name %s" % hostname) print("host_name %s" % hostname)
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")
print("graph_category system") print("graph_category system")
print("graph_order strict cache free") print("graph_order strict cache free")
print("graph_info This graph shows what the Fritzbox uses memory for.") print("graph_info This graph shows what the Fritzbox uses memory for.")
print("graph_scale no") print("graph_scale no")
print("strict.label strict") print("strict.label strict")
print("strict.type GAUGE") print("strict.type GAUGE")
print("strict.draw AREA") print("strict.draw AREA")
print("cache.label cache") print("cache.label cache")
print("cache.type GAUGE") print("cache.type GAUGE")
print("cache.draw STACK") print("cache.draw STACK")
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'): if os.environ.get('host_name'):
print("host_name " + os.environ['host_name']) print("host_name " + os.environ['host_name'])
if __name__ == '__main__': if __name__ == '__main__':
if len(sys.argv) == 2 and sys.argv[1] == 'config': if len(sys.argv) == 2 and sys.argv[1] == 'config':
print_config() print_config()
elif len(sys.argv) == 2 and sys.argv[1] == 'autoconf': elif len(sys.argv) == 2 and sys.argv[1] == 'autoconf':
print('yes') print('yes')
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':
# 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:
sys.exit("Couldn't retrieve fritzbox memory usage") sys.exit("Couldn't retrieve fritzbox memory usage")

198
fritzbox__power_consumption.py Normal file → Executable file
View File

@ -1,99 +1,99 @@
#!/usr/bin/env python #!/usr/bin/env python
# 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
Copyright (C) 2015 Christian Stade-Schuldt Copyright (C) 2015 Christian Stade-Schuldt
Author: Christian Stade-Schuldt Author: Christian Stade-Schuldt
Like Munin, this plugin is licensed under the GNU GPL v2 license Like Munin, this plugin is licensed under the GNU GPL v2 license
http://www.opensource.org/licenses/GPL-2.0 http://www.opensource.org/licenses/GPL-2.0
Add the following section to your munin-node's plugin configuration: Add the following section to your munin-node's plugin configuration:
[fritzbox_*] [fritzbox_*]
env.fritzbox_ip [ip address of the fritzbox] env.fritzbox_ip [ip address of the fritzbox]
env.fritzbox_password [fritzbox password] env.fritzbox_password [fritzbox password]
This plugin supports the following munin configuration parameters: This plugin supports the following munin configuration parameters:
#%# family=auto contrib #%# family=auto contrib
#%# capabilities=autoconf #%# capabilities=autoconf
""" """
import json import json
import os import os
import sys import sys
import fritzbox_helper as fh import fritzbox_helper as fh
PAGE = 'energy' PAGE = 'energy'
DEVICES = ['system', 'cpu', 'wifi', 'dsl', 'ab', 'usb'] DEVICES = ['system', 'cpu', 'wifi', 'dsl', 'ab', 'usb']
hostname = os.path.basename(__file__).split('_')[1] hostname = os.path.basename(__file__).split('_')[1]
def get_power_consumption(): def get_power_consumption():
"""get the current power consumption usage""" """get the current power consumption usage"""
server = hostname server = hostname
password = os.environ['fritzbox_password'] password = os.environ['fritzbox_password']
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)
devices = data['data']['drain'] devices = data['data']['drain']
for i, device in enumerate(DEVICES): for i, device in enumerate(DEVICES):
print('%s.value %s' % (device, devices[i]['actPerc'])) print('%s.value %s' % (device, devices[i]['actPerc']))
def print_config(): def print_config():
print("host_name %s" % hostname) print("host_name %s" % hostname)
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 system")
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")
print("system.graph LINE12") print("system.graph LINE12")
print("system.min 0") print("system.min 0")
print("system.max 100") print("system.max 100")
print("system.info Fritzbox overall power consumption") print("system.info Fritzbox overall power consumption")
print("cpu.label cpu") print("cpu.label cpu")
print("cpu.type GAUGE") print("cpu.type GAUGE")
print("cpu.graph LINE1") print("cpu.graph LINE1")
print("cpu.min 0") print("cpu.min 0")
print("cpu.max 100") print("cpu.max 100")
print("cpu.info Fritzbox central processor power consumption") print("cpu.info Fritzbox central processor power consumption")
print("wifi.label wifi") print("wifi.label wifi")
print("wifi.type GAUGE") print("wifi.type GAUGE")
print("wifi.graph LINE1") print("wifi.graph LINE1")
print("wifi.min 0") print("wifi.min 0")
print("wifi.max 100") print("wifi.max 100")
print("wifi.info Fritzbox wifi power consumption") print("wifi.info Fritzbox wifi power consumption")
print("dsl.label dsl") print("dsl.label dsl")
print("dsl.type GAUGE") print("dsl.type GAUGE")
print("dsl.graph LINE1") print("dsl.graph LINE1")
print("dsl.min 0") print("dsl.min 0")
print("dsl.max 100") print("dsl.max 100")
print("dsl.info Fritzbox dsl power consumption") print("dsl.info Fritzbox dsl power consumption")
print("ab.label ab") print("ab.label ab")
print("ab.type GAUGE") print("ab.type GAUGE")
print("ab.graph LINE1") print("ab.graph LINE1")
print("ab.min 0") print("ab.min 0")
print("ab.max 100") print("ab.max 100")
print("ab.info Fritzbox analog phone ports power consumption") print("ab.info Fritzbox analog phone ports power consumption")
print("usb.label usb") print("usb.label usb")
print("usb.type GAUGE") print("usb.type GAUGE")
print("usb.graph LINE1") print("usb.graph LINE1")
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'): if os.environ.get('host_name'):
print("host_name " + os.environ['host_name']) print("host_name " + os.environ['host_name'])
if __name__ == '__main__': if __name__ == '__main__':
if len(sys.argv) == 2 and sys.argv[1] == 'config': if len(sys.argv) == 2 and sys.argv[1] == 'config':
print_config() print_config()
elif len(sys.argv) == 2 and sys.argv[1] == 'autoconf': elif len(sys.argv) == 2 and sys.argv[1] == 'autoconf':
print('yes') print('yes')
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':
# 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:
sys.exit("Couldn't retrieve fritzbox power consumption") sys.exit("Couldn't retrieve fritzbox power consumption")

210
fritzbox__traffic.py Normal file → Executable file
View File

@ -1,105 +1,105 @@
#!/usr/bin/env python #!/usr/bin/env python
""" """
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
Author: Christian Stade-Schuldt Author: Christian Stade-Schuldt
Updated to fritzconnection library version 1.3.1 Updated to fritzconnection library version 1.3.1
Copyright (C) 2020 Oliver Edelamnn Copyright (C) 2020 Oliver Edelamnn
Author: Oliver Edelmann Author: Oliver Edelmann
Like Munin, this plugin is licensed under the GNU GPL v2 license Like Munin, this plugin is licensed under the GNU GPL v2 license
http://www.opensource.org/licenses/GPL-2.0 http://www.opensource.org/licenses/GPL-2.0
Like Munin, this plugin is licensed under the GNU GPL v2 license Like Munin, this plugin is licensed under the GNU GPL v2 license
http://www.opensource.org/licenses/GPL-2.0 http://www.opensource.org/licenses/GPL-2.0
This plugin requires the fritzconnection plugin. To install it using pip: This plugin requires the fritzconnection plugin. To install it using pip:
pip install fritzconnection pip install fritzconnection
This plugin supports the following munin configuration parameters: This plugin supports the following munin configuration parameters:
#%# family=auto contrib #%# family=auto contrib
#%# capabilities=autoconf #%# capabilities=autoconf
""" """
import os import os
import sys import sys
from fritzconnection.lib.fritzstatus import FritzStatus from fritzconnection.lib.fritzstatus import FritzStatus
hostname = os.path.basename(__file__).split('_')[1] hostname = os.path.basename(__file__).split('_')[1]
def print_values(): def print_values():
try: try:
conn = FritzStatus(address=hostname, password=os.environ['fritzbox_password']) conn = FritzStatus(address=hostname, password=os.environ['fritzbox_password'])
except Exception as e: except Exception as e:
print(e) print(e)
sys.exit("Couldn't get WAN traffic") sys.exit("Couldn't get WAN traffic")
traffic = conn.transmission_rate traffic = conn.transmission_rate
up = traffic[0]*8 up = traffic[0]*8
down = traffic[1]*8 down = traffic[1]*8
print('down.value %d' % down) print('down.value %d' % down)
print('up.value %d' % up) print('up.value %d' % up)
if not os.environ.get('traffic_remove_max') or "false" in os.environ.get('traffic_remove_max'): if not os.environ.get('traffic_remove_max') or "false" in os.environ.get('traffic_remove_max'):
max_traffic = conn.max_bit_rate max_traffic = conn.max_bit_rate
print('maxdown.value %d' % max_traffic[1]) print('maxdown.value %d' % max_traffic[1])
print('maxup.value %d' % max_traffic[0]) print('maxup.value %d' % max_traffic[0])
def print_config(): def print_config():
try: try:
conn = FritzStatus(address=hostname, password=os.environ['fritzbox_password']) conn = FritzStatus(address=hostname, password=os.environ['fritzbox_password'])
except Exception as e: except Exception as e:
print(e) print(e)
sys.exit("Couldn't get WAN traffic") sys.exit("Couldn't get WAN traffic")
max_traffic = conn.max_bit_rate max_traffic = conn.max_bit_rate
print("host_name %s" % hostname) print("host_name %s" % hostname)
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 bit up (+) / down (-) per ${graph_period}") print("graph_vlabel bit up (+) / down (-) per ${graph_period}")
print("graph_category network") print("graph_category network")
print("graph_order down up maxdown maxup") print("graph_order down up maxdown maxup")
print("down.label received") print("down.label received")
print("down.type GAUGE") print("down.type GAUGE")
print("down.graph no") print("down.graph no")
#print("down.cdef down,8,*") #print("down.cdef down,8,*")
print("down.min 0") print("down.min 0")
print("down.max %d" % max_traffic[1]) print("down.max %d" % max_traffic[1])
#print("down.warning %.0f" % (max_traffic[1]*0.6)) #print("down.warning %.0f" % (max_traffic[1]*0.6))
#print("down.critical %.0f" % (max_traffic[1]*0.8)) #print("down.critical %.0f" % (max_traffic[1]*0.8))
print("up.label bps") print("up.label bps")
print("up.type GAUGE") print("up.type GAUGE")
print("up.draw AREA") print("up.draw AREA")
#print("up.cdef up,8,*") #print("up.cdef up,8,*")
print("up.min 0") print("up.min 0")
print("up.max %d" % max_traffic[0]) print("up.max %d" % max_traffic[0])
print("up.negative down") print("up.negative down")
#print("up.warning %.0f" % (max_traffic[0]*0.6)) #print("up.warning %.0f" % (max_traffic[0]*0.6))
#print("down.critical %.0f" % (max_traffic[0]*0.8)) #print("down.critical %.0f" % (max_traffic[0]*0.8))
print("up.info Traffic of the WAN interface.") print("up.info Traffic of the WAN interface.")
if not os.environ.get('traffic_remove_max') or "false" in os.environ.get('traffic_remove_max'): if not os.environ.get('traffic_remove_max') or "false" in os.environ.get('traffic_remove_max'):
print("maxdown.label received") print("maxdown.label received")
print("maxdown.type GAUGE") print("maxdown.type GAUGE")
print("maxdown.graph no") print("maxdown.graph no")
print("maxup.label MAX") print("maxup.label MAX")
print("maxup.type GAUGE") print("maxup.type GAUGE")
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'): if os.environ.get('host_name'):
print("host_name " + os.environ['host_name']) print("host_name " + os.environ['host_name'])
if __name__ == "__main__": if __name__ == "__main__":
if len(sys.argv) == 2 and sys.argv[1] == 'config': if len(sys.argv) == 2 and sys.argv[1] == 'config':
print_config() print_config()
elif len(sys.argv) == 2 and sys.argv[1] == 'autoconf': elif len(sys.argv) == 2 and sys.argv[1] == 'autoconf':
print("yes") # Some docs say it'll be called with fetch, some say no arg at all print("yes") # Some docs say it'll be called with fetch, some say no arg at all
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:
sys.exit("Couldn't retrieve fritzbox traffic") sys.exit("Couldn't retrieve fritzbox traffic")

184
fritzbox__traffic_down.py Normal file → Executable file
View File

@ -1,92 +1,92 @@
#!/usr/bin/env python #!/usr/bin/env python
""" """
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
Author: Christian Stade-Schuldt Author: Christian Stade-Schuldt
Updated to fritzconnection library version 1.3.1 Updated to fritzconnection library version 1.3.1
Copyright (C) 2020 Oliver Edelamnn Copyright (C) 2020 Oliver Edelamnn
Author: Oliver Edelmann Author: Oliver Edelmann
Like Munin, this plugin is licensed under the GNU GPL v2 license Like Munin, this plugin is licensed under the GNU GPL v2 license
http://www.opensource.org/licenses/GPL-2.0 http://www.opensource.org/licenses/GPL-2.0
Like Munin, this plugin is licensed under the GNU GPL v2 license Like Munin, this plugin is licensed under the GNU GPL v2 license
http://www.opensource.org/licenses/GPL-2.0 http://www.opensource.org/licenses/GPL-2.0
This plugin requires the fritzconnection plugin. To install it using pip: This plugin requires the fritzconnection plugin. To install it using pip:
pip install fritzconnection pip install fritzconnection
This plugin supports the following munin configuration parameters: This plugin supports the following munin configuration parameters:
#%# family=auto contrib #%# family=auto contrib
#%# capabilities=autoconf #%# capabilities=autoconf
""" """
import os import os
import sys import sys
from fritzconnection.lib.fritzstatus import FritzStatus from fritzconnection.lib.fritzstatus import FritzStatus
hostname = os.path.basename(__file__).split('_')[1] hostname = os.path.basename(__file__).split('_')[1]
def print_values(): def print_values():
try: try:
conn = FritzStatus(address=hostname, password=os.environ['fritzbox_password']) conn = FritzStatus(address=hostname, password=os.environ['fritzbox_password'])
except Exception as e: except Exception as e:
print(e) print(e)
sys.exit("Couldn't get WAN traffic") sys.exit("Couldn't get WAN traffic")
traffic = conn.transmission_rate traffic = conn.transmission_rate
up = traffic[0]*8 up = traffic[0]*8
down = traffic[1]*8 down = traffic[1]*8
print('down.value %d' % down) print('down.value %d' % down)
print('up.value %d' % up) print('up.value %d' % up)
if not os.environ.get('traffic_remove_max') or "false" in os.environ.get('traffic_remove_max'): if not os.environ.get('traffic_remove_max') or "false" in os.environ.get('traffic_remove_max'):
max_traffic = conn.max_bit_rate max_traffic = conn.max_bit_rate
print('maxdown.value %d' % max_traffic[1]) print('maxdown.value %d' % max_traffic[1])
print('maxup.value %d' % max_traffic[0]) print('maxup.value %d' % max_traffic[0])
def print_config(): def print_config():
try: try:
conn = FritzStatus(address=hostname, password=os.environ['fritzbox_password']) conn = FritzStatus(address=hostname, password=os.environ['fritzbox_password'])
except Exception as e: except Exception as e:
print(e) print(e)
sys.exit("Couldn't get WAN traffic") sys.exit("Couldn't get WAN traffic")
max_traffic = conn.max_bit_rate max_traffic = conn.max_bit_rate
print("host_name %s" % hostname) print("host_name %s" % hostname)
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 bit down per ${graph_period}") print("graph_vlabel bit down per ${graph_period}")
print("graph_category network") print("graph_category network")
print("graph_order down maxdown") print("graph_order down maxdown")
print("down.label bps") print("down.label bps")
print("down.type GAUGE") print("down.type GAUGE")
print("down.draw AREA") print("down.draw AREA")
print("down.graph no") print("down.graph no")
print("down.min 0") print("down.min 0")
print("down.max %d" % max_traffic[1]) print("down.max %d" % max_traffic[1])
print("down.warning %.0f" % (max_traffic[1]*0.6)) print("down.warning %.0f" % (max_traffic[1]*0.6))
print("down.critical %.0f" % (max_traffic[1]*0.8)) print("down.critical %.0f" % (max_traffic[1]*0.8))
print("down.info Traffic of the WAN interface.") print("down.info Traffic of the WAN interface.")
if not os.environ.get('traffic_remove_max') or "false" in os.environ.get('traffic_remove_max'): if not os.environ.get('traffic_remove_max') or "false" in os.environ.get('traffic_remove_max'):
print("maxdown.label received") print("maxdown.label received")
print("maxdown.type GAUGE") print("maxdown.type GAUGE")
print("maxdown.graph no") print("maxdown.graph no")
print("maxdown.info Maximum down speed of the WAN interface.") print("maxdown.info Maximum down 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.environ['host_name'])
if __name__ == "__main__": if __name__ == "__main__":
if len(sys.argv) == 2 and sys.argv[1] == 'config': if len(sys.argv) == 2 and sys.argv[1] == 'config':
print_config() print_config()
elif len(sys.argv) == 2 and sys.argv[1] == 'autoconf': elif len(sys.argv) == 2 and sys.argv[1] == 'autoconf':
print("yes") # Some docs say it'll be called with fetch, some say no arg at all print("yes") # Some docs say it'll be called with fetch, some say no arg at all
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:
sys.exit("Couldn't retrieve fritzbox traffic") sys.exit("Couldn't retrieve fritzbox traffic")

182
fritzbox__traffic_up.py Normal file → Executable file
View File

@ -1,91 +1,91 @@
#!/usr/bin/env python #!/usr/bin/env python
""" """
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
Author: Christian Stade-Schuldt Author: Christian Stade-Schuldt
Updated to fritzconnection library version 1.3.1 Updated to fritzconnection library version 1.3.1
Copyright (C) 2020 Oliver Edelamnn Copyright (C) 2020 Oliver Edelamnn
Author: Oliver Edelmann Author: Oliver Edelmann
Like Munin, this plugin is licensed under the GNU GPL v2 license Like Munin, this plugin is licensed under the GNU GPL v2 license
http://www.opensource.org/licenses/GPL-2.0 http://www.opensource.org/licenses/GPL-2.0
Like Munin, this plugin is licensed under the GNU GPL v2 license Like Munin, this plugin is licensed under the GNU GPL v2 license
http://www.opensource.org/licenses/GPL-2.0 http://www.opensource.org/licenses/GPL-2.0
This plugin requires the fritzconnection plugin. To install it using pip: This plugin requires the fritzconnection plugin. To install it using pip:
pip install fritzconnection pip install fritzconnection
This plugin supports the following munin configuration parameters: This plugin supports the following munin configuration parameters:
#%# family=auto contrib #%# family=auto contrib
#%# capabilities=autoconf #%# capabilities=autoconf
""" """
import os import os
import sys import sys
from fritzconnection.lib.fritzstatus import FritzStatus from fritzconnection.lib.fritzstatus import FritzStatus
hostname = os.path.basename(__file__).split('_')[1] hostname = os.path.basename(__file__).split('_')[1]
def print_values(): def print_values():
try: try:
conn = FritzStatus(address=hostname, password=os.environ['fritzbox_password']) conn = FritzStatus(address=hostname, password=os.environ['fritzbox_password'])
except Exception as e: except Exception as e:
print(e) print(e)
sys.exit("Couldn't get WAN traffic") sys.exit("Couldn't get WAN traffic")
traffic = conn.transmission_rate traffic = conn.transmission_rate
up = traffic[0]*8 up = traffic[0]*8
down = traffic[1]*8 down = traffic[1]*8
print('down.value %d' % down) print('down.value %d' % down)
print('up.value %d' % up) print('up.value %d' % up)
if not os.environ.get('traffic_remove_max') or "false" in os.environ.get('traffic_remove_max'): if not os.environ.get('traffic_remove_max') or "false" in os.environ.get('traffic_remove_max'):
max_traffic = conn.max_bit_rate max_traffic = conn.max_bit_rate
print('maxdown.value %d' % max_traffic[1]) print('maxdown.value %d' % max_traffic[1])
print('maxup.value %d' % max_traffic[0]) print('maxup.value %d' % max_traffic[0])
def print_config(): def print_config():
try: try:
conn = FritzStatus(address=hostname, password=os.environ['fritzbox_password']) conn = FritzStatus(address=hostname, password=os.environ['fritzbox_password'])
except Exception as e: except Exception as e:
print(e) print(e)
sys.exit("Couldn't get WAN traffic") sys.exit("Couldn't get WAN traffic")
max_traffic = conn.max_bit_rate max_traffic = conn.max_bit_rate
print("host_name %s" % hostname) print("host_name %s" % hostname)
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 bit up per ${graph_period}") print("graph_vlabel bit up per ${graph_period}")
print("graph_category network") print("graph_category network")
print("graph_order up maxup") print("graph_order up maxup")
print("up.label bps") print("up.label bps")
print("up.type GAUGE") print("up.type GAUGE")
print("up.draw AREA") print("up.draw AREA")
print("up.min 0") print("up.min 0")
print("up.max %d" % max_traffic[1]) print("up.max %d" % max_traffic[1])
print("up.warning %.0f" % (max_traffic[1]*0.6)) print("up.warning %.0f" % (max_traffic[1]*0.6))
print("up.critical %.0f" % (max_traffic[1]*0.8)) print("up.critical %.0f" % (max_traffic[1]*0.8))
print("up.info Traffic of the WAN interface.") print("up.info Traffic of the WAN interface.")
if not os.environ.get('traffic_remove_max') or "false" in os.environ.get('traffic_remove_max'): if not os.environ.get('traffic_remove_max') or "false" in os.environ.get('traffic_remove_max'):
print("maxup.label MAX") print("maxup.label MAX")
print("maxup.type GAUGE") print("maxup.type GAUGE")
print("maxup.draw LINE1") print("maxup.draw LINE1")
print("maxup.info Maximum up speed of the WAN interface.") print("maxup.info Maximum up 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.environ['host_name'])
if __name__ == "__main__": if __name__ == "__main__":
if len(sys.argv) == 2 and sys.argv[1] == 'config': if len(sys.argv) == 2 and sys.argv[1] == 'config':
print_config() print_config()
elif len(sys.argv) == 2 and sys.argv[1] == 'autoconf': elif len(sys.argv) == 2 and sys.argv[1] == 'autoconf':
print("yes") # Some docs say it'll be called with fetch, some say no arg at all print("yes") # Some docs say it'll be called with fetch, some say no arg at all
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:
sys.exit("Couldn't retrieve fritzbox traffic") sys.exit("Couldn't retrieve fritzbox traffic")

170
fritzbox__uptime.py Normal file → Executable file
View File

@ -1,85 +1,85 @@
#!/usr/bin/env python #!/usr/bin/env python
""" """
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
Author: Christian Stade-Schuldt Author: Christian Stade-Schuldt
Like Munin, this plugin is licensed under the GNU GPL v2 license Like Munin, this plugin is licensed under the GNU GPL v2 license
http://www.opensource.org/licenses/GPL-2.0 http://www.opensource.org/licenses/GPL-2.0
Add the following section to your munin-node's plugin configuration: Add the following section to your munin-node's plugin configuration:
[fritzbox_*] [fritzbox_*]
env.fritzbox_ip [ip address of the fritzbox] env.fritzbox_ip [ip address of the fritzbox]
env.fritzbox_password [fritzbox password] env.fritzbox_password [fritzbox password]
This plugin supports the following munin configuration parameters: This plugin supports the following munin configuration parameters:
#%# family=auto contrib #%# family=auto contrib
#%# capabilities=autoconf #%# capabilities=autoconf
""" """
import json import json
import os import os
import re import re
import sys import sys
import fritzbox_helper as fh import fritzbox_helper as fh
locale = os.environ.get('locale', 'de') locale = os.environ.get('locale', 'de')
patternLoc = {"de": r"(\d+)\s(Tag|Stunden|Minuten)", patternLoc = {"de": r"(\d+)\s(Tag|Stunden|Minuten)",
"en": r"(\d+)\s(days|hours|minutes)"} "en": r"(\d+)\s(days|hours|minutes)"}
dayLoc = {"de": "Tag", "en": "days"} dayLoc = {"de": "Tag", "en": "days"}
hourLoc = {"de": "Stunden", "en": "hours"} hourLoc = {"de": "Stunden", "en": "hours"}
minutesLoc = {"de": "Minuten", "en": "minutes"} minutesLoc = {"de": "Minuten", "en": "minutes"}
PAGE = 'energy' PAGE = 'energy'
pattern = re.compile(patternLoc[locale]) pattern = re.compile(patternLoc[locale])
hostname = os.path.basename(__file__).split('_')[1] hostname = os.path.basename(__file__).split('_')[1]
def get_uptime(): def get_uptime():
"""get the current uptime""" """get the current uptime"""
server = hostname server = hostname
password = os.environ['fritzbox_password'] password = os.environ['fritzbox_password']
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)
for d in data['data']['drain']: for d in data['data']['drain']:
if 'aktiv' in d['statuses']: if 'aktiv' in d['statuses']:
matches = re.finditer(pattern, d['statuses']) matches = re.finditer(pattern, d['statuses'])
if matches: if matches:
hours = 0.0 hours = 0.0
for m in matches: for m in matches:
if m.group(2) == dayLoc[locale]: if m.group(2) == dayLoc[locale]:
hours += 24 * int(m.group(1)) hours += 24 * int(m.group(1))
if m.group(2) == hourLoc[locale]: if m.group(2) == hourLoc[locale]:
hours += int(m.group(1)) hours += int(m.group(1))
if m.group(2) == minutesLoc[locale]: if m.group(2) == minutesLoc[locale]:
hours += int(m.group(1)) / 60.0 hours += int(m.group(1)) / 60.0
uptime = hours / 24 uptime = hours / 24
print("uptime.value %.2f" % uptime) print("uptime.value %.2f" % uptime)
def print_config(): def print_config():
print("host_name %s" % hostname) print("host_name %s" % hostname)
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')
print("graph_scale no'") print("graph_scale no'")
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'): if os.environ.get('host_name'):
print("host_name " + os.environ['host_name']) print("host_name " + os.environ['host_name'])
if __name__ == '__main__': if __name__ == '__main__':
if len(sys.argv) == 2 and sys.argv[1] == 'config': if len(sys.argv) == 2 and sys.argv[1] == 'config':
print_config() print_config()
elif len(sys.argv) == 2 and sys.argv[1] == 'autoconf': elif len(sys.argv) == 2 and sys.argv[1] == 'autoconf':
print('yes') print('yes')
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':
# 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:
sys.exit("Couldn't retrieve fritzbox uptime") sys.exit("Couldn't retrieve fritzbox uptime")

138
fritzbox__wifi_devices.py Normal file → Executable file
View File

@ -1,69 +1,69 @@
#!/usr/bin/env python #!/usr/bin/env python
""" """
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
Author: Christian Stade-Schuldt Author: Christian Stade-Schuldt
Updated to fritzconnection library version 1.3.1 Updated to fritzconnection library version 1.3.1
Copyright (C) 2020 Oliver Edelamnn Copyright (C) 2020 Oliver Edelamnn
Author: Oliver Edelmann Author: Oliver Edelmann
Like Munin, this plugin is licensed under the GNU GPL v2 license Like Munin, this plugin is licensed under the GNU GPL v2 license
http://www.opensource.org/licenses/GPL-2.0 http://www.opensource.org/licenses/GPL-2.0
Add the following section to your munin-node's plugin configuration: Add the following section to your munin-node's plugin configuration:
[fritzbox_*] [fritzbox_*]
env.fritzbox_ip [ip address of the fritzbox] env.fritzbox_ip [ip address of the fritzbox]
env.fritzbox_password [fritzbox password] env.fritzbox_password [fritzbox password]
This plugin supports the following munin configuration parameters: This plugin supports the following munin configuration parameters:
#%# family=auto contrib #%# family=auto contrib
#%# capabilities=autoconf #%# capabilities=autoconf
""" """
import os import os
import sys import sys
from fritzconnection.lib.fritzwlan import FritzWLAN from fritzconnection.lib.fritzwlan import FritzWLAN
hostname = os.path.basename(__file__).split('_')[1] hostname = os.path.basename(__file__).split('_')[1]
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"""
try: try:
conn = FritzWLAN(address=hostname, password=os.environ['fritzbox_password']) conn = FritzWLAN(address=hostname, password=os.environ['fritzbox_password'])
except Exception as e: except Exception as e:
print(e) print(e)
sys.exit("Couldn't get connection uptime") sys.exit("Couldn't get connection uptime")
connected_devices = conn.host_number connected_devices = conn.host_number
print('wifi.value %d' % connected_devices) print('wifi.value %d' % connected_devices)
def print_config(): def print_config():
print("host_name %s" % hostname) print("host_name %s" % hostname)
print('graph_title AVM Fritz!Box Connected Wifi Devices') print('graph_title AVM Fritz!Box Connected Wifi 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')
print('graph_order wifi') print('graph_order wifi')
print('wifi.label Wifi Connections on 2.4 & 5 Ghz') print('wifi.label Wifi Connections on 2.4 & 5 Ghz')
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'): if os.environ.get('host_name'):
print("host_name " + os.environ['host_name']) print("host_name " + os.environ['host_name'])
if __name__ == '__main__': if __name__ == '__main__':
if len(sys.argv) == 2 and sys.argv[1] == 'config': if len(sys.argv) == 2 and sys.argv[1] == 'config':
print_config() print_config()
elif len(sys.argv) == 2 and sys.argv[1] == 'autoconf': elif len(sys.argv) == 2 and sys.argv[1] == 'autoconf':
print('yes') print('yes')
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':
# 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:
sys.exit("Couldn't retrieve connected fritzbox wifi devices") sys.exit("Couldn't retrieve connected fritzbox wifi devices")

0
fritzbox_helper.py Normal file → Executable file
View File