Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support for multiple boxes and username authentication #10

Open
wants to merge 7 commits into
base: fritzos6.5
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ If you are using FRITZ!OS 6.30 use the master branch.

[fritzbox_*]
env.fritzbox_ip <ip_address_to_your_fritzbox>
env.fritzbox_username <fritzbox_username>
env.fritzbox_password <fritzbox_password>

3. Create symbolic links to /etc/munin/plugins.
Expand All @@ -75,3 +76,19 @@ If you are using FRITZ!OS 6.30 use the master branch.

Do not forget to restart the munin-node daemon as described in step
3 of the installation instructions above.

## Multiple Fritz!Boxes

To generate graphs for additional boxes create new symbolic links (like in step 3) but chgange the first part of th
e.g.: ```ln -s /usr/share/munin/plugins/fritzbox_uptime.py /etc/munin/plugins/freetz_uptime```

And create a new section in ```/etc/munin/plugin-cond.d/munin-node``` with the alternative name.

```
[freetz_*]
env.fritzbox_ip <ip_address_to_your_second_fritzbox>
env.fritzbox_username <fritzbox_username>
env.fritzbox_password <fritzbox_password>
```

Restart the munin-node daemon.
4 changes: 4 additions & 0 deletions fritzbox_connection_uptime.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@

from fritzconnection import FritzConnection

# bet box name from first part before '_' in (symlink) file name
boxname = os.path.basename(__file__).rsplit('_')[0]


def print_values():
try:
Expand All @@ -31,6 +34,7 @@ def print_values():


def print_config():
print "host_name %s" % boxname
print "graph_title AVM Fritz!Box Connection Uptime"
print "graph_args --base 1000 -l 0"
print 'graph_vlabel uptime in days'
Expand Down
8 changes: 7 additions & 1 deletion fritzbox_cpu_temperature.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

[fritzbox_*]
env.fritzbox_ip [ip address of the fritzbox]
env.fritzbox_username [fritzbox username]
env.fritzbox_password [fritzbox password]

This plugin supports the following munin configuration parameters:
Expand All @@ -24,14 +25,18 @@
PAGE = '/system/ecostat.lua'
pattern = re.compile('Query\s=\s"(\d{1,3})')

# bet box name from first part before '_' in (symlink) file name
boxname = os.path.basename(__file__).rsplit('_')[0]


def get_cpu_temperature():
"""get the current cpu temperature"""

server = os.environ['fritzbox_ip']
username = os.getenv('fritzbox_username', "None")
password = os.environ['fritzbox_password']

sid = fh.get_sid(server, password)
sid = fh.get_sid(server, username, password)
data = fh.get_page(server, sid, PAGE)

m = re.search(pattern, data)
Expand All @@ -40,6 +45,7 @@ def get_cpu_temperature():


def print_config():
print "host_name %s" % boxname
print "graph_title AVM Fritz!Box CPU temperature"
print "graph_vlabel degrees Celsius"
print "graph_category sensors"
Expand Down
8 changes: 7 additions & 1 deletion fritzbox_cpu_usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

[fritzbox_*]
env.fritzbox_ip [ip address of the fritzbox]
env.fritzbox_username[fritzbox username]
env.fritzbox_password [fritzbox password]

This plugin supports the following munin configuration parameters:
Expand All @@ -24,14 +25,18 @@
PAGE = '/system/ecostat.lua'
pattern = re.compile('Query1\s=\s"(\d{1,3})')

# bet box name from first part before '_' in (symlink) file name
boxname = os.path.basename(__file__).rsplit('_')[0]


def get_cpu_usage():
"""get the current cpu usage"""

server = os.environ['fritzbox_ip']
username = os.getenv('fritzbox_username', "None")
password = os.environ['fritzbox_password']

sid = fh.get_sid(server, password)
sid = fh.get_sid(server, username, password)
data = fh.get_page(server, sid, PAGE)

m = re.search(pattern, data)
Expand All @@ -40,6 +45,7 @@ def get_cpu_usage():


def print_config():
print "host_name %s" % boxname
print "graph_title AVM Fritz!Box CPU usage"
print "graph_vlabel %"
print "graph_category system"
Expand Down
8 changes: 6 additions & 2 deletions fritzbox_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
USER_AGENT = "Mozilla/5.0 (U; Windows NT 5.1; rv:5.0) Gecko/20100101 Firefox/5.0"


def get_sid(server, password, port=80):
def get_sid(server, username, password, port=80):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Set default username to None:
def get_sid(server, username=None, password, port=80):

"""Obtains the sid after login into the fritzbox"""
conn = httplib.HTTPConnection(server + ':' + str(port))

Expand Down Expand Up @@ -58,7 +58,10 @@ def get_sid(server, password, port=80):
"Content-Type": "application/x-www-form-urlencoded",
"User-Agent": USER_AGENT}

login_page = "/login_sid.lua?&response=" + response_bf
if username == '' or username == 'None':
login_page = "/login_sid.lua?&response=" + response_bf
else:
login_page = "/login_sid.lua?username=" + username + "&response=" + response_bf
conn.request("GET", login_page, '', headers)
response = conn.getresponse()
data = response.read()
Expand All @@ -69,6 +72,7 @@ def get_sid(server, password, port=80):
sid = re.search("<SID>(.*?)</SID>", data).group(1)
if sid == "0000000000000000":
print "ERROR - No SID received because of invalid password"

sys.exit(0)
return sid

Expand Down
8 changes: 7 additions & 1 deletion fritzbox_memory_usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

[fritzbox_*]
env.fritzbox_ip [ip address of the fritzbox]
env.fritzbox_username [fritzbox username]
env.fritzbox_password [fritzbox password]

This plugin supports the following munin configuration parameters:
Expand All @@ -25,14 +26,18 @@
pattern = re.compile('Query[1-3]\s="(\d{1,3})')
USAGE = ['free', 'cache', 'strict']

# bet box name from first part before '_' in (symlink) file name
boxname = os.path.basename(__file__).rsplit('_')[0]


def get_memory_usage():
"""get the current memory usage"""

server = os.environ['fritzbox_ip']
username = os.getenv('fritzbox_username', "None")
password = os.environ['fritzbox_password']

sid = fh.get_sid(server, password)
sid = fh.get_sid(server, username, password)
data = fh.get_page(server, sid, PAGE)
matches = re.finditer(pattern, data)
if matches:
Expand All @@ -42,6 +47,7 @@ def get_memory_usage():


def print_config():
print "host_name %s" % boxname
print "graph_title AVM Fritz!Box Memory"
print "graph_vlabel %"
print "graph_args --base 1000 -r --lower-limit 0 --upper-limit 100"
Expand Down
8 changes: 7 additions & 1 deletion fritzbox_power_consumption.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

[fritzbox_*]
env.fritzbox_ip [ip address of the fritzbox]
env.fritzbox_username [fritzbox username]
env.fritzbox_password [fritzbox password]

This plugin supports the following munin configuration parameters:
Expand All @@ -25,14 +26,18 @@
pattern = re.compile('<td>(.+?)"bar\s(act|fillonly)"(.+?)\s(\d{1,3})\s%')
DEVICES = ['system', 'cpu', 'wifi', 'dsl', 'ab', 'usb']

# bet box name from first part before '_' in (symlink) file name
boxname = os.path.basename(__file__).rsplit('_')[0]


def get_power_consumption():
"""get the current power consumption usage"""

server = os.environ['fritzbox_ip']
username = os.getenv('fritzbox_username', "None")
password = os.environ['fritzbox_password']

sid = fh.get_sid(server, password)
sid = fh.get_sid(server, username, password)
data = fh.get_page(server, sid, PAGE)
matches = re.finditer(pattern, data)
if matches:
Expand All @@ -42,6 +47,7 @@ def get_power_consumption():


def print_config():
print "host_name %s" % boxname
print "graph_title AVM Fritz!Box Power Consumption"
print "graph_vlabel %"
print "graph_category network"
Expand Down
4 changes: 4 additions & 0 deletions fritzbox_traffic.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@

from fritzconnection import FritzConnection

# bet box name from first part before '_' in (symlink) file name
boxname = os.path.basename(__file__).rsplit('_')[0]


def print_values():
try:
Expand All @@ -42,6 +45,7 @@ def print_values():


def print_config():
print "host_name %s" % boxname
print "graph_title AVM Fritz!Box WAN traffic"
print "graph_args --base 1000"
print "graph_vlabel bits in (-) / out (+) per \${graph_period}"
Expand Down
8 changes: 7 additions & 1 deletion fritzbox_uptime.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

[fritzbox_*]
env.fritzbox_ip [ip address of the fritzbox]
env.fritzbox_username [fritzbox username]
env.fritzbox_password [fritzbox password]

This plugin supports the following munin configuration parameters:
Expand All @@ -24,14 +25,18 @@
PAGE = '/system/energy.lua'
pattern = re.compile("(\d+)\s(Tag|Stunden|Minuten)")

# bet box name from first part before '_' in (symlink) file name
boxname = os.path.basename(__file__).rsplit('_')[0]


def get_uptime():
"""get the current uptime"""

server = os.environ['fritzbox_ip']
username = os.getenv('fritzbox_username', "None")
password = os.environ['fritzbox_password']

sid = fh.get_sid(server, password)
sid = fh.get_sid(server, username, password)
data = fh.get_page(server, sid, PAGE)
matches = re.finditer(pattern, data)
if matches:
Expand All @@ -48,6 +53,7 @@ def get_uptime():


def print_config():
print "host_name %s" % boxname
print "graph_title AVM Fritz!Box Uptime"
print "graph_args --base 1000 -l 0"
print 'graph_vlabel uptime in days'
Expand Down
8 changes: 7 additions & 1 deletion fritzbox_wifi_devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

[fritzbox_*]
env.fritzbox_ip [ip address of the fritzbox]
env.fritzbox_username [fritzbox username]
env.fritzbox_password [fritzbox password]

This plugin supports the following munin configuration parameters:
Expand All @@ -24,14 +25,18 @@
PAGE = '/system/energy.lua'
pattern = re.compile("(\d+) WLAN")

# bet box name from first part before '_' in (symlink) file name
boxname = os.path.basename(__file__).rsplit('_')[0]


def get_connected_wifi_devices():
"""gets the numbrer of currently connected wifi devices"""

server = os.environ['fritzbox_ip']
username = os.getenv('fritzbox_username', "None")
password = os.environ['fritzbox_password']

sid = fh.get_sid(server, password)
sid = fh.get_sid(server, username, password)
data = fh.get_page(server, sid, PAGE)
m = re.search(pattern, data)
if m:
Expand All @@ -40,6 +45,7 @@ def get_connected_wifi_devices():


def print_config():
print "host_name %s" % boxname
print 'graph_title AVM Fritz!Box Connected Wifi Devices'
print 'graph_vlabel Number of devices'
print 'graph_args --base 1000'
Expand Down