snmp-mqtt/README.md

65 lines
1.8 KiB
Markdown
Raw Permalink Normal View History

2019-10-15 11:40:10 -04:00
# snmp-mqtt
2024-01-25 12:40:25 +01:00
This project is directly derived from https://github.com/dchote/snmp-mqtt
2019-10-15 11:40:10 -04:00
A simple go app that reads SNMP values and publishes it to the specified MQTT endpoint at the specified interval.
2024-01-25 12:39:35 +01:00
In constrast to the original version, all configuration must be provided via an environment variable containing
a JSON string.
The MQTT configuration is part of this JSON string.
The topic has been moved to the MQTT configuration and there is now only one topic for all endpoints and variables.
The published message on MQTT looks like this:
```
{"device":"172.16.3.1","label":"router","variables":{"lan-in":{"label":"lan-in","variable":".1.3.6.1.2.1.31.1.1.1.6.2","value":"979673705579"},"lan-out":{"label":"lan-out","variable":".1.3.6.1.2.1.31.1.1.1.10.2","value":"1813410276168"},"wan-in":{"label":"wan-in","variable":".1.3.6.1.2.1.31.1.1.1.6.4","value":"83591215399"},"wan-out":{"label":"wan-out","variable":".1.3.6.1.2.1.31.1.1.1.10.4","value":"83741895468"}}}
```
2019-10-15 11:40:10 -04:00
```
2024-01-25 12:39:35 +01:00
export SNMP_MQTT_CONF=$(cat config.json)
./smq
2019-10-15 11:40:10 -04:00
```
2024-01-25 12:39:35 +01:00
An example config.json file:
2019-10-15 11:40:10 -04:00
```
{
2024-01-25 12:39:35 +01:00
"mqtt": {
"broker": "mqtt://172.23.1.102:1883",
"tlsEnable": "false",
"topic": "snmp"
},
"interval": 10,
2019-10-15 11:40:10 -04:00
"snmpEndpoints": [
{
2024-01-25 12:39:35 +01:00
"endpoint": "172.16.3.1",
"label": "router",
2019-10-15 11:40:10 -04:00
"community": "public",
"oidTopics": [
{
"oid": ".1.3.6.1.2.1.31.1.1.1.6.4",
2024-01-25 12:39:35 +01:00
"label": "wan-in",
"diff": "true"
2019-10-15 11:40:10 -04:00
},
{
"oid": ".1.3.6.1.2.1.31.1.1.1.10.4",
2024-01-25 12:39:35 +01:00
"label": "wan-out",
"diff": "true"
},
{
"oid": ".1.3.6.1.2.1.31.1.1.1.6.2",
"label": "lan-in",
"diff": "true"
},
{
"oid": ".1.3.6.1.2.1.31.1.1.1.10.2",
"label": "lan-out",
"diff": "true"
2019-10-15 11:40:10 -04:00
}
]
}
2024-01-25 12:39:35 +01:00
]
2019-10-15 11:40:10 -04:00
}
2024-01-25 12:39:35 +01:00
```