mikrotik snmp monitoring

This commit is contained in:
CroneKorkN 2025-12-13 15:02:37 +01:00
parent 8066efb923
commit 8539f59302
Signed by: cronekorkn
SSH key fingerprint: SHA256:v0410ZKfuO1QHdgKBsdQNF64xmTxOF8osF1LIqwTcVw
8 changed files with 4366 additions and 20 deletions

View file

@ -2,7 +2,7 @@ files = {
'/usr/local/share/telegraf/cpu_frequency': {
'mode': '0755',
'triggers': {
'svc_systemd:telegraf:restart',
'svc_systemd:telegraf.service:restart',
},
},
}

View file

@ -0,0 +1,10 @@
files = {
# https://mikrotik.com/download/tools
'/usr/share/snmp/mibs/MIKROTIK-MIB.txt': {
'source': 'mikrotik.mib',
'mode': '0644',
'needed_by': {
'svc_systemd:telegraf.service',
},
},
}

View file

@ -0,0 +1,143 @@
h = repo.libs.hashable.hashable
defaults = {
'apt': {
'packages': {
'snmp': {},
'snmp-mibs-downloader': {},
},
},
}
@metadata_reactor.provides(
'telegraf/config/inputs/snmp',
)
def routeros_monitoring_telegraf_inputs(metadata):
return {
"telegraf": {
"config": {
"inputs": {
"snmp": [
{
"agents": [f"udp://{routeros_node.hostname}:161"],
"version": 2,
"community": "public",
"interval": "30s",
"tags": {
"host": routeros_node.name,
"operating_system": "routeros",
},
# scalar -> input-level
"field": [
{
"name": "switch_name",
"oid": "SNMPv2-MIB::sysName.0",
"is_tag": True,
},
],
"table": [
# Interface statistics
{
"name": "interface",
"oid": "IF-MIB::ifTable",
"field": [
# Labels (optional but recommended)
{
"name": "ifName",
"oid": "IF-MIB::ifName",
"is_tag": True,
},
{
"name": "ifAlias",
"oid": "IF-MIB::ifAlias",
"is_tag": True,
},
# Bytes (64-bit)
{
"name": "in_octets",
"oid": "IF-MIB::ifHCInOctets",
},
{
"name": "out_octets",
"oid": "IF-MIB::ifHCOutOctets",
},
# Packets (64-bit unicast)
{
"name": "in_ucast_pkts",
"oid": "IF-MIB::ifHCInUcastPkts",
},
{
"name": "out_ucast_pkts",
"oid": "IF-MIB::ifHCOutUcastPkts",
},
# Drops / Errors
{
"name": "in_discards",
"oid": "IF-MIB::ifInDiscards",
},
{
"name": "out_discards",
"oid": "IF-MIB::ifOutDiscards",
},
{
"name": "in_errors",
"oid": "IF-MIB::ifInErrors",
},
{
"name": "out_errors",
"oid": "IF-MIB::ifOutErrors",
},
],
},
# PoE
{
"name": "poe",
"oid": "MIKROTIK-MIB::mtxrPOETable",
"field": [
{
"name": "ifName",
"oid": "IF-MIB::ifName",
"is_tag": True,
},
{
"name": "ifAlias",
"oid": "IF-MIB::ifAlias",
"is_tag": True,
},
{
"name": "poe_ifindex",
"oid": "MIKROTIK-MIB::mtxrPOEInterfaceIndex",
"is_tag": True,
},
{
"name": "poe_status",
"oid": "MIKROTIK-MIB::mtxrPOEStatus",
},
{
"name": "poe_voltage",
"oid": "MIKROTIK-MIB::mtxrPOEVoltage",
},
{
"name": "poe_current",
"oid": "MIKROTIK-MIB::mtxrPOECurrent",
},
{
"name": "poe_power",
"oid": "MIKROTIK-MIB::mtxrPOEPower",
},
],
},
],
}
for routeros_node in repo.nodes_in_group("routeros")
]
}
}
}
}

View file

@ -27,15 +27,15 @@ routeros['/system/identity'] = {
# for topic in LOGGING_TOPICS:
# routeros[f'/system/logging?action=memory&topics={topic}'] = {}
# routeros['/snmp'] = {
# 'enabled': True,
# }
# routeros['/snmp/community?name=public'] = {
# 'addresses': '0.0.0.0/0',
# 'disabled': False,
# 'read-access': True,
# 'write-access': False,
# }
routeros['/snmp'] = {
'enabled': True,
}
routeros['/snmp/community?name=public'] = {
'addresses': '0.0.0.0/0',
'disabled': False,
'read-access': True,
'write-access': False,
}
routeros['/system/clock'] = {
'time-zone-autodetect': False,

View file

@ -12,7 +12,7 @@ files = {
sort_keys=True,
),
'triggers': [
'svc_systemd:telegraf:restart',
'svc_systemd:telegraf.service:restart',
],
},
'/usr/local/share/telegraf/procio': {
@ -27,7 +27,7 @@ files = {
},
}
svc_systemd['telegraf'] = {
svc_systemd['telegraf.service'] = {
'needs': [
'file:/etc/telegraf/telegraf.conf',
'pkg_apt:telegraf',

View file

@ -29,11 +29,12 @@ defaults = {
'collection_jitter': '0s',
'flush_interval': '15s',
'flush_jitter': '0s',
'interval': '15s',
'interval': '1m',
'metric_batch_size': 1000,
'metric_buffer_limit': 10000,
'omit_hostname': False,
'round_interval': True,
'skip_processors_after_aggregators': True,
},
'inputs': {
'cpu': {h({
@ -71,13 +72,13 @@ defaults = {
'system': {h({})},
'net': {h({})},
'exec': {
h({
'commands': [
f'sudo /usr/local/share/telegraf/procio',
],
'data_format': 'influx',
'interval': '20s',
}),
# h({
# 'commands': [
# f'sudo /usr/local/share/telegraf/procio',
# ],
# 'data_format': 'influx',
# 'interval': '20s',
# }),
h({
'commands': [
f'/usr/local/share/telegraf/pressure_stall',

File diff suppressed because it is too large Load diff

View file

@ -33,6 +33,7 @@
'raspberrymatic-cert',
'wol-waker',
'zfs',
'routeros-monitoring',
],
'metadata': {
'id': 'af96709e-b13f-4965-a588-ef2cd476437a',