27 Commits
0.0.4 ... 0.3.1

Author SHA1 Message Date
a8ab382216 Merge branch 'master' of gitea.hottis.de:wn/snmp-mqtt
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2025-03-19 08:34:37 +01:00
8d6b6eaa3c changes in config 2025-03-19 08:34:33 +01:00
ea948d0bb3 fix config
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2025-03-18 21:37:55 +01:00
30c64cde60 test
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2025-03-18 21:30:26 +01:00
a5712a20a9 config changes
All checks were successful
ci/woodpecker/manual/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2025-03-18 20:47:20 +01:00
36699bd248 Merge branch 'master' of gitea.hottis.de:wn/snmp-mqtt 2025-03-11 20:32:25 +01:00
3ab6814c16 fix 2025-03-11 20:32:17 +01:00
9f19e12375 fix config 2025-03-11 07:40:14 +01:00
917db84ebb harrison 2025-03-10 21:36:33 +01:00
7c7b175893 add new oid, 3
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2025-02-13 10:52:46 +01:00
057b2c3776 add new oid, 2
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2025-02-13 10:47:46 +01:00
15cfb7b51c add new oid
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2025-02-13 10:43:06 +01:00
2852f871ec new points,2
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2025-02-12 18:36:31 +01:00
cdb2eeceed new points
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2025-02-12 18:01:10 +01:00
31a548f08e david
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2025-02-10 15:18:22 +01:00
e0a44205b1 add status
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2025-02-10 13:52:16 +01:00
81378d80e4 add unit in variable
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2025-02-10 13:45:39 +01:00
b0def60a92 fix, 2
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2025-02-10 13:43:15 +01:00
9846f70e5c fix, 1
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2025-02-10 13:40:06 +01:00
2d2e251f0b adjust for dtrack
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2025-02-10 13:38:19 +01:00
aa7498d93e change cluster switch
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2024-05-06 19:00:13 +02:00
b5b2e3ac0d nothing
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-01-29 22:35:52 +01:00
ad9b3625e1 fix anno
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2024-01-26 18:28:12 +01:00
56aec29c76 add cluster switch to config
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-01-26 14:39:08 +01:00
85124d028d use 64bit counter
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-01-25 16:10:53 +01:00
4ed32f8314 fix struct
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2024-01-25 15:24:56 +01:00
4222e19573 skip diff value
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2024-01-25 15:22:29 +01:00
8 changed files with 188 additions and 25 deletions

View File

@ -1,8 +1,20 @@
steps:
build:
image: golang:1.22.5-alpine3.20
commands:
- GOPATH=/woodpecker/go
- ls -l
- cd src/smq
- go mod tidy
- go build -a -installsuffix nocgo -o smq snmp-mqtt.go
- cp smq ../..
when:
- event: [push, tag]
dockerize:
image: plugins/kaniko
settings:
repo: gitea.hottis.de/wn/snmp-mqtt
repo: ${FORGE_NAME}/${CI_REPO}
registry:
from_secret: container_registry
tags: latest,${CI_COMMIT_SHA},${CI_COMMIT_TAG}
@ -15,14 +27,15 @@ steps:
- event: [push, tag]
deploy:
image: portainer/kubectl-shell:latest
secrets:
- source: kube_config
target: KUBE_CONFIG_CONTENT
image: quay.io/wollud1969/woodpecker-helper:0.5.1
environment:
KUBE_CONFIG_CONTENT:
from_secret: kube_config
commands:
- export IMAGE_TAG=$CI_COMMIT_TAG
- printf "$KUBE_CONFIG_CONTENT" > /tmp/kubeconfig
- export KUBECONFIG=/tmp/kubeconfig
- ./deployment/deploy.sh
when:
- event: tag
- event: [tag]

View File

@ -1,16 +1,8 @@
FROM golang:1.21-alpine as builder
RUN mkdir -p /go/src
COPY ./src /go/src
WORKDIR /go/src/smq
RUN go build -a -installsuffix nocgo -o smq snmp-mqtt.go
FROM scratch
ENV SNMP_MQTT_CONF ""
COPY --from=builder /go/src/smq ./
COPY smq ./
ENTRYPOINT ["./smq"]

View File

