Skip to content
Snippets Groups Projects
Unverified Commit 028b1998 authored by Nico's avatar Nico
Browse files

expose zyxel location

parent 46f3d9b4
No related branches found
No related tags found
No related merge requests found
...@@ -28,10 +28,11 @@ class ZyxelCollector: ...@@ -28,10 +28,11 @@ class ZyxelCollector:
self.targets = targets self.targets = targets
def collect(self): def collect(self):
channel = prometheus_client.core.InfoMetricFamily("channel", "Channel the radio is operating on", labels=["ap", "ip", "radio"]) labels = ["ap", "ip", "radio", "location"]
client_count = prometheus_client.core.GaugeMetricFamily('client_count', "Number of clients on this radio", labels=["ap", "ip", "radio"]) channel = prometheus_client.core.InfoMetricFamily("channel", "Channel the radio is operating on", labels=labels)
uptime = prometheus_client.core.GaugeMetricFamily('zyxel_uptime', "Number of seconds device is running", labels=["ap", "ip", "radio"]) client_count = prometheus_client.core.GaugeMetricFamily('client_count', "Number of clients on this radio", labels=labels)
util = prometheus_client.core.GaugeMetricFamily('zyxel_chan_util', "Utilization of radio channel", labels=["ap", "ip", "radio"]) uptime = prometheus_client.core.GaugeMetricFamily('zyxel_uptime', "Number of seconds device is running", labels=labels)
util = prometheus_client.core.GaugeMetricFamily('zyxel_chan_util', "Utilization of radio channel", labels=labels)
for target in self.targets: for target in self.targets:
try: try:
...@@ -40,10 +41,11 @@ class ZyxelCollector: ...@@ -40,10 +41,11 @@ class ZyxelCollector:
stats = c.collect() stats = c.collect()
for stat in stats: for stat in stats:
client_count.add_metric([stat.hostname, stat.ip, stat.type], stat.client_count) label_values = [stat.hostname, stat.ip, stat.type, stat.location]
channel.add_metric([stat.hostname, stat.ip, stat.type], {"channel": stat.channel}) client_count.add_metric(label_values, stat.client_count)
uptime.add_metric([stat.hostname, stat.ip, stat.type], stat.uptime) channel.add_metric(label_values, {"channel": stat.channel})
util.add_metric([stat.hostname, stat.ip, stat.type], stat.util) uptime.add_metric(label_values, stat.uptime)
util.add_metric(label_values, stat.util)
c.close() c.close()
logging.info("Done scaping for %s", target["host"]) logging.info("Done scaping for %s", target["host"])
except Exception as e: except Exception as e:
......
...@@ -7,6 +7,7 @@ TYPE_5G = "5ghz" ...@@ -7,6 +7,7 @@ TYPE_5G = "5ghz"
@dataclass @dataclass
class WifiStats: class WifiStats:
hostname : str hostname : str
location : str
ip : str ip : str
uptime : int uptime : int
channel : str channel : str
......
...@@ -52,6 +52,32 @@ class ZyxelClient: ...@@ -52,6 +52,32 @@ class ZyxelClient:
_, ip = line.split(":", maxsplit=1) _, ip = line.split(":", maxsplit=1)
ip = ip.strip() ip = ip.strip()
"""
Router> show snmp status
active : no
port : 161
version : v2c
contact : support@zyxel.com.tw
location : Infozelt
get community : public
set community : private
trap : no
informs : no
trap host : none
trap community: public
wireless trap : no
"""
resp = self._run_cmd("show snmp status")
for line in resp.split("\n"):
line = line.strip()
if line.startswith("location"):
_, location = line.split(":", maxsplit=1)
location = location.strip()
"""
Router> show system uptime
system uptime: 05:01:57
"""
resp = self._run_cmd("show system uptime") resp = self._run_cmd("show system uptime")
for line in resp.split("\n"): for line in resp.split("\n"):
line = line.strip() line = line.strip()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment