mirror of
https://github.com/munin-monitoring/contrib.git
synced 2025-08-03 14:48:22 +00:00
141 lines
3.4 KiB
Python
Executable file
141 lines
3.4 KiB
Python
Executable file
#!/usr/bin/env python3
|
|
|
|
# Copyright 2020 Nathaniel Clark <nathaniel.clark@misrule.us>
|
|
#
|
|
# This program is free software; you can redistribute it and/or modify
|
|
# it under the terms of the GNU Library General Public License as published by
|
|
# the Free Software Foundation; version 2 only
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU Library General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU Library General Public License
|
|
# along with this program; if not, write to the Free Software
|
|
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
#
|
|
|
|
"""
|
|
=head1 NAME
|
|
|
|
arris-sb6183_uptime - Uptime monitoring for Arris SB6183 Cable Modem
|
|
|
|
=head1 CONFIGURATION
|
|
|
|
Make sure 192.168.100.1 is accessible through your firewall.
|
|
|
|
To have this register with munin as it's own host set the "env.hostname" in config.
|
|
Also ensure that the hostname set is listed in munin.conf.
|
|
|
|
[arris*]
|
|
env.hostname modem
|
|
|
|
=head1 TESTING
|
|
|
|
Developed and tested with:
|
|
firmware: D30CM-OSPREY-2.4.0.1-GA-02-NOSH
|
|
hardware version: 1
|
|
|
|
=head1 VERSION
|
|
|
|
0.0.1
|
|
|
|
=head1 AUTHOR
|
|
|
|
Nathaniel Clark <nathaniel.clark@misrule.us>
|
|
|
|
=head1 LICENSE
|
|
|
|
GPLv2
|
|
|
|
=head1 MAGIC MARKERS
|
|
|
|
#%# family=contrib
|
|
#%# capabilities=autoconf
|
|
|
|
=cut
|
|
"""
|
|
import re
|
|
import os
|
|
import sys
|
|
from urllib import request
|
|
|
|
|
|
HOSTNAME = os.getenv("hostname", None)
|
|
URL = "http://192.168.100.1/RgSwInfo.asp"
|
|
|
|
if len(sys.argv) == 2:
|
|
if sys.argv[1] == "config":
|
|
if HOSTNAME:
|
|
print("host_name {0}".format(HOSTNAME))
|
|
|
|
# POWER
|
|
print(
|
|
"""graph_title Modem Uptime
|
|
graph_category system
|
|
graph_args --base 1000 -l 0
|
|
graph_vlabel uptime in days
|
|
graph_scale no
|
|
graph_category system
|
|
graph_info This graph shows the number of days that the the host is up and running so far.
|
|
uptime.label uptime
|
|
uptime.info The system uptime itself in days.
|
|
uptime.draw AREA
|
|
"""
|
|
)
|
|
sys.exit(0)
|
|
|
|
if sys.argv[1] == "autoconfig":
|
|
try:
|
|
from lxml import html
|
|
|
|
resp = request.urlopen(URL)
|
|
except ImportError:
|
|
print("no (missing lxml module)")
|
|
except OSError:
|
|
print("no (no router)")
|
|
else:
|
|
if page.status_code == 200:
|
|
print("yes")
|
|
else:
|
|
print("no (Bad status code: %d)" % page.status_code)
|
|
sys.exit(0)
|
|
|
|
from lxml import html
|
|
|
|
rxblank = re.compile(r"[\x00\n\r\t ]+", re.MULTILINE)
|
|
rxcomment = re.compile(r"<!--.*?-->")
|
|
rxscript = re.compile(r"<script.*?</script>", re.MULTILINE)
|
|
|
|
resp = request.urlopen(URL)
|
|
if resp.status != 200:
|
|
print(
|
|
"failed to get status page %d: %s" % (resp.status, resp.reason), file=sys.stderr
|
|
)
|
|
print("uptime.value U")
|
|
sys.exit(0)
|
|
|
|
data = rxscript.sub(
|
|
"",
|
|
rxcomment.sub(
|
|
"",
|
|
rxblank.sub(" ", "".join(map(lambda x: x.decode("utf-8"), resp.readlines()))),
|
|
),
|
|
)
|
|
dom = html.fromstring(data)
|
|
|
|
arr = dom.xpath('//table[contains(@class, "simpleTable")]')
|
|
trs = arr[1].findall("tr")
|
|
# drop title
|
|
trs.pop(0)
|
|
|
|
date = "".join(trs[0].findall("td")[1].itertext()).strip()
|
|
|
|
arr = date.split(" ")
|
|
rx = re.compile(r"[hms]")
|
|
days = int(arr[0])
|
|
hms = rx.sub("", arr[2]).split(":")
|
|
|
|
seconds = ((days * 24 + int(hms[0])) * 60 + int(hms[1])) * 60 + int(hms[2])
|
|
print("uptime.value {0}".format(seconds / 86400.0))
|