mirror of
https://github.com/Tafkas/fritzbox-munin.git
synced 2023-10-10 13:36:55 +02:00
add optional fritzbox_username environment variable to do username/password authentication
this implementation should also work seamlessly with "master-password" style authentication.
This commit is contained in:
parent
ef6f81b426
commit
b193e29fe5
@ -10,6 +10,7 @@
|
|||||||
[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]
|
||||||
|
env.fritzbox_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,7 +32,11 @@ def get_cpu_temperature():
|
|||||||
server = os.environ['fritzbox_ip']
|
server = os.environ['fritzbox_ip']
|
||||||
password = os.environ['fritzbox_password']
|
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)
|
||||||
data = fh.get_page_content(server, session_id, PAGE)
|
data = fh.get_page_content(server, session_id, PAGE)
|
||||||
|
|
||||||
m = re.search(pattern, data)
|
m = re.search(pattern, data)
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
[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]
|
||||||
|
env.fritzbox_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,7 +32,11 @@ def get_cpu_usage():
|
|||||||
server = os.environ['fritzbox_ip']
|
server = os.environ['fritzbox_ip']
|
||||||
password = os.environ['fritzbox_password']
|
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)
|
||||||
data = fh.get_page_content(server, session_id, PAGE)
|
data = fh.get_page_content(server, session_id, PAGE)
|
||||||
|
|
||||||
m = re.search(pattern, data)
|
m = re.search(pattern, data)
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
[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]
|
||||||
|
env.fritzbox_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()
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
[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]
|
||||||
|
env.fritzbox_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
|
||||||
@ -32,7 +33,11 @@ def get_memory_usage():
|
|||||||
server = os.environ['fritzbox_ip']
|
server = os.environ['fritzbox_ip']
|
||||||
password = os.environ['fritzbox_password']
|
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)
|
||||||
data = fh.get_page_content(server, session_id, PAGE)
|
data = fh.get_page_content(server, session_id, PAGE)
|
||||||
matches = re.finditer(pattern, data)
|
matches = re.finditer(pattern, data)
|
||||||
if matches:
|
if matches:
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
[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]
|
||||||
|
env.fritzbox_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
|
||||||
@ -32,7 +33,11 @@ def get_power_consumption():
|
|||||||
server = os.environ['fritzbox_ip']
|
server = os.environ['fritzbox_ip']
|
||||||
password = os.environ['fritzbox_password']
|
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)
|
||||||
data = fh.get_page_content(server, session_id, PAGE)
|
data = fh.get_page_content(server, session_id, PAGE)
|
||||||
matches = re.finditer(pattern, data)
|
matches = re.finditer(pattern, data)
|
||||||
if matches:
|
if matches:
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
[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]
|
||||||
|
env.fritzbox_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
|
||||||
@ -39,7 +40,11 @@ def get_uptime():
|
|||||||
server = os.environ['fritzbox_ip']
|
server = os.environ['fritzbox_ip']
|
||||||
password = os.environ['fritzbox_password']
|
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)
|
||||||
data = fh.get_page_content(server, session_id, PAGE)
|
data = fh.get_page_content(server, session_id, PAGE)
|
||||||
matches = re.finditer(pattern, data)
|
matches = re.finditer(pattern, data)
|
||||||
if matches:
|
if matches:
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
[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]
|
||||||
|
env.fritzbox_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
|
||||||
@ -35,7 +36,11 @@ def get_connected_wifi_devices():
|
|||||||
server = os.environ['fritzbox_ip']
|
server = os.environ['fritzbox_ip']
|
||||||
password = os.environ['fritzbox_password']
|
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)
|
||||||
data = fh.get_page_content(server, session_id, PAGE)
|
data = fh.get_page_content(server, session_id, PAGE)
|
||||||
m = re.search(pattern, data)
|
m = re.search(pattern, data)
|
||||||
if m:
|
if m:
|
||||||
|
Loading…
Reference in New Issue
Block a user