add bundle:telegraf-monitors-mikrotik

This commit is contained in:
Franzi 2023-04-01 07:01:03 +02:00
parent 4bcf15a64c
commit a27ac38bec
Signed by: kunsi
GPG key ID: 12E3D2136B818350
4 changed files with 93 additions and 6 deletions

View file

@ -0,0 +1,61 @@
#!/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),
))

View file

@ -0,0 +1,9 @@
files['/usr/local/bin/telegraf-plugin-snmp-mikrotik'] = {
'mode': '0755',
}
pkg_pip['hnmp'] = {
'before': {
'svc_systemd:telegraf',
},
}

View file

@ -0,0 +1,22 @@
@metadata_reactor.provides(
'telegraf/input_plugins/exec',
)
def collect_nodes(metadata):
execs = {}
for rnode in repo.nodes_in_group('switches-mikrotik'):
snmp_pw = rnode.metadata.get('routeros/snmp/community', 'public')
execs[f'snmp_mikrotik_{rnode.name}'] = {
'commands': [f'/usr/local/bin/telegraf-plugin-snmp-mikrotik {rnode.name} {rnode.hostname} {snmp_pw}'],
'data_format': 'influx',
'timeout': '30s',
}
return {
'telegraf': {
'input_plugins': {
'exec': execs,
},
},
}

View file

@ -3,6 +3,7 @@ nodes['htz-cloud.influxdb'] = {
'bundles': {
'grafana',
'influxdb2',
'telegraf-monitors-mikrotik',
'zfs',
},
'groups': {
@ -68,12 +69,6 @@ nodes['htz-cloud.influxdb'] = {
'input_plugins': {
'builtin': {
'snmp': [
{
'agents': ['udp://172.19.138.4'],
'agent_host_tag': 'host',
'table': [{'oid': 'IF-MIB::ifTable'}],
'interval': '10s',
},
{
'agents': ['udp://172.19.138.3'],
'agent_host_tag': 'host',