Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
61509c0000 | |||
3c09c04066 | |||
af739c7148 | |||
33ff176c79 | |||
134e3706cc |
@ -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": {
|
||||||
|
@ -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';
|
||||||
|
|
||||||
|
@ -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 {
|
||||||
|
@ -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:
|
||||||
|
@ -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()
|
Reference in New Issue
Block a user