@ -19,3 +19,5 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -4,20 +4,129 @@
"tlsEnable": "false",
"topic": "snmp"
},
"interval": 10,
"interval": 60,
"snmpEndpoints": [
{
"endpoint": "172.16.13.10",
"label": "david",
"community": "public",
"oidTopics": [
{
"oid": ".1.3.6.1.4.1.2021.10.1.3.1",
"label": "load1",
"diff": "false"
},
{
"oid": ".1.3.6.1.4.1.9676.123.1.4",
"label": "stratum",
"diff": "false"
},
{
"oid": ".1.3.6.1.4.1.9676.123.1.7",
"label": "rootdisp",
"diff": "false"
},
{
"oid": ".1.3.6.1.4.1.9676.123.2.3",
"label": "ss-reset",
"diff": "false"
},
{
"oid": ".1.3.6.1.4.1.9676.123.2.10",
"label": "processed-pkts",
"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.7.2",
"label": "lan-in-pkts",
"diff": "true"
},
{
"oid": ".1.3.6.1.2.1.31.1.1.1.10.2",
"label": "lan-out",
"diff": "true"
},
{
"oid": ".1.3.6.1.2.1.31.1.1.1.11.2",
"label": "lan-out-pkts",
"diff": "true"
}
]
},
{
"endpoint": "172.16.13.11",
"label": "harrison",
"community": "public",
"oidTopics": [
{
"oid": ".1.3.6.1.4.1.2021.10.1.3.1",
"label": "load1",
"diff": "false"
},
{
"oid": ".1.3.6.1.4.1.9676.123.1.4",
"label": "stratum",
"diff": "false"
},
{
"oid": ".1.3.6.1.4.1.9676.123.1.7",
"label": "rootdisp",
"diff": "false"
},
{
"oid": ".1.3.6.1.4.1.9676.123.2.3",
"label": "ss-reset",
"diff": "false"
},
{
"oid": ".1.3.6.1.4.1.9676.123.2.10",
"label": "processed-pkts",
"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.7.2",
"label": "lan-in-pkts",
"diff": "true"
},
{
"oid": ".1.3.6.1.2.1.31.1.1.1.10.2",
"label": "lan-out",
"diff": "true"
},
{
"oid": ".1.3.6.1.2.1.31.1.1.1.11.2",
"label": "lan-out-pkts",
"diff": "true"
}
]
},
{
"endpoint": "172.16.3.1",
"label": "router",
"community": "public",
"oidTopics": [
{
"oid": ".1.3.6.1.2.1.2.2.1.10.5",
"oid": ".1.3.6.1.2.1.25.3.3.1.2.1",
"label": "load1",
"diff": "false"
},
{
"oid": ".1.3.6.1.2.1.31.1.1.1.6.5",
"label": "wan-in",
"diff": "true"
},
{
"oid": ".1.3.6.1.2.1.2.2.1.16.5",
"oid": ".1.3.6.1.2.1.31.1.1.1.10.5",
"label": "wan-out",
"diff": "true"
}

View File

@ -6,7 +6,7 @@ metadata:
labels:
app: snmp-nmqtt
annotations:
secret.reloader.stakater.com/reload: "snmp-mqtt-conf"
secret.reloader.stakater.com/reload: snmp-mqtt-conf
spec:
replicas: 1
selector:

View File

@ -1,6 +1,6 @@
module smq
go 1.21.3
go 1.22.5
require (
github.com/eclipse/paho.mqtt.golang v1.4.3
@ -10,6 +10,6 @@ require (
require (
github.com/gorilla/websocket v1.5.0 // indirect
golang.org/x/net v0.15.0 // indirect
golang.org/x/net v0.34.0 // indirect
golang.org/x/sync v0.1.0 // indirect
)

View File

@ -18,7 +18,8 @@ type variable_t struct {
Label string `json:"label"`
Variable string `json:"variable"`
Value string `json:"value"`
DiffValue string `json:"diffValue"`
Unit string `json:"unit"`
Status string `json:"status"`
}
type message_t struct {
@ -114,15 +115,15 @@ func Start() {
convertedValue = fmt.Sprintf("%d", gosnmp.ToBigInt(variable.Value))
}
diffValue := "-"
if oidTopic.Diff == "true" {
log.Println("Calculate difference to last value")
key := endpoint.Endpoint + ":" + oidTopic.OID
diff, err := calculateDifference(key, convertedValue)
if err != nil {
log.Printf("Error when building difference: %v", err)
convertedValue = "-1"
} else {
diffValue = diff
convertedValue = diff
}
}
@ -131,7 +132,8 @@ func Start() {
Label: oidTopic.Label,
Variable: oidTopic.OID,
Value: convertedValue,
DiffValue: diffValue,
Unit: "",
Status: "",
}
message.Variables[oidTopic.Label] = v

45
tools/mysnmpwalk.sh Executable file
View File

@ -0,0 +1,45 @@
#!/bin/bash
COMMUNITY=""
HOST=""
BASE_OID=""
while getopts "c:h:b:" option; do
case $option in
c) COMMUNITY=$OPTARG
;;
h) HOST=$OPTARG
;;
b) BASE_OID=$OPTARG
;;
?)
echo "Usage $0 -c COMMUNITY -h HOST -b BASE_OID"
exit 1
;;
esac
done
if [ "$COMMUNITY" = "" ]; then
echo "Set a community using -c"
exit 1
fi
if [ "$HOST" = "" ]; then
echo "Set a host using -h"
exit 1
fi
if [ "$BASE_OID" = "" ]; then
echo "Set a base oid using -b"
exit 1
fi
snmpwalk -v 2c -c $COMMUNITY -On $HOST $BASE_OID | while read -r line; do
oid=`echo $line | awk '{print $1}'`
textoid=`snmptranslate $oid`
value=`echo $line | cut -d ' ' -f 3-`
echo "$oid ($textoid): $value"
done