Switch to fritzconnection 1.3.1

This commit is contained in:
root 2020-07-05 22:31:19 +02:00
parent 2dd4e07013
commit 77168af184
3 changed files with 41 additions and 40 deletions

View File

@ -3,6 +3,11 @@
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
Copyright (C) 2020 Oliver Edelamnn
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
@ -17,23 +22,23 @@
import os import os
import sys import sys
from fritzconnection import FritzConnection from fritzconnection.lib.fritzstatus import FritzStatus
def print_values(): def print_values():
try: try:
conn = FritzConnection(address=os.environ['fritzbox_ip']) conn = FritzStatus(address=os.environ['fritzbox_ip'], password=os.environ['fritzbox_password'])
except Exception as e: except Exception as e:
sys.exit("Couldn't get connection uptime") sys.exit("Couldn't get connection uptime")
uptime = conn.call_action('WANIPConnection', 'GetStatusInfo')['NewUptime'] uptime = conn.uptime
print('uptime.value %.2f' % (int(uptime) / 86400.0)) print('uptime.value %.2f' % (int(uptime) / 3600.0))
def print_config(): def print_config():
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 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")

View File

@ -3,6 +3,11 @@
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
Copyright (C) 2020 Oliver Edelamnn
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
@ -17,35 +22,32 @@
import os import os
import sys import sys
from fritzconnection import FritzConnection from fritzconnection.lib.fritzstatus import FritzStatus
def print_values(): def print_values():
try: try:
conn = FritzConnection(address=os.environ['fritzbox_ip']) conn = FritzStatus(address=os.environ['fritzbox_ip'], password=os.environ['fritzbox_password'])
except Exception as e: except Exception as e:
sys.exit("Couldn't get WAN traffic") sys.exit("Couldn't get WAN traffic")
down_traffic = conn.call_action('WANCommonInterfaceConfig', 'GetTotalBytesReceived')['NewTotalBytesReceived'] traffic = conn.transmission_rate
print('down.value %d' % down_traffic) up = traffic[0]
down = traffic[1]
print('down.value %d' % down)
up_traffic = conn.call_action('WANCommonInterfaceConfig', 'GetTotalBytesSent')['NewTotalBytesSent'] print('up.value %d' % up)
print('up.value %d' % up_traffic)
if not os.environ.get('traffic_remove_max'): if not os.environ.get('traffic_remove_max') or "false" in os.environ.get('traffic_remove_max'):
max_down_traffic = conn.call_action('WANCommonInterfaceConfig', 'GetCommonLinkProperties')[ max_traffic = conn.max_bit_rate
'NewLayer1DownstreamMaxBitRate'] print('maxdown.value %d' % max_traffic[1])
print('maxdown.value %d' % max_down_traffic)
max_up_traffic = conn.call_action('WANCommonInterfaceConfig', 'GetCommonLinkProperties')[ print('maxup.value %d' % max_traffic[0])
'NewLayer1UpstreamMaxBitRate']
print('maxup.value %d' % max_up_traffic)
def print_config(): def print_config():
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 bit in (-) / out (+) 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")
@ -62,7 +64,7 @@ def print_config():
print("up.max 1000000000") print("up.max 1000000000")
print("up.negative down") print("up.negative down")
print("up.info Traffic of the WAN interface.") print("up.info Traffic of the WAN interface.")
if not 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")

View File

@ -3,6 +3,11 @@
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
Copyright (C) 2020 Oliver Edelamnn
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:
@ -15,34 +20,23 @@
#%# family=auto contrib #%# family=auto contrib
#%# capabilities=autoconf #%# capabilities=autoconf
""" """
import json
import os import os
import re
import sys import sys
import fritzbox_helper as fh from fritzconnection.lib.fritzwlan import FritzWLAN
locale = os.environ.get('locale', 'de')
patternLoc = {"de": r"(\d+) WLAN",
"en": r"(\d+) wireless LAN"}
PAGE = 'energy'
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'] try:
password = os.environ['fritzbox_password'] conn = FritzWLAN(address=os.environ['fritzbox_ip'], password=os.environ['fritzbox_password'])
except Exception as e:
sys.exit("Couldn't get connection uptime")
session_id = fh.get_session_id(server, password)
xhr_data = fh.get_xhr_content(server, session_id, PAGE) connected_devices = conn.host_number
data = json.loads(xhr_data) print('wifi.value %d' % connected_devices)
m = re.search(pattern, data['data']['drain'][2]['statuses'][-1])
if m:
connected_devices = int(m.group(1))
print('wifi.value %d' % connected_devices)
def print_config(): def print_config():