Compare commits

...

6 Commits

Author SHA1 Message Date
00524c0a3f label in snmp measurements
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2024-01-26 14:44:23 +01:00
3af9482880 fix
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2024-01-25 15:27:33 +01:00
df353d4f6c skip diff value
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
ci/woodpecker/tag/woodpecker Pipeline failed
2024-01-25 15:24:11 +01:00
d1bbbeaccf snmp
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2024-01-25 15:13:36 +01:00
8cfc92c226 some more views
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-01-15 11:12:23 +01:00
08e81e309c locative handler, config adjusted
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2024-01-15 10:16:58 +01:00
4 changed files with 121 additions and 5 deletions

View File

@ -4,6 +4,15 @@
"tlsEnable": "false" "tlsEnable": "false"
}, },
"topicMappings": [ "topicMappings": [
{
"topics": [ "snmp" ],
"handler": "SNMP",
"id": "SNMP",
"config": {
"attributes": {
}
}
},
{ {
"topics": [ "dt1/ai/periodic/1" ], "topics": [ "dt1/ai/periodic/1" ],
"handler": "DT1T", "handler": "DT1T",
@ -44,6 +53,16 @@
} }
} }
}, },
{
"topics": [ "locative/event/#" ],
"handler": "Locative",
"id": "Locative",
"config": {
"databaseConnStr": "",
"attributes": {
}
}
},
{ {
"topics": [ "IoT/MBGW3/Measurement" ], "topics": [ "IoT/MBGW3/Measurement" ],
"handler": "MBGW3", "handler": "MBGW3",

View File

@ -70,9 +70,28 @@ create or replace view soil_v as
create or replace view co2_v as create or replace view co2_v as
select time, select time,
cast(values->'CO2concentration'->>'value' as float) as co2concentration, cast(m.values->'CO2concentration'->>'value' as float) as co2concentration,
cast(values->'Humidity'->>'value' as float) as humidity, cast(m.values->'Humidity'->>'value' as float) as humidity,
cast(values->'Temperature'->>'value' as float) as temperature, cast(m.values->'Temperature'->>'value' as float) as temperature,
device m.device as device,
d.attributes->>'Label' as label
from measurements m, devices d
where m.application = 'de-hottis-app01' and
m.attributes->>'DeviceType' = 'hottis-scd30' and
m.device = d.label;
create or replace view locative_v as
select time,
device as person,
values->'Location'->>'value' as location,
values->'Trigger'->>'value' as direction
from measurements from measurements
where application = 'de-hottis-app01' and attributes->>'DeviceType' = 'hottis-scd30'; where application = 'Locative';
create or replace view router_v as
select time,
device,
cast(values->'wan-in'->>'value' as int) as wanInOctetsPerSeconds,
cast(values->'wan-out'->>'value' as int) as wanOutOctetsPerSeconds
from measurements
where application = 'SNMP' and device = '172.16.3.1';

View File

@ -17,6 +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"
var handlerMap map[string]handler.Handler = make(map[string]handler.Handler) var handlerMap map[string]handler.Handler = make(map[string]handler.Handler)
@ -47,6 +48,8 @@ func InitDispatcher() {
factory = dt1t.New factory = dt1t.New
case "Locative": case "Locative":
factory = locative.New factory = locative.New
case "SNMP":
factory = snmp.New
default: default:
factory = nil factory = nil
log.Printf("No handler %s found, ignore mapping", mapping.Handler) log.Printf("No handler %s found, ignore mapping", mapping.Handler)

View File

@ -0,0 +1,75 @@
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()
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()
}