8 Commits
0.0.3 ... 0.0.5

Author SHA1 Message Date
f2d0d1ca94 stratum, 6
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2025-02-11 10:24:57 +01:00
fa0b168ad3 stratum, 5
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2025-02-11 10:15:50 +01:00
4bdeb56013 stratum, 4
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2025-02-11 10:13:29 +01:00
f557893fad stratum, 3
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2025-02-11 10:11:08 +01:00
5de07b85dc stratum, 2
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2025-02-11 10:09:13 +01:00
38d35c1e79 stratum
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2025-02-11 10:06:36 +01:00
101072eabc drop old readme
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2025-02-10 17:12:26 +01:00
cc553c1341 value shall be string, 2
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2025-02-10 14:19:49 +01:00
2 changed files with 14 additions and 71 deletions

View File

@ -1,64 +0,0 @@
# snmp-mqtt
This project is directly derived from https://github.com/dchote/snmp-mqtt
A simple go app that reads SNMP values and publishes it to the specified MQTT endpoint at the specified interval.
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"}}}
```
```
export SNMP_MQTT_CONF=$(cat config.json)
./smq
```
An example config.json file:
```
{
"mqtt": {
"broker": "mqtt://172.23.1.102:1883",
"tlsEnable": "false",
"topic": "snmp"
},
"interval": 10,
"snmpEndpoints": [
{
"endpoint": "172.16.3.1",
"label": "router",
"community": "public",
"oidTopics": [
{
"oid": ".1.3.6.1.2.1.31.1.1.1.6.4",
"label": "wan-in",
"diff": "true"
},
{
"oid": ".1.3.6.1.2.1.31.1.1.1.10.4",
"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"
}
]
}
]
}
```

View File

@ -39,24 +39,31 @@ func Start() {
Variables: make(map[string]variable_t),
}
label := "rootdisp"
status := "Ok"
value := 0.0
rootdisp := 0.0
stratum := 0
resp, err := ntp.Query(server.Name)
if err != nil {
status = "Error"
} else {
value = resp.RootDispersion.Seconds() * 1000
rootdisp = resp.RootDispersion.Seconds() * 1000
stratum = int(resp.Stratum)
}
v := variable_t {
Label: label,
message.Variables["rootdisp"] = variable_t {
Label: "rootdisp",
Variable: "",
Value: strconv.FormatFloat(value, 'f', 4, 64)
Value: strconv.FormatFloat(rootdisp, 'f', 4, 64),
Unit: "ms",
Status: status,
}
message.Variables["stratum"] = variable_t {
Label: "stratum",
Variable: "",
Value: strconv.Itoa(stratum),
Unit: "ms",
Status: status,
}
message.Variables[label] = v
j, err := json.Marshal(message)