Compare commits

...

5 Commits
0.1.4 ... main

Author SHA1 Message Date
61509c0000 queries
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2025-02-10 15:40:37 +01:00
3c09c04066 rename snmp handler to prepared handler, 4
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2025-02-10 14:07:25 +01:00
af739c7148 rename snmp handler to prepared handler, 3
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2025-02-10 14:03:22 +01:00
33ff176c79 rename snmp handler to prepared handler, 2
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2025-02-10 14:01:50 +01:00
134e3706cc rename snmp handler to prepared handler
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2025-02-10 13:58:01 +01:00
5 changed files with 43 additions and 27 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

@ -129,3 +129,20 @@ create or replace view lora_sht21_v as
where m.application = 'de-hottis-app01' and where m.application = 'de-hottis-app01' and
m.attributes->>'DeviceType' = 'hottis-gy21' and m.attributes->>'DeviceType' = 'hottis-gy21' and
m.device = d.label; m.device = d.label;
create or replace view ntp_server_snmp_v as
select time,
device,
cast(values->'load1'->>'value' as float) as laLoad1,
cast(values->'lan-in'->>'value' as int) as lanInOctetsPerSeconds,
cast(values->'lan-out'->>'value' as int) as lanOutOctetsPerSeconds
from measurements
where application = 'SNMP' and device = '172.16.13.10';
create or replace view ntp_server_variables_v as
select time,
device,
cast(values->'rootdisp'->>'value' as float) as rootdisp
from measurements
where application = 'TSM' and device = '172.16.13.10';

View File

@ -9,6 +9,7 @@ type VariableType struct {
Variable string `json:"variable"` Variable string `json:"variable"`
Unit string `json:"unit"` Unit string `json:"unit"`
Value interface{} `json:"value,omitempty"` Value interface{} `json:"value,omitempty"`
Status string `json:"status,omitempty"`
} }
type Measurement struct { type Measurement struct {

View File

@ -17,7 +17,7 @@ import "udi/handlers/sver"
import "udi/handlers/svej" import "udi/handlers/svej"
import "udi/handlers/dt1t" import "udi/handlers/dt1t"
import "udi/handlers/locative" import "udi/handlers/locative"
import "udi/handlers/snmp" import "udi/handlers/prepared"
import "udi/handlers/z2m" import "udi/handlers/z2m"
@ -49,8 +49,8 @@ func InitDispatcher() {
factory = dt1t.New factory = dt1t.New
case "Locative": case "Locative":
factory = locative.New factory = locative.New
case "SNMP": case "PREP":
factory = snmp.New factory = prepared.New
case "Z2M": case "Z2M":
factory = z2m.New factory = z2m.New
default: default:

View File

@ -1,4 +1,4 @@
package snmp package prepared
import ( import (
"time" "time"
@ -10,7 +10,7 @@ import (
) )
type SnmpHandler struct { type PreparedHandler struct {
handler.CommonHandler handler.CommonHandler
dbh *database.DatabaseHandle dbh *database.DatabaseHandle
} }
@ -19,6 +19,8 @@ type endpoint_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"`
Unit string `json:"unit"`
Status string `json:"status"`
} }
type observation_t struct { type observation_t struct {
@ -29,16 +31,16 @@ type observation_t struct {
func New(id string, config config.HandlerConfigT) handler.Handler { func New(id string, config config.HandlerConfigT) handler.Handler {
t := &SnmpHandler { t := &PreparedHandler {
} }
t.Id = id t.Id = id
t.dbh = database.NewDatabaseHandle() t.dbh = database.NewDatabaseHandle()
log.Printf("Handler SNMP %d initialized", id) log.Printf("Handler Prepared %d initialized", id)
return t return t
} }
func (self *SnmpHandler) Handle(message handler.MessageT) { func (self *PreparedHandler) Handle(message handler.MessageT) {
// log.Printf("Handler SNMP %d processing %s -> %s", self.Id, message.Topic, message.Payload) log.Printf("Handler Prepared %d processing %s -> %s", self.Id, message.Topic, message.Payload)
var observation observation_t var observation observation_t
err := json.Unmarshal([]byte(message.Payload), &observation) err := json.Unmarshal([]byte(message.Payload), &observation)
@ -50,7 +52,7 @@ func (self *SnmpHandler) Handle(message handler.MessageT) {
var measurement database.Measurement var measurement database.Measurement
measurement.Time = time.Now() measurement.Time = time.Now()
measurement.Application = "SNMP" measurement.Application = self.Id
measurement.Device = observation.Device measurement.Device = observation.Device
measurement.Attributes = map[string]interface{} { measurement.Attributes = map[string]interface{} {
@ -62,12 +64,13 @@ func (self *SnmpHandler) Handle(message handler.MessageT) {
measurement.Values[k] = database.VariableType { measurement.Values[k] = database.VariableType {
Label: v.Label, Label: v.Label,
Variable: v.Variable, Variable: v.Variable,
Unit: "", Unit: v.Unit,
Value: v.Value, Value: v.Value,
Status: v.Status,
} }
} }
// log.Printf("Prepared measurement item: %s", measurement) log.Printf("Prepared measurement item: %s", measurement)
self.dbh.StoreMeasurement(&measurement) self.dbh.StoreMeasurement(&measurement)
self.S() self.S()