Compare commits
32 Commits
Author | SHA1 | Date | |
---|---|---|---|
a0733f70e5 | |||
53dc8a68a3 | |||
a8ab382216 | |||
8d6b6eaa3c | |||
ea948d0bb3
|
|||
30c64cde60
|
|||
a5712a20a9
|
|||
36699bd248 | |||
3ab6814c16 | |||
9f19e12375
|
|||
917db84ebb | |||
7c7b175893
|
|||
057b2c3776
|
|||
15cfb7b51c
|
|||
2852f871ec
|
|||
cdb2eeceed
|
|||
31a548f08e | |||
e0a44205b1 | |||
81378d80e4 | |||
b0def60a92 | |||
9846f70e5c | |||
2d2e251f0b | |||
aa7498d93e
|
|||
b5b2e3ac0d
|
|||
ad9b3625e1
|
|||
56aec29c76
|
|||
85124d028d
|
|||
4ed32f8314
|
|||
4222e19573
|
|||
11e63155bc
|
|||
353a3780c6
|
|||
f407198c5b
|
@ -1,8 +1,20 @@
|
|||||||
steps:
|
steps:
|
||||||
build:
|
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
|
image: plugins/kaniko
|
||||||
settings:
|
settings:
|
||||||
repo: gitea.hottis.de/wn/snmp-mqtt
|
repo: ${FORGE_NAME}/${CI_REPO}
|
||||||
registry:
|
registry:
|
||||||
from_secret: container_registry
|
from_secret: container_registry
|
||||||
tags: latest,${CI_COMMIT_SHA},${CI_COMMIT_TAG}
|
tags: latest,${CI_COMMIT_SHA},${CI_COMMIT_TAG}
|
||||||
@ -15,14 +27,15 @@ steps:
|
|||||||
- event: [push, tag]
|
- event: [push, tag]
|
||||||
|
|
||||||
deploy:
|
deploy:
|
||||||
image: portainer/kubectl-shell:latest
|
image: quay.io/wollud1969/woodpecker-helper:0.5.1
|
||||||
secrets:
|
environment:
|
||||||
- source: kube_config
|
KUBE_CONFIG_CONTENT:
|
||||||
target: KUBE_CONFIG_CONTENT
|
from_secret: kube_config
|
||||||
commands:
|
commands:
|
||||||
- export IMAGE_TAG=$CI_COMMIT_TAG
|
- export IMAGE_TAG=$CI_COMMIT_TAG
|
||||||
- printf "$KUBE_CONFIG_CONTENT" > /tmp/kubeconfig
|
- printf "$KUBE_CONFIG_CONTENT" > /tmp/kubeconfig
|
||||||
- export KUBECONFIG=/tmp/kubeconfig
|
- export KUBECONFIG=/tmp/kubeconfig
|
||||||
- ./deployment/deploy.sh
|
- ./deployment/deploy.sh
|
||||||
when:
|
when:
|
||||||
- event: tag
|
- event: [tag]
|
||||||
|
|
||||||
|
10
Dockerfile
10
Dockerfile
@ -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
|
FROM scratch
|
||||||
|
|
||||||
ENV SNMP_MQTT_CONF ""
|
ENV SNMP_MQTT_CONF ""
|
||||||
|
|
||||||
COPY --from=builder /go/src/smq ./
|
COPY smq ./
|
||||||
ENTRYPOINT ["./smq"]
|
ENTRYPOINT ["./smq"]
|
||||||
|
|
||||||
|
|
||||||
|
2
LICENSE
2
LICENSE
@ -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,
|
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
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
SOFTWARE.
|
SOFTWARE.
|
||||||
|
|
||||||
|
|
||||||
|
@ -2,30 +2,133 @@
|
|||||||
"mqtt": {
|
"mqtt": {
|
||||||
"broker": "mqtt://emqx01-anonymous-cluster-internal.broker.svc.cluster.local:1883",
|
"broker": "mqtt://emqx01-anonymous-cluster-internal.broker.svc.cluster.local:1883",
|
||||||
"tlsEnable": "false",
|
"tlsEnable": "false",
|
||||||
"topicPre": "snmp"
|
"topic": "snmp"
|
||||||
},
|
},
|
||||||
"interval": 60,
|
"interval": 60,
|
||||||
"snmpEndpoints": [
|
"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",
|
"endpoint": "172.16.3.1",
|
||||||
"label": "router",
|
"label": "router",
|
||||||
"community": "public",
|
"community": "public",
|
||||||
"oidTopics": [
|
"oidTopics": [
|
||||||
{
|
{
|
||||||
"oid": ".1.3.6.1.2.1.31.1.1.1.6.4",
|
"oid": ".1.3.6.1.2.1.25.3.3.1.2.1",
|
||||||
"label": "wan-in"
|
"label": "load1",
|
||||||
|
"diff": "false"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"oid": ".1.3.6.1.2.1.31.1.1.1.10.4",
|
"oid": ".1.3.6.1.2.1.31.1.1.1.6.5",
|
||||||
"label": "wan-out"
|
"label": "wan-in",
|
||||||
|
"diff": "true"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"oid": ".1.3.6.1.2.1.31.1.1.1.6.2",
|
"oid": ".1.3.6.1.2.1.31.1.1.1.10.5",
|
||||||
"label": "lan-in"
|
"label": "wan-out",
|
||||||
},
|
"diff": "true"
|
||||||
{
|
|
||||||
"oid": ".1.3.6.1.2.1.31.1.1.1.10.2",
|
|
||||||
"label": "lan-out"
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,8 @@ metadata:
|
|||||||
namespace: homea
|
namespace: homea
|
||||||
labels:
|
labels:
|
||||||
app: snmp-nmqtt
|
app: snmp-nmqtt
|
||||||
|
annotations:
|
||||||
|
secret.reloader.stakater.com/reload: snmp-mqtt-conf
|
||||||
spec:
|
spec:
|
||||||
replicas: 1
|
replicas: 1
|
||||||
selector:
|
selector:
|
||||||
|
4
deployment/pushconfig.sh
Executable file
4
deployment/pushconfig.sh
Executable file
@ -0,0 +1,4 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
|
||||||
|
kubectl create configmap snmp-mqtt-conf --from-literal=SNMP_MQTT_CONF="`cat config.json`" --dry-run=client -o yaml --save-config | kubectl apply -f - -n homea
|
@ -1,6 +1,6 @@
|
|||||||
module smq
|
module smq
|
||||||
|
|
||||||
go 1.21.3
|
go 1.22.5
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/eclipse/paho.mqtt.golang v1.4.3
|
github.com/eclipse/paho.mqtt.golang v1.4.3
|
||||||
@ -10,6 +10,6 @@ require (
|
|||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/gorilla/websocket v1.5.0 // indirect
|
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
|
golang.org/x/sync v0.1.0 // indirect
|
||||||
)
|
)
|
||||||
|
@ -18,7 +18,8 @@ type variable_t struct {
|
|||||||
Label string `json:"label"`
|
Label string `json:"label"`
|
||||||
Variable string `json:"variable"`
|
Variable string `json:"variable"`
|
||||||
Value string `json:"value"`
|
Value string `json:"value"`
|
||||||
DiffValue string `json:"diffValue"`
|
Unit string `json:"unit"`
|
||||||
|
Status string `json:"status"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type message_t struct {
|
type message_t struct {
|
||||||
@ -55,6 +56,9 @@ func calculateDifference(key string, newValue string) (string, error) {
|
|||||||
Timestamp: currentTime,
|
Timestamp: currentTime,
|
||||||
Value: newValue,
|
Value: newValue,
|
||||||
}
|
}
|
||||||
|
if diffValuePerSecond < 0 {
|
||||||
|
return "", fmt.Errorf("negative difference value: %d", diffValuePerSecond)
|
||||||
|
}
|
||||||
return strconv.Itoa(diffValuePerSecond), nil
|
return strconv.Itoa(diffValuePerSecond), nil
|
||||||
} else {
|
} else {
|
||||||
log.Printf("create lvv for %s", key)
|
log.Printf("create lvv for %s", key)
|
||||||
@ -114,15 +118,15 @@ func Start() {
|
|||||||
convertedValue = fmt.Sprintf("%d", gosnmp.ToBigInt(variable.Value))
|
convertedValue = fmt.Sprintf("%d", gosnmp.ToBigInt(variable.Value))
|
||||||
}
|
}
|
||||||
|
|
||||||
diffValue := "0"
|
|
||||||
if oidTopic.Diff == "true" {
|
if oidTopic.Diff == "true" {
|
||||||
log.Println("Calculate difference to last value")
|
log.Println("Calculate difference to last value")
|
||||||
key := endpoint.Endpoint + ":" + oidTopic.OID
|
key := endpoint.Endpoint + ":" + oidTopic.OID
|
||||||
diff, err := calculateDifference(key, convertedValue)
|
diff, err := calculateDifference(key, convertedValue)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error when building difference: %v", err)
|
log.Printf("Error when building difference: %v", err)
|
||||||
|
convertedValue = "-1"
|
||||||
} else {
|
} else {
|
||||||
diffValue = diff
|
convertedValue = diff
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,7 +135,8 @@ func Start() {
|
|||||||
Label: oidTopic.Label,
|
Label: oidTopic.Label,
|
||||||
Variable: oidTopic.OID,
|
Variable: oidTopic.OID,
|
||||||
Value: convertedValue,
|
Value: convertedValue,
|
||||||
DiffValue: diffValue,
|
Unit: "",
|
||||||
|
Status: "",
|
||||||
}
|
}
|
||||||
message.Variables[oidTopic.Label] = v
|
message.Variables[oidTopic.Label] = v
|
||||||
|
|
||||||
|
45
tools/mysnmpwalk.sh
Executable file
45
tools/mysnmpwalk.sh
Executable 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
|
||||||
|
|
||||||
|
|
Reference in New Issue
Block a user