diff --git a/main.py b/main.py index 8780021ddd0455e17d13f74b8d7dd44d9da4815a..421ba22ffa85c0c763e99de04ac2ed030aa158ec 100755 --- a/main.py +++ b/main.py @@ -28,10 +28,11 @@ class ZyxelCollector: self.targets = targets def collect(self): - channel = prometheus_client.core.InfoMetricFamily("channel", "Channel the radio is operating on", labels=["ap", "ip", "radio"]) - client_count = prometheus_client.core.GaugeMetricFamily('client_count', "Number of clients on this radio", labels=["ap", "ip", "radio"]) - uptime = prometheus_client.core.GaugeMetricFamily('zyxel_uptime', "Number of seconds device is running", labels=["ap", "ip", "radio"]) - util = prometheus_client.core.GaugeMetricFamily('zyxel_chan_util', "Utilization of radio channel", labels=["ap", "ip", "radio"]) + labels = ["ap", "ip", "radio", "location"] + channel = prometheus_client.core.InfoMetricFamily("channel", "Channel the radio is operating on", labels=labels) + client_count = prometheus_client.core.GaugeMetricFamily('client_count', "Number of clients on this radio", labels=labels) + 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: try: @@ -40,10 +41,11 @@ class ZyxelCollector: stats = c.collect() for stat in stats: - client_count.add_metric([stat.hostname, stat.ip, stat.type], stat.client_count) - channel.add_metric([stat.hostname, stat.ip, stat.type], {"channel": stat.channel}) - uptime.add_metric([stat.hostname, stat.ip, stat.type], stat.uptime) - util.add_metric([stat.hostname, stat.ip, stat.type], stat.util) + label_values = [stat.hostname, stat.ip, stat.type, stat.location] + client_count.add_metric(label_values, stat.client_count) + channel.add_metric(label_values, {"channel": stat.channel}) + uptime.add_metric(label_values, stat.uptime) + util.add_metric(label_values, stat.util) c.close() logging.info("Done scaping for %s", target["host"]) except Exception as e: diff --git a/stats.py b/stats.py index 6ef131129dc06e2524875621ae2a0004e0c8c4d0..5e23fb77686333eef2733ed3b71a2b2ded0519d3 100644 --- a/stats.py +++ b/stats.py @@ -7,6 +7,7 @@ TYPE_5G = "5ghz" @dataclass class WifiStats: hostname : str + location : str ip : str uptime : int channel : str diff --git a/zyxel.py b/zyxel.py index a3dcb53d2a04a30dfd093f14de5e3504d6e816ff..22de703e7838f20d7858ae5cb71d2dab7e1b3d4f 100644 --- a/zyxel.py +++ b/zyxel.py @@ -52,6 +52,32 @@ class ZyxelClient: _, ip = line.split(":", maxsplit=1) 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") for line in resp.split("\n"): line = line.strip()