From 134e3706cc035844f52c99bbef9488232a30dfa5 Mon Sep 17 00:00:00 2001 From: Wolfgang Hottgenroth Date: Mon, 10 Feb 2025 13:58:01 +0100 Subject: [PATCH] rename snmp handler to prepared handler --- deployment/instances/udi/default/config.json | 25 +++---- src/udi/handlers/snmp/snmp.go | 76 -------------------- 2 files changed, 10 insertions(+), 91 deletions(-) delete mode 100644 src/udi/handlers/snmp/snmp.go diff --git a/deployment/instances/udi/default/config.json b/deployment/instances/udi/default/config.json index 087776f..d824512 100644 --- a/deployment/instances/udi/default/config.json +++ b/deployment/instances/udi/default/config.json @@ -6,13 +6,22 @@ "topicMappings": [ { "topics": [ "snmp" ], - "handler": "SNMP", + "handler": "PREP", "id": "SNMP", "config": { "attributes": { } } }, + { + "topics": [ "tsm" ], + "handler": "PREP", + "id": "TSM", + "config": { + "attributes": { + } + } + }, { "topics": [ "dt1/ai/periodic/1" ], "handler": "DT1T", @@ -156,20 +165,6 @@ "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": { diff --git a/src/udi/handlers/snmp/snmp.go b/src/udi/handlers/snmp/snmp.go deleted file mode 100644 index e6e5e8e..0000000 --- a/src/udi/handlers/snmp/snmp.go +++ /dev/null @@ -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() -} - -