bundlewrap/bundles/telegraf-monitors-mikrotik/files/telegraf-plugin-snmp-mikrotik

60 lines
1.5 KiB
Python

#!/usr/bin/env python3
from sys import argv
from hnmp import SNMP
snmp = SNMP(argv[2], community=argv[3])
single_value_metrics_int_oids = {
'cpu-load': '1.3.6.1.2.1.25.3.3.1.2.1',
'cpu-temperature': '1.3.6.1.4.1.14988.1.1.3.11.0',
'fan1-speed': '1.3.6.1.4.1.14988.1.1.3.17.0',
'fan2-speed': '1.3.6.1.4.1.14988.1.1.3.18.0',
'power-consumption': '1.3.6.1.4.1.14988.1.1.3.12.0',
#'psu1-state': '1.3.6.1.4.1.14988.1.1.3.15.0',
'temperature': '1.3.6.1.4.1.14988.1.1.3.10.0',
}
single_value_metrics_int_values = {
key: snmp.get(oid)
for key, oid in single_value_metrics_int_oids.items()
}
formatted_values = sorted([
f"{key}={value}i"
for key, value in single_value_metrics_int_values.items()
if value
])
print("mikrotik,host={host} {values}".format(
host=argv[1],
values=",".join(formatted_values),
))
table = snmp.table(
"1.3.6.1.4.1.14988.1.1.15.1.1",
columns={
2: "interface",
#3: "status",
4: "voltage",
5: "current",
6: "power",
},
fetch_all_columns=False,
)
for row in table.rows:
print(row)
interface_name = row['interface']
values = []
for column, value in row.items():
if column == "interface" or not value:
continue
values.append("{}={}i".format(column, value))
print("mikrotik,interface={interface},host={host} {values}".format(
host=argv[1],
interface=interface_name,
values=",".join(values),
))