Compare commits
12 Commits
Author | SHA1 | Date | |
---|---|---|---|
943516f1ac
|
|||
1a8e76dc32
|
|||
3e4c621645
|
|||
c8e60df30b
|
|||
664a2831ab
|
|||
00524c0a3f
|
|||
3af9482880
|
|||
df353d4f6c
|
|||
d1bbbeaccf
|
|||
8cfc92c226
|
|||
08e81e309c
|
|||
f44664eaad
|
@ -2,7 +2,7 @@ steps:
|
||||
build:
|
||||
image: plugins/kaniko
|
||||
settings:
|
||||
repo: gitea.hottis.de/wn/udi
|
||||
repo: ${FORGE_NAME}/${CI_REPO}
|
||||
registry:
|
||||
from_secret: container_registry
|
||||
tags: latest,${CI_COMMIT_SHA},${CI_COMMIT_TAG}
|
||||
@ -14,6 +14,13 @@ steps:
|
||||
when:
|
||||
- event: [push, tag]
|
||||
|
||||
scan_image:
|
||||
image: aquasec/trivy
|
||||
commands:
|
||||
- trivy image $FORGE_NAME/$CI_REPO:$CI_COMMIT_SHA --quiet --exit-code 1
|
||||
when:
|
||||
- event: [push, tag]
|
||||
|
||||
deploy:
|
||||
image: portainer/kubectl-shell:latest
|
||||
secrets:
|
||||
|
@ -13,4 +13,3 @@ ENV UDI_CONF ""
|
||||
COPY --from=builder /go/src/udi ./
|
||||
ENTRYPOINT ["./udi"]
|
||||
|
||||
|
||||
|
@ -4,6 +4,15 @@
|
||||
"tlsEnable": "false"
|
||||
},
|
||||
"topicMappings": [
|
||||
{
|
||||
"topics": [ "snmp" ],
|
||||
"handler": "SNMP",
|
||||
"id": "SNMP",
|
||||
"config": {
|
||||
"attributes": {
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"topics": [ "dt1/ai/periodic/1" ],
|
||||
"handler": "DT1T",
|
||||
@ -44,6 +53,16 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"topics": [ "locative/event/#" ],
|
||||
"handler": "Locative",
|
||||
"id": "Locative",
|
||||
"config": {
|
||||
"databaseConnStr": "",
|
||||
"attributes": {
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"topics": [ "IoT/MBGW3/Measurement" ],
|
||||
"handler": "MBGW3",
|
||||
|
@ -67,3 +67,31 @@ create or replace view soil_v as
|
||||
device
|
||||
from measurements
|
||||
where application = 'de-hottis-app01' and attributes->>'DeviceType' = 'dragino-lse01';
|
||||
|
||||
create or replace view co2_v as
|
||||
select time,
|
||||
cast(m.values->'CO2concentration'->>'value' as float) as co2concentration,
|
||||
cast(m.values->'Humidity'->>'value' as float) as humidity,
|
||||
cast(m.values->'Temperature'->>'value' as float) as temperature,
|
||||
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
|
||||
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';
|
||||
|
@ -16,6 +16,8 @@ import "udi/handlers/mbgw3"
|
||||
import "udi/handlers/sver"
|
||||
import "udi/handlers/svej"
|
||||
import "udi/handlers/dt1t"
|
||||
import "udi/handlers/locative"
|
||||
import "udi/handlers/snmp"
|
||||
|
||||
|
||||
var handlerMap map[string]handler.Handler = make(map[string]handler.Handler)
|
||||
@ -44,6 +46,10 @@ func InitDispatcher() {
|
||||
factory = svej.New
|
||||
case "DT1T":
|
||||
factory = dt1t.New
|
||||
case "Locative":
|
||||
factory = locative.New
|
||||
case "SNMP":
|
||||
factory = snmp.New
|
||||
default:
|
||||
factory = nil
|
||||
log.Printf("No handler %s found, ignore mapping", mapping.Handler)
|
||||
|
@ -17,8 +17,8 @@ require (
|
||||
github.com/jackc/pgx/v5 v5.4.3 // indirect
|
||||
github.com/jinzhu/inflection v1.0.0 // indirect
|
||||
github.com/jinzhu/now v1.1.5 // indirect
|
||||
golang.org/x/crypto v0.14.0 // indirect
|
||||
golang.org/x/net v0.10.0 // indirect
|
||||
golang.org/x/crypto v0.19.0 // indirect
|
||||
golang.org/x/net v0.20.0 // indirect
|
||||
golang.org/x/sync v0.1.0 // indirect
|
||||
golang.org/x/text v0.13.0 // indirect
|
||||
golang.org/x/text v0.14.0 // indirect
|
||||
)
|
||||
|
@ -28,12 +28,18 @@ github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKs
|
||||
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
||||
golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc=
|
||||
golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4=
|
||||
golang.org/x/crypto v0.19.0 h1:ENy+Az/9Y1vSrlrvBSyna3PITt4tiZLf7sgCjZBX7Wo=
|
||||
golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU=
|
||||
golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M=
|
||||
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
|
||||
golang.org/x/net v0.20.0 h1:aCL9BSgETF1k+blQaYUBx9hJ9LOGP3gAVemcZlf1Kpo=
|
||||
golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY=
|
||||
golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o=
|
||||
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k=
|
||||
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
|
||||
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
|
||||
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
|
73
src/udi/handlers/locative/locative.go
Normal file
73
src/udi/handlers/locative/locative.go
Normal file
@ -0,0 +1,73 @@
|
||||
package locative
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"time"
|
||||
"log"
|
||||
"encoding/json"
|
||||
"udi/config"
|
||||
"udi/handlers/handler"
|
||||
"udi/database"
|
||||
)
|
||||
|
||||
|
||||
type LocativeHandler struct {
|
||||
handler.CommonHandler
|
||||
dbh *database.DatabaseHandle
|
||||
}
|
||||
|
||||
type locativeEvent struct {
|
||||
Trigger string `json:"trigger"`
|
||||
Device string `json:"device"`
|
||||
Location string `json:"location"`
|
||||
Latitude string `json:"latitude"`
|
||||
Longitude string `json:"longitude"`
|
||||
Person string `json:"person"`
|
||||
Timestamp string `json:"timestamp"`
|
||||
}
|
||||
|
||||
func New(id string, config config.HandlerConfigT) handler.Handler {
|
||||
t := &LocativeHandler {
|
||||
}
|
||||
t.Id = id
|
||||
t.dbh = database.NewDatabaseHandle()
|
||||
return t
|
||||
}
|
||||
|
||||
|
||||
func (self *LocativeHandler) Handle(message handler.MessageT) {
|
||||
log.Printf("Handler Locative %d processing %s -> %s", self.Id, message.Topic, message.Payload)
|
||||
|
||||
var locativeEvent locativeEvent
|
||||
err := json.Unmarshal([]byte(message.Payload), &locativeEvent)
|
||||
if err != nil {
|
||||
self.Lost("Unable to parse payload into locativeEvent struct", err, message)
|
||||
return
|
||||
}
|
||||
|
||||
variables := make(map[string]database.VariableType)
|
||||
locativeEventStructValue := reflect.ValueOf(locativeEvent)
|
||||
for i := 0; i < locativeEventStructValue.NumField(); i++ {
|
||||
field := locativeEventStructValue.Type().Field(i)
|
||||
fieldValue := locativeEventStructValue.Field(i)
|
||||
v := database.VariableType {
|
||||
Label: "",
|
||||
Variable: field.Name,
|
||||
Unit: "",
|
||||
Value: fieldValue.Interface(),
|
||||
}
|
||||
variables[field.Name] = v
|
||||
}
|
||||
|
||||
measurement := database.Measurement {
|
||||
Time: time.Now(),
|
||||
Application: "Locative",
|
||||
Device: locativeEvent.Person,
|
||||
Values: variables,
|
||||
}
|
||||
|
||||
self.dbh.StoreMeasurement(&measurement)
|
||||
self.S()
|
||||
}
|
||||
|
||||
|
75
src/udi/handlers/snmp/snmp.go
Normal file
75
src/udi/handlers/snmp/snmp.go
Normal 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()
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user