rename snmp handler to prepared handler
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed

This commit is contained in:
Wolfgang Hottgenroth 2025-02-10 13:58:01 +01:00
parent 3a56309b9f
commit 134e3706cc
2 changed files with 10 additions and 91 deletions

View File

@ -6,13 +6,22 @@
"topicMappings": [ "topicMappings": [
{ {
"topics": [ "snmp" ], "topics": [ "snmp" ],
"handler": "SNMP", "handler": "PREP",
"id": "SNMP", "id": "SNMP",
"config": { "config": {
"attributes": { "attributes": {
} }
} }
}, },
{
"topics": [ "tsm" ],
"handler": "PREP",
"id": "TSM",
"config": {
"attributes": {
}
}
},
{ {
"topics": [ "dt1/ai/periodic/1" ], "topics": [ "dt1/ai/periodic/1" ],
"handler": "DT1T", "handler": "DT1T",
@ -156,20 +165,6 @@
"unitSelector": "C:%" "unitSelector": "C:%"
} }
} }
},
{
"topics": [ "tsm" ],
"handler": "SVEJ",
"id": "SVEJ5",
"config": {
"databaseConnStr": "",
"attributes": {
"application": "Timeserver Monitoring",
"deviceSelector": "J:$.label",
"valueSelector": "J:$.variables.rootdisp.value",
"unitSelector": "J:$.variables.rootdisp.unit"
}
}
} }
], ],
"archiver": { "archiver": {

View File

@ -1,76 +0,0 @@
package snmp
import (
"time"
"log"
"encoding/json"
"udi/config"
"udi/handlers/handler"
"udi/database"
)
type SnmpHandler struct {
handler.CommonHandler
dbh *database.DatabaseHandle
}
type endpoint_t struct {
Label string `json:"label"`
Variable string `json:"variable"`
Value string `json:"value"`
}
type observation_t struct {
Device string `json:"device"`
Label string `json:"label"`
Variables map[string]endpoint_t `json:"variables"`
}
func New(id string, config config.HandlerConfigT) handler.Handler {
t := &SnmpHandler {
}
t.Id = id
t.dbh = database.NewDatabaseHandle()
log.Printf("Handler SNMP %d initialized", id)
return t
}
func (self *SnmpHandler) Handle(message handler.MessageT) {
// log.Printf("Handler SNMP %d processing %s -> %s", self.Id, message.Topic, message.Payload)
var observation observation_t
err := json.Unmarshal([]byte(message.Payload), &observation)
if err != nil {
self.Lost("Unable to parse payload into Observation struct", err, message)
return
}
var measurement database.Measurement
measurement.Time = time.Now()
measurement.Application = "SNMP"
measurement.Device = observation.Device
measurement.Attributes = map[string]interface{} {
"Label": observation.Label,
}
measurement.Values = make(map[string]database.VariableType)
for k, v := range observation.Variables {
measurement.Values[k] = database.VariableType {
Label: v.Label,
Variable: v.Variable,
Unit: "",
Value: v.Value,
}
}
// log.Printf("Prepared measurement item: %s", measurement)
self.dbh.StoreMeasurement(&measurement)
self.S()
}