Skip to content

Instantly share code, notes, and snippets.

@christianchristensen
Last active August 12, 2023 15:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christianchristensen/ae0a514a5338479698e207f3ad34f502 to your computer and use it in GitHub Desktop.
Save christianchristensen/ae0a514a5338479698e207f3ad34f502 to your computer and use it in GitHub Desktop.

Motorola SB6183 montioring script and Zabbix template+config

$ grep 6183 /etc/zabbix/zabbix_agentd.conf
UserParameter=motosb6183[*],/PATH/Motorola_SB6183_RgConnect.py '$1' '$2' $3

$ zabbix_agentd -c /PATH/zabbix_agentd.conf -t "motosb6183[Upstream Bonded Channels,Power,5]"
motosb6183[Upstream Bonded Channels,Power,5]  [t|30.3]

$ zabbix_agentd -c /PATH/zabbix_agentd.conf -t "motosb6183[Upstream Bonded Channels]"
motosb6183[Upstream Bonded Channels]          [t|[{"{#CHANNELID}": "6"}, {"{#CHANNELID}": "5"}, {"{#CHANNELID}": "7"}, {"{#CHANNELID}": "8"}]]
#!/usr/bin/env python2.7
# TODO: Python 2 EOL -> 3
# Parser for Motorola SB6183 Signal page
# Motorola_SB6183_RgCRgConnectt.py <tablename> <column>
# Specify the tablename to return all available (Zabbix LLD format) Bonding Channel Values
# Specity tablename and column to return a specific value for the table and channel
# Data based on Model Name: SB6183, Firmware Name: D30CM-OSPREY-1.5.2.5-GA-00-NOSH
# Downstream Bonded Channels: Channel Lock Status Modulation Channel ID Frequency Power SNR Corrected Uncorrectables
# Upstream Bonded Channels: Channel Lock Status US Channel Type Channel ID Symbol Rate Frequency Power
import json
import os
import sys
import time
import urllib2
from HTMLParser import HTMLParser
# Purpose: Simple class for parsing an (x)html string to extract tables.
# Author: Josua Schmid
# Original: https://github.com/schmijos/html-table-parser-python3
class HTMLTableParser(HTMLParser):
""" This class serves as a html table parser. It is able to parse multiple
tables which you feed in. You can access the result per .tables field.
"""
def __init__(
self,
decode_html_entities=False,
data_separator=' ',
):
HTMLParser.__init__(self)
self._parse_html_entities = decode_html_entities
self._data_separator = data_separator
self._in_td = False
self._in_th = False
self._current_table = []
self._current_row = []
self._current_cell = []
self.tables = []
def handle_starttag(self, tag, attrs):
""" We need to remember the opening point for the content of interest.
The other tags (<table>, <tr>) are only handled at the closing point.
"""
if tag == 'td':
self._in_td = True
if tag == 'th':
self._in_th = True
def handle_data(self, data):
""" This is where we save content to a cell """
if self._in_td or self._in_th:
self._current_cell.append(data.strip())
def handle_charref(self, name):
""" Handle HTML encoded characters """
if self._parse_html_entities:
self.handle_data(self.unescape('&#{};'.format(name)))
def handle_endtag(self, tag):
""" Here we exit the tags. If the closing tag is </tr>, we know that we
can save our currently parsed cells to the current table as a row and
prepare for a new row. If the closing tag is </table>, we save the
current table and prepare for a new one.
"""
if tag == 'td':
self._in_td = False
elif tag == 'th':
self._in_th = False
if tag in ['td', 'th']:
final_cell = self._data_separator.join(self._current_cell).strip()
self._current_row.append(final_cell)
self._current_cell = []
elif tag == 'tr':
self._current_table.append(self._current_row)
self._current_row = []
elif tag == 'table':
self.tables.append(self._current_table)
self._current_table = []
# ---
def url_get_contents(url):
""" Opens a website and read its binary contents (HTTP Response Body) """
req = urllib2.Request(url)
r = urllib2.urlopen(req)
return r.read()
def main():
url = 'http://192.168.100.1/RgConnect.asp'
xhtml = False # cache signal
# Cache
cachefile = '/tmp/.Motorola_SB6183_RgConnect.py.cache'
try:
if os.path.exists(cachefile):
age = time.time() - os.path.getmtime(cachefile)
if age < 120:
f = open(cachefile, "r")
xhtml = f.read()
f.close()
except:
xhtml = False
if not xhtml:
xhtml = url_get_contents(url).decode('utf-8')
try:
f = open(cachefile, 'w')
f.write(xhtml)
f.close()
except:
pass
p = HTMLTableParser()
p.feed(xhtml)
# CLI parse
tablename = sys.argv[1] # Downstream, Upstream, ...
rowname = sys.argv[2] if len(sys.argv)>2 else '' # Frequency, Symbol Rate, ...
chanid = sys.argv[3] if len(sys.argv)==4 else -1
for t in p.tables:
if t[0][0] == tablename:
if chanid != -1:
# Cleanup header rows
t.pop(0) # Header name row
# find row name column index
rowcntid = t.pop(0).index(str(rowname)) # Column title row
for r in t:
if r[3] == chanid:
print r[rowcntid].split()[0] # print first int, float from string
else: # LLD output based on columns available
macroname = t[1][3] # 3rd column is Channel ID
macroname = '{#' + ''.join(macroname.upper().split()) + '}' # tranform to Zabbix format
lld = []
t.pop(0) # Header
t.pop(0) # Column titles
for r in t:
lld.append( { macroname: r[3] } )
print json.dumps(lld)
if __name__ == '__main__':
main()
<?xml version="1.0" encoding="UTF-8"?>
<zabbix_export>
<version>5.4</version>
<date>2022-01-30T18:46:09Z</date>
<groups>
<group>
<uuid>7df96b18c230490a9a0a9e2307226338</uuid>
<name>Templates</name>
</group>
</groups>
<templates>
<template>
<uuid>117764d446d94b2e94c1781537c7e68a</uuid>
<template>Template NET Motorola Arris SB6183</template>
<name>Template NET Motorola Arris SB6183</name>
<description>Monitoring for SB6183 Signal stats</description>
<groups>
<group>
<name>Templates</name>
</group>
</groups>
<items>
<item>
<uuid>38b4b57750634b31bcc57553f0852bfc</uuid>
<name>System Up Time</name>
<type>ZABBIX_ACTIVE</type>
<key>web.page.regexp[192.168.100.1,RgSwInfo.asp,80,&quot;&lt;td...........&gt;(.*.days.*)&lt;/td&gt;&quot;,,&quot;\1&quot;]</key>
<delay>6h</delay>
<history>30d</history>
<trends>0</trends>
<value_type>CHAR</value_type>
<request_method>POST</request_method>
<tags>
<tag>
<tag>Application</tag>
<value>Cable Modem Operation</value>
</tag>
</tags>
</item>
<item>
<uuid>d6732995b1ff4a85b95830f26821999a</uuid>
<name>Hardware Version</name>
<type>ZABBIX_ACTIVE</type>
<key>web.page.regexp[192.168.100.1,RgSwInfo.asp,80,&quot;Hardware Version(.*)&quot;,,&quot;\1&quot;]</key>
<delay>6h</delay>
<history>30d</history>
<trends>0</trends>
<value_type>CHAR</value_type>
<request_method>POST</request_method>
<tags>
<tag>
<tag>Application</tag>
<value>Modem Configuration Manager</value>
</tag>
</tags>
</item>
<item>
<uuid>c027d75a6cf541a692d0a0f792962f2f</uuid>
<name>Serial Number</name>
<type>ZABBIX_ACTIVE</type>
<key>web.page.regexp[192.168.100.1,RgSwInfo.asp,80,&quot;Serial Number(.*)&quot;,,&quot;\1&quot;]</key>
<delay>6h</delay>
<history>30d</history>
<trends>0</trends>
<value_type>CHAR</value_type>
<request_method>POST</request_method>
<tags>
<tag>
<tag>Application</tag>
<value>Modem Configuration Manager</value>
</tag>
</tags>
</item>
<item>
<uuid>2ae03b54e1974e46bbf85e4e0a58a2ee</uuid>
<name>Software Version</name>
<type>ZABBIX_ACTIVE</type>
<key>web.page.regexp[192.168.100.1,RgSwInfo.asp,80,&quot;Software Version.(.*)&quot;,,&quot;\1&quot;]</key>
<delay>6h</delay>
<history>30d</history>
<trends>0</trends>
<value_type>CHAR</value_type>
<request_method>POST</request_method>
<tags>
<tag>
<tag>Application</tag>
<value>Modem Configuration Manager</value>
</tag>
</tags>
</item>
</items>
<discovery_rules>
<discovery_rule>
<uuid>9295304ad8094ca18e6102edd55a2fb9</uuid>
<name>Downstream Channel IDs</name>
<type>ZABBIX_ACTIVE</type>
<key>motosb6183[Downstream Bonded Channels]</key>
<delay>1h</delay>
<filter>
<conditions>
<condition>
<macro>{#CHANNELID}</macro>
<value>.*</value>
<formulaid>A</formulaid>
</condition>
</conditions>
</filter>
<item_prototypes>
<item_prototype>
<uuid>36cb666303094ce3852a35b38cd5e15b</uuid>
<name>Downstream Corrected rate for Channel {#CHANNELID}</name>
<type>ZABBIX_ACTIVE</type>
<key>motosb6183[Downstream Bonded Channels,Corrected,{#CHANNELID},]</key>
<delay>5m</delay>
<history>1w</history>
<preprocessing>
<step>
<type>SIMPLE_CHANGE</type>
<parameters>
<parameter/>
</parameters>
</step>
</preprocessing>
</item_prototype>
<item_prototype>
<uuid>deafd2fd112a49cfb64e0e35a136f298</uuid>
<name>Downstream Corrected for Channel {#CHANNELID}</name>
<type>ZABBIX_ACTIVE</type>
<key>motosb6183[Downstream Bonded Channels,Corrected,{#CHANNELID}]</key>
<delay>5m</delay>
<history>1w</history>
</item_prototype>
<item_prototype>
<uuid>848bfa9a6d6b4dd086b3e31b34eff2ff</uuid>
<name>Downstream Frequency for Channel {#CHANNELID}</name>
<type>ZABBIX_ACTIVE</type>
<key>motosb6183[Downstream Bonded Channels,Frequency,{#CHANNELID}]</key>
<delay>5m</delay>
<history>1w</history>
<units>Hz</units>
<request_method>POST</request_method>
</item_prototype>
<item_prototype>
<uuid>7434898826474fc88f88e9843820655b</uuid>
<name>Downstream Lock Status for Channel {#CHANNELID}</name>
<type>ZABBIX_ACTIVE</type>
<key>motosb6183[Downstream Bonded Channels,Lock Status,{#CHANNELID}]</key>
<delay>5m</delay>
<history>1w</history>
<preprocessing>
<step>
<type>MATCHES_REGEX</type>
<parameters>
<parameter>^Locked$</parameter>
</parameters>
<error_handler>CUSTOM_VALUE</error_handler>
<error_handler_params>1</error_handler_params>
</step>
<step>
<type>NOT_MATCHES_REGEX</type>
<parameters>
<parameter>^Locked$</parameter>
</parameters>
<error_handler>CUSTOM_VALUE</error_handler>
<error_handler_params>0</error_handler_params>
</step>
</preprocessing>
</item_prototype>
<item_prototype>
<uuid>4c5b2536fcf24646b7c5a0fdc1c0f200</uuid>
<name>Downstream Power Level for Channel {#CHANNELID}</name>
<type>ZABBIX_ACTIVE</type>
<key>motosb6183[Downstream Bonded Channels,Power,{#CHANNELID}]</key>
<delay>5m</delay>
<history>1w</history>
<value_type>FLOAT</value_type>
<units>dBmV</units>
<request_method>POST</request_method>
</item_prototype>
<item_prototype>
<uuid>398dbec67bb748c193d881e1386753bd</uuid>
<name>Downstream Signal to Noise Ratio for Channel {#CHANNELID}</name>
<type>ZABBIX_ACTIVE</type>
<key>motosb6183[Downstream Bonded Channels,SNR,{#CHANNELID}]</key>
<delay>5m</delay>
<history>1w</history>
<value_type>FLOAT</value_type>
<units>dB</units>
<request_method>POST</request_method>
</item_prototype>
<item_prototype>
<uuid>7e05f4cd3af143e5a0bd08bfde0b1138</uuid>
<name>Downstream Uncorrectables rate for Channel {#CHANNELID}</name>
<type>ZABBIX_ACTIVE</type>
<key>motosb6183[Downstream Bonded Channels,Uncorrectables,{#CHANNELID},]</key>
<delay>5m</delay>
<history>1w</history>
<preprocessing>
<step>
<type>SIMPLE_CHANGE</type>
<parameters>
<parameter/>
</parameters>
</step>
</preprocessing>
</item_prototype>
<item_prototype>
<uuid>acec816b499c49c895631e95e8bc9aaa</uuid>
<name>Downstream Uncorrectables for Channel {#CHANNELID}</name>
<type>ZABBIX_ACTIVE</type>
<key>motosb6183[Downstream Bonded Channels,Uncorrectables,{#CHANNELID}]</key>
<delay>5m</delay>
<history>1w</history>
</item_prototype>
</item_prototypes>
<request_method>POST</request_method>
</discovery_rule>
<discovery_rule>
<uuid>281800940ef54fe5871ad26ae3dfa84b</uuid>
<name>Upstream Channel IDs</name>
<type>ZABBIX_ACTIVE</type>
<key>motosb6183[Upstream Bonded Channels]</key>
<delay>1h</delay>
<filter>
<conditions>
<condition>
<macro>{#CHANNELID}</macro>
<value>.*</value>
<formulaid>A</formulaid>
</condition>
</conditions>
</filter>
<item_prototypes>
<item_prototype>
<uuid>2540aa1eb4bf48829309716fdaa2d55b</uuid>
<name>Upstream Frequency for Channel {#CHANNELID}</name>
<type>ZABBIX_ACTIVE</type>
<key>motosb6183[Upstream Bonded Channels,Frequency,{#CHANNELID}]</key>
<delay>5m</delay>
<history>1w</history>
<units>Hz</units>
<request_method>POST</request_method>
</item_prototype>
<item_prototype>
<uuid>5cfd6203319049d180670663f07934ef</uuid>
<name>Upstream Lock Status for Channel {#CHANNELID}</name>
<type>ZABBIX_ACTIVE</type>
<key>motosb6183[Upstream Bonded Channels,Lock Status,{#CHANNELID}]</key>
<delay>5m</delay>
<history>1w</history>
<preprocessing>
<step>
<type>MATCHES_REGEX</type>
<parameters>
<parameter>^Locked$</parameter>
</parameters>
<error_handler>CUSTOM_VALUE</error_handler>
<error_handler_params>1</error_handler_params>
</step>
<step>
<type>NOT_MATCHES_REGEX</type>
<parameters>
<parameter>^Locked$</parameter>
</parameters>
<error_handler>CUSTOM_VALUE</error_handler>
<error_handler_params>0</error_handler_params>
</step>
</preprocessing>
<request_method>POST</request_method>
</item_prototype>
<item_prototype>
<uuid>bdea4c4007254b8d9cff978233082c8b</uuid>
<name>Upstream Power Level for Channel {#CHANNELID}</name>
<type>ZABBIX_ACTIVE</type>
<key>motosb6183[Upstream Bonded Channels,Power,{#CHANNELID}]</key>
<delay>5m</delay>
<history>1w</history>
<value_type>FLOAT</value_type>
<units>dBmV</units>
<request_method>POST</request_method>
</item_prototype>
<item_prototype>
<uuid>de89ac03b5954f5cbb6ed6f40e5cd390</uuid>
<name>Upstream Symbol Rate for Channel {#CHANNELID}</name>
<type>ZABBIX_ACTIVE</type>
<key>motosb6183[Upstream Bonded Channels,Symbol Rate,{#CHANNELID}]</key>
<delay>5m</delay>
<history>1w</history>
<value_type>FLOAT</value_type>
<units>Ksym/sec</units>
<request_method>POST</request_method>
</item_prototype>
</item_prototypes>
<request_method>POST</request_method>
</discovery_rule>
</discovery_rules>
</template>
</templates>
</zabbix_export>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment