root / plugins / router / arris-sb6183_uptime @ 1671e356
Historique | Voir | Annoter | Télécharger (2,64 ko)
| 1 |
#!/usr/bin/python |
|---|---|
| 2 |
|
| 3 |
# modem: |
| 4 |
# |
| 5 |
# * uptime |
| 6 |
# |
| 7 |
# The values are retrieved from the cable modem's status web pages at |
| 8 |
# 192.168.100.1. So, this plugin must be installed on a munin node |
| 9 |
# which can access those pages. |
| 10 |
# |
| 11 |
# To install, place this plugin in the node's plugins directory, |
| 12 |
# /etc/munin/plugins and restart munin-node. |
| 13 |
# |
| 14 |
# Developed and tested with: |
| 15 |
# firmware: D30CM-OSPREY-2.4.0.1-GA-02-NOSH |
| 16 |
# hardware version: 1 |
| 17 |
# |
| 18 |
# Copyright 2020 Nathaniel Clark <nathaniel.clark@misrule.us> |
| 19 |
|
| 20 |
""" |
| 21 |
=head1 NAME |
| 22 |
|
| 23 |
arris-sb6183_uptime - Uptime monitoring for Arris SB6183 Cable Modem |
| 24 |
|
| 25 |
=head1 CONFIGURATION |
| 26 |
|
| 27 |
Make sure 192.168.100.1 is accessable through your firewall. |
| 28 |
|
| 29 |
To have this register with munin as it's own host set the "env.hostname" in config. |
| 30 |
Also ensure that the hostname set is listed in munin.conf. |
| 31 |
|
| 32 |
[arris*] |
| 33 |
env.hostname modem |
| 34 |
|
| 35 |
=head1 VERSION |
| 36 |
|
| 37 |
0.0.1 |
| 38 |
|
| 39 |
=head1 AUTHOR |
| 40 |
|
| 41 |
Nathaniel Clark <nathaniel.clark@misrule.us> |
| 42 |
|
| 43 |
=head1 LICENSE |
| 44 |
|
| 45 |
GPLv2 |
| 46 |
|
| 47 |
=head1 MAGIC MARKERS |
| 48 |
|
| 49 |
#%# family=contrib |
| 50 |
#%# capabilities=autoconf |
| 51 |
|
| 52 |
=cut |
| 53 |
""" |
| 54 |
import re |
| 55 |
import os |
| 56 |
import sys |
| 57 |
import requests |
| 58 |
from lxml import html |
| 59 |
|
| 60 |
|
| 61 |
URL = os.getenv("url", "http://192.168.100.1/RgSwInfo.asp")
|
| 62 |
HOSTNAME = os.getenv("hostname", None)
|
| 63 |
|
| 64 |
if len(sys.argv) == 2: |
| 65 |
if sys.argv[1] == "config": |
| 66 |
print("host_name {0}".format(HOSTNAME))
|
| 67 |
|
| 68 |
# POWER |
| 69 |
print( |
| 70 |
"""graph_title Modem Uptime |
| 71 |
graph_category system |
| 72 |
graph_args --base 1000 -l 0 |
| 73 |
graph_vlabel uptime in days |
| 74 |
graph_scale no |
| 75 |
graph_category system |
| 76 |
graph_info This graph shows the number of days that the the host is up and running so far. |
| 77 |
uptime.label uptime |
| 78 |
uptime.info The system uptime itself in days. |
| 79 |
uptime.draw AREA |
| 80 |
""" |
| 81 |
) |
| 82 |
sys.exit(0) |
| 83 |
|
| 84 |
if sys.argv[1] == "autoconfig": |
| 85 |
try: |
| 86 |
page = requests.get(URL) |
| 87 |
except: |
| 88 |
print("no (no router)")
|
| 89 |
else: |
| 90 |
if page.status_code == 200: |
| 91 |
print("yes")
|
| 92 |
else: |
| 93 |
print("no (Bad status code: %d)" % page.status_code)
|
| 94 |
sys.exit(0) |
| 95 |
|
| 96 |
rxblank = re.compile(r"[\x00\n\r\t ]+", re.MULTILINE) |
| 97 |
rxcomment = re.compile(r"<!--.*?-->") |
| 98 |
rxscript = re.compile(r"<script.*?</script>", re.MULTILINE) |
| 99 |
|
| 100 |
page = requests.get(URL) |
| 101 |
data = rxscript.sub("", rxcomment.sub("", rxblank.sub(" ", page.text)))
|
| 102 |
dom = html.fromstring(data) |
| 103 |
|
| 104 |
arr = dom.xpath('//table[contains(@class, "simpleTable")]')
|
| 105 |
trs = arr[1].findall("tr")
|
| 106 |
# drop title |
| 107 |
trs.pop(0) |
| 108 |
|
| 109 |
date = "".join(trs[0].findall("td")[1].itertext()).strip()
|
| 110 |
|
| 111 |
arr = date.split(" ")
|
| 112 |
rx = re.compile(r"[hms]") |
| 113 |
days = int(arr[0]) |
| 114 |
hms = rx.sub("", arr[2]).split(":")
|
| 115 |
|
| 116 |
seconds = ((days * 24 + int(hms[0])) * 60 + int(hms[1])) * 60 + int(hms[2]) |
| 117 |
print("uptime.value {0}".format(seconds / 86400.0))
|
