aboutsummaryrefslogtreecommitdiffstats
path: root/switch-snmp
diff options
context:
space:
mode:
authorjwansek <eddie.atten.ea29@gmail.com>2026-06-19 18:00:55 +0100
committerjwansek <eddie.atten.ea29@gmail.com>2026-06-19 18:00:55 +0100
commit79bc0eb0f08638c8ded80b04e4d0ae6f18cbe417 (patch)
tree6ca948f136d016ce48cccbbe1c794c7c9861781a /switch-snmp
parentae73799694b23cc0af558e2ed8bc9b77fd818c47 (diff)
downloadpower.eda.gay-79bc0eb0f08638c8ded80b04e4d0ae6f18cbe417.tar.gz
power.eda.gay-79bc0eb0f08638c8ded80b04e4d0ae6f18cbe417.zip
Started pushing SNMP POE shit to MQTT also
Diffstat (limited to 'switch-snmp')
-rw-r--r--switch-snmp/mikrotik-switches.conf6
-rw-r--r--switch-snmp/omada-switches.conf4
-rw-r--r--switch-snmp/requirements.txt4
-rw-r--r--switch-snmp/switches.py17
4 files changed, 25 insertions, 6 deletions
diff --git a/switch-snmp/mikrotik-switches.conf b/switch-snmp/mikrotik-switches.conf
index 8f13525..9f28a32 100644
--- a/switch-snmp/mikrotik-switches.conf
+++ b/switch-snmp/mikrotik-switches.conf
@@ -1,8 +1,8 @@
[192.168.6.5]
ether2 = 2
-ether1 = 1
-ether3 = 3
-ether4 = 4
+ether1 = Cisco 7940
+ether3 = TypeCPOENIC
+ether4 = ApplePOENIC
ether5 = 5
ether6 = 6
ether7 = 7
diff --git a/switch-snmp/omada-switches.conf b/switch-snmp/omada-switches.conf
index be77cd2..eb112bc 100644
--- a/switch-snmp/omada-switches.conf
+++ b/switch-snmp/omada-switches.conf
@@ -15,11 +15,11 @@
18 = Cluster Pi 6
17 = Cluster Pi 4
9 = Jetson Orin Nano
-12 = Netgate SG-1100
+12 = POETypeC
[192.168.69.27]
1 = Fibre ONT
2 = TL-RP108GE & EAP110
3 = Firestick
-4 = ES205G
+4 = Cisco 7942
diff --git a/switch-snmp/requirements.txt b/switch-snmp/requirements.txt
index aeb5843..c6f1ed1 100644
--- a/switch-snmp/requirements.txt
+++ b/switch-snmp/requirements.txt
@@ -2,4 +2,6 @@ python-dotenv
influxdb-client
pandas
fabric
-prometheus-client \ No newline at end of file
+prometheus-client
+paho-mqtt==1.6.1
+numpyencoder==0.3.2
diff --git a/switch-snmp/switches.py b/switch-snmp/switches.py
index 1bc43c2..06d7b5b 100644
--- a/switch-snmp/switches.py
+++ b/switch-snmp/switches.py
@@ -1,6 +1,9 @@
+import paho.mqtt.client as paho
+from numpyencoder import NumpyEncoder
import prometheus_client
import snmpOmada
import mikrotik
+import json
import os
from influxdb_client import InfluxDBClient, Point, WritePrecision
@@ -15,6 +18,11 @@ def append(points):
influxc.ping()
for measurement in points:
+ mqttc.publish(
+ "tele/SwitchSNMP/%s/%s/SENSOR" % (measurement["tags"]["switch_host"], str(measurement["tags"]["port"])),
+ json.dumps({**measurement["tags"], **measurement["fields"]}, cls = NumpyEncoder),
+ qos = 1
+ )
for field in measurement["fields"].keys():
try:
float(measurement["fields"][field])
@@ -44,11 +52,17 @@ if __name__ == "__main__":
import dotenv
dotenv.load_dotenv(dotenv_path = env_path)
INFLUXDB_HOST = "dns.athome"
+ MQTT_HOST = "dns.athome"
PUSHGATEWAY_HOST = "dns.athome"
else:
+ MQTT_HOST = "mqtt"
INFLUXDB_HOST = "influxdb"
PUSHGATEWAY_HOST = "pushgateway"
+ mqttc = paho.Client("reg.reaweb.uk/switch-snmp", clean_session = True)
+ mqttc.username_pw_set(os.environ["MQTT_USER"], password = os.environ["MQTT_PASSWD"])
+ mqttc.connect(MQTT_HOST, 1883, 60)
+
registry = prometheus_client.CollectorRegistry()
switch_power = prometheus_client.Gauge(
"switch_power",
@@ -60,3 +74,6 @@ if __name__ == "__main__":
points = snmpOmada.get_points() + mikrotik.get_points()
mikrotik.print_points(points)
append(points)
+
+ mqttc.disconnect()
+