Merge remote-tracking branch 'gh-mistersmie/feature/userauth' into shtrom-s-master

This commit is contained in:
Olivier Mehani 2019-09-22 17:05:20 +10:00
commit a20ac8808b
7 changed files with 43 additions and 9 deletions

View File

@ -10,6 +10,7 @@
[fritzbox_*]
env.fritzbox_ip [ip address of the fritzbox]
env.fritzbox_password [fritzbox password]
env.fritzbox_username [optional: fritzbox username]
This plugin supports the following munin configuration parameters:
#%# family=auto contrib
@ -29,7 +30,11 @@ def get_cpu_temperature():
server = os.environ['fritzbox_ip']
password = os.environ['fritzbox_password']
session_id = fh.get_session_id(server, password)
if "fritzbox_username" in os.environ:
fritzuser = os.environ['fritzbox_username']
session_id = fh.get_session_id(server, password, fritzuser)
else:
session_id = fh.get_session_id(server, password)
xhr_data = fh.get_xhr_content(server, session_id, PAGE)
data = json.loads(xhr_data)
print('temp.value %d' % (int(data['data']['cputemp']['series'][0][-1])))

View File

@ -10,6 +10,7 @@
[fritzbox_*]
env.fritzbox_ip [ip address of the fritzbox]
env.fritzbox_password [fritzbox password]
env.fritzbox_username [optional: fritzbox username]
This plugin supports the following munin configuration parameters:
#%# family=auto contrib
@ -29,7 +30,11 @@ def get_cpu_usage():
server = os.environ['fritzbox_ip']
password = os.environ['fritzbox_password']
session_id = fh.get_session_id(server, password)
if "fritzbox_username" in os.environ:
fritzuser = os.environ['fritzbox_username']
session_id = fh.get_session_id(server, password, fritzuser)
else:
session_id = fh.get_session_id(server, password)
xhr_data = fh.get_xhr_content(server, session_id, PAGE)
data = json.loads(xhr_data)
print('cpu.value %d' % (int(data['data']['cpuutil']['series'][0][-1])))

View File

@ -10,6 +10,7 @@
[fritzbox_*]
env.fritzbox_ip [ip address of the fritzbox]
env.fritzbox_password [fritzbox password]
env.fritzbox_username [optional: fritzbox username]
This plugin supports the following munin configuration parameters:
#%# family=auto contrib
@ -29,22 +30,25 @@ from lxml import etree
USER_AGENT = "Mozilla/5.0 (Macintosh; Intel Mac OS X x.y; rv:10.0) Gecko/20100101 Firefox/10.0"
def get_session_id(server, password, port=80):
def get_session_id(server, password, username=None, port=80):
"""Obtains the session id after login into the Fritzbox.
See https://avm.de/fileadmin/user_upload/Global/Service/Schnittstellen/AVM_Technical_Note_-_Session_ID.pdf
for deteils (in German).
:param server: the ip address of the Fritzbox
:param password: the password to log into the Fritzbox webinterface
:param username: (optional) the username with which to log into the Fritzbox webinterface
:param port: the port the Fritzbox webserver runs on
:return: the session id
"""
userpar = '' if username is None else '?username={}'.format(username)
headers = {"Accept": "application/xml",
"Content-Type": "text/plain",
"User-Agent": USER_AGENT}
url = 'http://{}:{}/login_sid.lua'.format(server, port)
url = 'http://{}:{}/login_sid.lua{}'.format(server, port, userpar)
try:
r = requests.get(url, headers=headers)
r.raise_for_status()
@ -67,7 +71,7 @@ def get_session_id(server, password, port=80):
"Content-Type": "application/x-www-form-urlencoded",
"User-Agent": USER_AGENT}
url = 'http://{}:{}/login_sid.lua?&response={}'.format(server, port, response_bf)
url = 'http://{}:{}/login_sid.lua?{}&response={}'.format(server, port, userpar[1:], response_bf)
try:
r = requests.get(url, headers=headers)
r.raise_for_status()

View File

@ -10,6 +10,7 @@
[fritzbox_*]
env.fritzbox_ip [ip address of the fritzbox]
env.fritzbox_password [fritzbox password]
env.fritzbox_username [optional: fritzbox username]
This plugin supports the following munin configuration parameters:
#%# family=auto contrib
@ -30,7 +31,11 @@ def get_memory_usage():
server = os.environ['fritzbox_ip']
password = os.environ['fritzbox_password']
session_id = fh.get_session_id(server, password)
if "fritzbox_username" in os.environ:
fritzuser = os.environ['fritzbox_username']
session_id = fh.get_session_id(server, password, fritzuser)
else:
session_id = fh.get_session_id(server, password)
xhr_data = fh.get_xhr_content(server, session_id, PAGE)
data = json.loads(xhr_data)
for i, usage in enumerate(USAGE):

View File

@ -11,6 +11,7 @@
[fritzbox_*]
env.fritzbox_ip [ip address of the fritzbox]
env.fritzbox_password [fritzbox password]
env.fritzbox_username [optional: fritzbox username]
This plugin supports the following munin configuration parameters:
#%# family=auto contrib
@ -32,7 +33,11 @@ def get_power_consumption():
server = os.environ['fritzbox_ip']
password = os.environ['fritzbox_password']
session_id = fh.get_session_id(server, password)
if "fritzbox_username" in os.environ:
fritzuser = os.environ['fritzbox_username']
session_id = fh.get_session_id(server, password, fritzuser)
else:
session_id = fh.get_session_id(server, password)
xhr_data = fh.get_xhr_content(server, session_id, PAGE)
data = json.loads(xhr_data)
devices = data['data']['drain']

View File

@ -10,6 +10,7 @@
[fritzbox_*]
env.fritzbox_ip [ip address of the fritzbox]
env.fritzbox_password [fritzbox password]
env.fritzbox_username [optional: fritzbox username]
This plugin supports the following munin configuration parameters:
#%# family=auto contrib
@ -39,7 +40,11 @@ def get_uptime():
server = os.environ['fritzbox_ip']
password = os.environ['fritzbox_password']
session_id = fh.get_session_id(server, password)
if "fritzbox_username" in os.environ:
fritzuser = os.environ['fritzbox_username']
session_id = fh.get_session_id(server, password, fritzuser)
else:
session_id = fh.get_session_id(server, password)
xhr_data = fh.get_xhr_content(server, session_id, PAGE)
data = json.loads(xhr_data)
for d in data['data']['drain']:

View File

@ -10,6 +10,7 @@
[fritzbox_*]
env.fritzbox_ip [ip address of the fritzbox]
env.fritzbox_password [fritzbox password]
env.fritzbox_username [optional: fritzbox username]
This plugin supports the following munin configuration parameters:
#%# family=auto contrib
@ -36,7 +37,11 @@ def get_connected_wifi_devices():
server = os.environ['fritzbox_ip']
password = os.environ['fritzbox_password']
session_id = fh.get_session_id(server, password)
if "fritzbox_username" in os.environ:
fritzuser = os.environ['fritzbox_username']
session_id = fh.get_session_id(server, password, fritzuser)
else:
session_id = fh.get_session_id(server, password)
xhr_data = fh.get_xhr_content(server, session_id, PAGE)
data = json.loads(xhr_data)
m = re.search(pattern, data['data']['drain'][2]['statuses'][-1])