Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
61509c0000 | |||
3c09c04066 | |||
af739c7148 | |||
33ff176c79 | |||
134e3706cc |
@ -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": {
|
||||
|
@ -129,3 +129,20 @@ create or replace view lora_sht21_v as
|
||||
where m.application = 'de-hottis-app01' and
|
||||
m.attributes->>'DeviceType' = 'hottis-gy21' and
|
||||
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';
|
||||
|
||||
|
@ -9,6 +9,7 @@ type VariableType struct {
|
||||
Variable string `json:"variable"`
|
||||
Unit string `json:"unit"`
|
||||
Value interface{} `json:"value,omitempty"`
|
||||
Status string `json:"status,omitempty"`
|
||||
}
|
||||
|
||||
type Measurement struct {
|
||||
|
@ -17,7 +17,7 @@ import "udi/handlers/sver"
|
||||
import "udi/handlers/svej"
|
||||
import "udi/handlers/dt1t"
|
||||
import "udi/handlers/locative"
|
||||
import "udi/handlers/snmp"
|
||||
import "udi/handlers/prepared"
|
||||
import "udi/handlers/z2m"
|
||||
|
||||
|
||||
@ -49,8 +49,8 @@ func InitDispatcher() {
|
||||
factory = dt1t.New
|
||||
case "Locative":
|
||||
factory = locative.New
|
||||
case "SNMP":
|
||||
factory = snmp.New
|
||||
case "PREP":
|
||||
factory = prepared.New
|
||||
case "Z2M":
|
||||
factory = z2m.New
|
||||
default:
|
||||
|
@ -1,4 +1,4 @@
|
||||
package snmp
|
||||
package prepared
|
||||
|
||||
import (
|
||||
"time"
|
||||
@ -10,7 +10,7 @@ import (
|
||||
)
|
||||
|
||||
|
||||
type SnmpHandler struct {
|
||||
type PreparedHandler struct {
|
||||
handler.CommonHandler
|
||||
dbh *database.DatabaseHandle
|
||||
}
|
||||
@ -19,6 +19,8 @@ type endpoint_t struct {
|
||||
Label string `json:"label"`
|
||||
Variable string `json:"variable"`
|
||||
Value string `json:"value"`
|
||||
Unit string `json:"unit"`
|
||||
Status string `json:"status"`
|
||||
}
|
||||
|
||||
type observation_t struct {
|
||||
@ -29,16 +31,16 @@ type observation_t struct {
|
||||
|
||||
|
||||
func New(id string, config config.HandlerConfigT) handler.Handler {
|
||||
t := &SnmpHandler {
|
||||
t := &PreparedHandler {
|
||||
}
|
||||
t.Id = id
|
||||
t.dbh = database.NewDatabaseHandle()
|
||||
log.Printf("Handler SNMP %d initialized", id)
|
||||
log.Printf("Handler Prepared %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)
|
||||
func (self *PreparedHandler) Handle(message handler.MessageT) {
|
||||
log.Printf("Handler Prepared %d processing %s -> %s", self.Id, message.Topic, message.Payload)
|
||||
|
||||
var observation observation_t
|
||||
err := json.Unmarshal([]byte(message.Payload), &observation)
|
||||
@ -50,7 +52,7 @@ func (self *SnmpHandler) Handle(message handler.MessageT) {
|
||||
var measurement database.Measurement
|
||||
measurement.Time = time.Now()
|
||||
|
||||
measurement.Application = "SNMP"
|
||||
measurement.Application = self.Id
|
||||
measurement.Device = observation.Device
|
||||
|
||||
measurement.Attributes = map[string]interface{} {
|
||||
@ -62,12 +64,13 @@ func (self *SnmpHandler) Handle(message handler.MessageT) {
|
||||
measurement.Values[k] = database.VariableType {
|
||||
Label: v.Label,
|
||||
Variable: v.Variable,
|
||||
Unit: "",
|
||||
Unit: v.Unit,
|
||||
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.S()
|
Reference in New Issue
Block a user