aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--switch-snmp/.dockerignore5
-rw-r--r--switch-snmp/Dockerfile2
-rw-r--r--switch-snmp/mikrotik-switches.conf10
-rw-r--r--switch-snmp/mikrotik.py24
-rw-r--r--switch-snmp/omada-switches.conf5
5 files changed, 28 insertions, 18 deletions
diff --git a/switch-snmp/.dockerignore b/switch-snmp/.dockerignore
index ea6cd72..662471f 100644
--- a/switch-snmp/.dockerignore
+++ b/switch-snmp/.dockerignore
@@ -1 +1,4 @@
-port-names.conf \ No newline at end of file
+port-names.conf
+*.pem
+*.pub
+
diff --git a/switch-snmp/Dockerfile b/switch-snmp/Dockerfile
index 9e12d5e..4369d61 100644
--- a/switch-snmp/Dockerfile
+++ b/switch-snmp/Dockerfile
@@ -1,4 +1,4 @@
-FROM ubuntu:20.04
+FROM reg.reaweb.uk/cron
ENV TZ=Europe/London
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN apt-get update -y
diff --git a/switch-snmp/mikrotik-switches.conf b/switch-snmp/mikrotik-switches.conf
index b777b53..c1a344c 100644
--- a/switch-snmp/mikrotik-switches.conf
+++ b/switch-snmp/mikrotik-switches.conf
@@ -1,9 +1,9 @@
[192.168.69.22]
-ether1 = Modem
-ether2 = 2
-ether3 = EAP110 Wifi
-ether4 = Amazon Firestick
+ether2 = MikroTik CSS610-8G-2S+IN
+ether1 = TP-RP108GE
+ether3 = 3
+ether4 = 4
ether5 = 5
ether6 = 6
ether7 = 7
-ether8 = 8 \ No newline at end of file
+ether8 = 8
diff --git a/switch-snmp/mikrotik.py b/switch-snmp/mikrotik.py
index 8493675..5c3a88a 100644
--- a/switch-snmp/mikrotik.py
+++ b/switch-snmp/mikrotik.py
@@ -4,12 +4,13 @@ import configparser
import threading
import fabric
import logging
+import socket
import time
import os
import re
-logging.basicConfig(
- format = "%(levelname)s\t[%(asctime)s]\t%(message)s",
+logging.basicConfig(
+ format = "%(levelname)s\t[%(asctime)s]\t%(message)s",
level = logging.INFO,
handlers=[
logging.StreamHandler()
@@ -36,9 +37,10 @@ class MikroTikSSHDevice:
return fabric.Connection(
user = self.user,
host = self.host,
- connect_kwargs = {"key_filename": self.ssh_key_path}
+ connect_kwargs = {"key_filename": self.ssh_key_path},
+ connect_timeout = 5
)
-
+
def _poll_four_interfaces(self, four_interfaces):
# only poll four interfaces at the same time since we can only get a certain amount of information through SSH at the same time
self.is_being_polled.set()
@@ -71,7 +73,7 @@ class MikroTikSSHDevice:
# print("Adding %s to off interfaces" % interface_name)
off_interfaces.add(interface_name)
return out
-
+
def get_poe_interfaces(self, interface_names):
out = {}
for four_interfaces in [interface_names[i:i + 4] for i in range(0, len(interface_names), 4)]:
@@ -79,6 +81,9 @@ class MikroTikSSHDevice:
return out
def remove_measurement_type(type_str):
+ if str(type_str).endswith(".0"):
+ return float(type_str)
+
type_str = "".join([s for s in type_str if s.isdigit() or s == "."])
if "." in type_str:
return float(type_str)
@@ -87,8 +92,8 @@ def remove_measurement_type(type_str):
def fields_to_points(fields, switch_host, config):
return [{
- "measurement": "switch_status",
- "tags": {"port": port, "port_name": config.get(switch_host, port), "switch_host": switch_host, "type": "MikroTik"},
+ "measurement": "switch_status",
+ "tags": {"port": port, "port_name": config.get(switch_host, port), "switch_host": switch_host, "type": "MikroTik"},
"fields": {INFLUXDB_MAPPINGS[k]: remove_measurement_type(v) for k, v in values.items() if k in INFLUXDB_MAPPINGS}
} for port, values in fields.items()]
@@ -100,7 +105,7 @@ def get_points():
mikrotik_device = MikroTikSSHDevice(mikrotik_switch, os.path.join(os.path.dirname(__file__), "mikrotik.pem"))
try:
points += fields_to_points(mikrotik_device.get_poe_interfaces(list(mikrotik_switches[mikrotik_switch].keys())), mikrotik_switch, mikrotik_switches)
- except NoValidConnectionsError as e:
+ except (NoValidConnectionsError, TimeoutError, socket.timeout) as e:
logging.error("Could not connect to mikrotik switch @ %s" % mikrotik_switch)
return points
@@ -123,8 +128,7 @@ if __name__ == "__main__":
raise FileNotFoundError("Couldn't find mikrotik config file")
if not os.path.exists(os.path.join(os.path.dirname(__file__), "mikrotik.pem")):
raise FileNotFoundError("Couldn't find mikrotik public key file")
-
+
import json
points = get_points()
print(json.dumps(points, indent = 4))
-
diff --git a/switch-snmp/omada-switches.conf b/switch-snmp/omada-switches.conf
index 3f3f3f0..a76ff82 100644
--- a/switch-snmp/omada-switches.conf
+++ b/switch-snmp/omada-switches.conf
@@ -1,4 +1,4 @@
-[192.168.69.26]
+[192.168.69.112]
1 = EAP225 Wifi
2 = Tasmota Zigbee
4 = Mikrotik CRS310-8G+2S+
@@ -8,6 +8,7 @@
23 = Modem & ES205G
8 = PiKVM
10 = TL-RP108GE & EAP110
+11 = Type-C POE Charger
22 = Cluster Pi 9
19 = Cluster Pi 5
20 = Cluster Pi 7
@@ -15,4 +16,6 @@
18 = Cluster Pi 6
17 = Cluster Pi 4
9 = Jetson Orin Nano
+12 = Netgate SG-1100
+