From c0e5edf270c68528b157f416e04c096eca1f758f Mon Sep 17 00:00:00 2001 From: VG Date: Sun, 8 Dec 2024 08:56:22 +0200 Subject: [PATCH] fix CA information, add 4G CA (untested) --- zte_exporter.py | 53 +++++++++++++++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 22 deletions(-) diff --git a/zte_exporter.py b/zte_exporter.py index 64a7429..81acb83 100644 --- a/zte_exporter.py +++ b/zte_exporter.py @@ -83,7 +83,7 @@ class zteRouter: def zteinfo(self): ip = self.ip cookie = self.getCookie(username=self.username, password=self.password, LD=self.get_LD(), login=self.login) - cmd_url = f"{self.protocol}://{self.ip}/goform/goform_get_cmd_process?multi_data=1&isTest=false&cmd=wa_inner_version%2Clte_rssi%2CZ5g_rssi%2Clte_rsrp%2CZ5g_rsrp%2Clte_rsrq%2CZ5g_rsrq%2Clte_snr%2CZ5g_SINR%2Csignalbar%2Ccell_id%2Cnr5g_action_band%2Ccell_id%2Cnetwork_provider%2Cmonthly_tx_bytes%2Cmonthly_rx_bytes%2Crealtime_tx_bytes%2Crealtime_rx_bytes%2Crealtime_tx_thrpt%2Crealtime_rx_thrpt%2Cwan_ipaddr%2Cwan_apn%2Clte_multi_ca_scell_sig_info%2Cnr_multi_ca_scell_info%2Cnr5g_action_band" + cmd_url = f"{self.protocol}://{self.ip}/goform/goform_get_cmd_process?multi_data=1&isTest=false&cmd=wa_inner_version%2Cwan_ipaddr%2Cwan_apn%2Ccell_id%2Cnr5g_action_band%2CZ5g_rsrq%2CZ5g_rsrp%2CZ5g_rssi%2CZ5g_SINR%2Cnr_multi_ca_scell_info%2Clte_multi_ca_scell_info%2Clte_ca_pcell_band%2Clte_rsrp%2Clte_rsrq%2Clte_rssi%2Clte_snr%2Cmonthly_tx_bytes%2Cmonthly_rx_bytes%2Crealtime_tx_bytes%2Crealtime_rx_bytes%2Crealtime_tx_thrpt%2Crealtime_rx_thrpt"%2Cnr_multi_ca_scell_info%2Cnr5g_action_band" cookie_pass = cookie headers = { @@ -110,9 +110,6 @@ class serveInfos(BaseHTTPRequestHandler): self.send_header("Content-type", "text/plain") self.end_headers() - #self.wfile.write(bytes("\n\n%s\n\n" % json.dumps(gatheredJson, indent=4), "utf-8")) - - # for reference for now self.wfile.write(bytes("# HELP zte_modem_info Modem general information\n# TYPE zte_modem_info untyped\n", "utf-8")) self.wfile.write(bytes("zte_modem_info{firmware=\"%s\",ip_addr=\"" % gatheredJson["wa_inner_version"], "utf-8")) self.wfile.write(bytes("%s\",apn=\"" % gatheredJson["wan_ipaddr"], "utf-8")) @@ -124,7 +121,7 @@ class serveInfos(BaseHTTPRequestHandler): self.wfile.write(bytes("# HELP zte_rsrq Reference Signal Received Quality\n# TYPE zte_rsrq gauge\n", "utf-8")) self.wfile.write(bytes("# HELP zte_rssi Received Signal Strength Indicator\n# TYPE zte_rssi gauge\n", "utf-8")) - if gatheredJson['nr_multi_ca_scell_info'] and gatheredJson['nr5g_action_band']: + if gatheredJson['nr5g_action_band']: self.wfile.write(bytes("zte_rsrq{band=\"%s\"} " % gatheredJson["nr5g_action_band"], "utf-8")) self.wfile.write(bytes("%s\n" % gatheredJson["Z5g_rsrq"], "utf-8")) @@ -137,6 +134,7 @@ class serveInfos(BaseHTTPRequestHandler): self.wfile.write(bytes("zte_snr{band=\"%s\"} " % gatheredJson["nr5g_action_band"], "utf-8")) self.wfile.write(bytes("%s\n\n" % gatheredJson["Z5g_SINR"], "utf-8")) + if gatheredJson['nr_multi_ca_scell_info']: for index, item in enumerate(gatheredJson['nr_multi_ca_scell_info'].split(";")): nrbit = item.split(",") if not len(nrbit[0]) == 0: @@ -152,23 +150,34 @@ class serveInfos(BaseHTTPRequestHandler): self.wfile.write(bytes("zte_snr{band=\"%s\"} " % nrbit[3], "utf-8")) self.wfile.write(bytes("%s\n\n" % nrbit[9], "utf-8")) - else: - if gatheredJson["lte_rsrq"]: - self.wfile.write(bytes("zte_rsrq{band=\"lte\"} %s\n" % gatheredJson["lte_rsrq"], "utf-8")) - if gatheredJson["Z5g_rsrq"]: - self.wfile.write(bytes("zte_rsrq{band=\"5g\"} %s\n" % gatheredJson["Z5g_rsrq"], "utf-8")) - if gatheredJson["lte_rsrp"]: - self.wfile.write(bytes("zte_rsrp{band=\"lte\"} %s\n" % gatheredJson["lte_rsrp"], "utf-8")) - if gatheredJson["Z5g_rssi"]: - self.wfile.write(bytes("zte_rsrp{band=\"5g\"} %s\n" % gatheredJson["Z5g_rssi"], "utf-8")) - if gatheredJson["lte_rssi"]: - self.wfile.write(bytes("zte_snr{band=\"lte\"} %s\n" % gatheredJson["lte_rssi"], "utf-8")) - if gatheredJson["Z5g_SINR"]: - self.wfile.write(bytes("zte_snr{band=\"5g\"} %s\n" % gatheredJson["Z5g_SINR"], "utf-8")) - if gatheredJson["lte_snr"]: - self.wfile.write(bytes("zte_snr{band=\"lte\"} %s\n" % gatheredJson["lte_snr"], "utf-8")) - if gatheredJson["Z5g_SINR"]: - self.wfile.write(bytes("zte_snr{band=\"5g\"} %s\n\n" % gatheredJson["Z5g_SINR"], "utf-8")) + if gatheredJson['lte_ca_pcell_band']: + self.wfile.write(bytes("zte_rsrq{band=\"%s\"} " % gatheredJson["lte_ca_pcell_band"], "utf-8")) + self.wfile.write(bytes("%s\n" % gatheredJson["lte_rsrq"], "utf-8")) + + self.wfile.write(bytes("zte_rsrp{band=\"%s\"} " % gatheredJson["lte_ca_pcell_band"], "utf-8")) + self.wfile.write(bytes("%s\n" % gatheredJson["lte_rsrp"], "utf-8")) + + self.wfile.write(bytes("zte_rssi{band=\"%s\"} " % gatheredJson["lte_ca_pcell_band"], "utf-8")) + self.wfile.write(bytes("%s\n" % gatheredJson["lte_rssi"], "utf-8")) + + self.wfile.write(bytes("zte_snr{band=\"%s\"} " % gatheredJson["lte_ca_pcell_band"], "utf-8")) + self.wfile.write(bytes("%s\n\n" % gatheredJson["lte_snr"], "utf-8")) + + if gatheredJson['lte_multi_ca_scell_info']: + for index, item in enumerate(gatheredJson['lte_multi_ca_scell_info'].split(";")): + cabit = item.split(",") + if not len(cabit[0]) == 0: + self.wfile.write(bytes("zte_rsrq{band=\"%s\"} " % cabit[3], "utf-8")) + self.wfile.write(bytes("%s\n" % cabit[8], "utf-8")) + + self.wfile.write(bytes("zte_rsrp{band=\"%s\"} " % cabit[3], "utf-8")) + self.wfile.write(bytes("%s\n" % cabit[7], "utf-8")) + + self.wfile.write(bytes("zte_rssi{band=\"%s\"} " % cabit[3], "utf-8")) + self.wfile.write(bytes("%s\n" % cabit[10], "utf-8")) + + self.wfile.write(bytes("zte_snr{band=\"%s\"} " % cabit[3], "utf-8")) + self.wfile.write(bytes("%s\n\n" % cabit[9], "utf-8")) self.wfile.write(bytes("# HELP zte_bandwidth_used_monthly_tx Used bandwidth, transmit (bytes)\n# TYPE zte_bandwidth_used_monthly_tx counter\n", "utf-8")) self.wfile.write(bytes("zte_bandwidth_used_monthly_tx %s\n\n" % gatheredJson["monthly_tx_bytes"], "utf-8"))