Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
a78c6952f0
|
|||
|
3b69e1e2af
|
|||
|
2dfca8d70a
|
|||
|
0352b720cd
|
|||
|
95984157e8
|
|||
| 61509c0000 | |||
| 3c09c04066 | |||
| af739c7148 | |||
| 33ff176c79 | |||
| 134e3706cc |
@@ -1,3 +1,7 @@
|
|||||||
|
when:
|
||||||
|
- event: tag
|
||||||
|
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
build:
|
build:
|
||||||
image: golang:1.22.5-alpine3.20
|
image: golang:1.22.5-alpine3.20
|
||||||
@@ -7,8 +11,6 @@ steps:
|
|||||||
- go mod tidy
|
- go mod tidy
|
||||||
- go build -a -installsuffix nocgo -o udi main.go
|
- go build -a -installsuffix nocgo -o udi main.go
|
||||||
- cp udi ../..
|
- cp udi ../..
|
||||||
when:
|
|
||||||
- event: [push, tag]
|
|
||||||
|
|
||||||
scan:
|
scan:
|
||||||
image: quay.io/wollud1969/woodpecker-helper:0.5.1
|
image: quay.io/wollud1969/woodpecker-helper:0.5.1
|
||||||
@@ -43,37 +45,29 @@ steps:
|
|||||||
-F "projectVersion=$TAG" \
|
-F "projectVersion=$TAG" \
|
||||||
-F "bom=@/tmp/sbom.xml"\
|
-F "bom=@/tmp/sbom.xml"\
|
||||||
"$DTRACK_API_URL/api/v1/bom"
|
"$DTRACK_API_URL/api/v1/bom"
|
||||||
when:
|
|
||||||
- event: [push, tag]
|
|
||||||
|
|
||||||
dockerize:
|
dockerize:
|
||||||
image: plugins/kaniko
|
image: plugins/kaniko
|
||||||
settings:
|
settings:
|
||||||
repo: ${FORGE_NAME}/${CI_REPO}
|
repo: ${FORGE_NAME}/${CI_REPO}
|
||||||
registry:
|
registry:
|
||||||
from_secret: container_registry
|
from_secret: local_registry
|
||||||
tags: latest,${CI_COMMIT_SHA},${CI_COMMIT_TAG}
|
tags: latest,${CI_COMMIT_TAG}
|
||||||
username:
|
username:
|
||||||
from_secret: container_registry_username
|
from_secret: local_username
|
||||||
password:
|
password:
|
||||||
from_secret: container_registry_password
|
from_secret: local_password
|
||||||
dockerfile: Dockerfile
|
dockerfile: Dockerfile
|
||||||
when:
|
|
||||||
- event: [push, tag]
|
|
||||||
|
|
||||||
deploy:
|
deploy:
|
||||||
image: quay.io/wollud1969/woodpecker-helper:0.5.1
|
image: quay.io/wollud1969/k8s-admin-helper:0.4.1
|
||||||
environment:
|
environment:
|
||||||
KUBE_CONFIG_CONTENT:
|
KUBE_CONFIG_CONTENT:
|
||||||
from_secret: kube_config
|
from_secret: kube_config
|
||||||
ENCRYPTION_KEY:
|
GPG_PASSPHRASE:
|
||||||
from_secret: encryption_key
|
from_secret: gpg_passphrase
|
||||||
MD5_CHECKSUM:
|
|
||||||
from_secret: secrets_checksum
|
|
||||||
commands:
|
commands:
|
||||||
- export IMAGE_TAG=$CI_COMMIT_TAG
|
- export IMAGE_TAG=$CI_COMMIT_TAG
|
||||||
- printf "$KUBE_CONFIG_CONTENT" > /tmp/kubeconfig
|
- printf "$KUBE_CONFIG_CONTENT" > /tmp/kubeconfig
|
||||||
- export KUBECONFIG=/tmp/kubeconfig
|
- export KUBECONFIG=/tmp/kubeconfig
|
||||||
- ./deployment/deploy.sh
|
- ./deployment/deploy.sh
|
||||||
when:
|
|
||||||
- event: tag
|
|
||||||
|
|||||||
@@ -4,6 +4,11 @@ if [ "$IMAGE_TAG" == "" ]; then
|
|||||||
echo "Make sure IMAGE_TAG is set"
|
echo "Make sure IMAGE_TAG is set"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
if [ "$GPG_PASSPHRASE" == "" ]; then
|
||||||
|
echo "Make sure GPG_PASSPHRASE is set"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
IMAGE_NAME=$FORGE_NAME/$CI_REPO
|
IMAGE_NAME=$FORGE_NAME/$CI_REPO
|
||||||
@@ -15,7 +20,10 @@ DEPLOYMENT_DIR=$PWD/deployment
|
|||||||
INSTANCES_DIR=$DEPLOYMENT_DIR/instances
|
INSTANCES_DIR=$DEPLOYMENT_DIR/instances
|
||||||
|
|
||||||
pushd $DEPLOYMENT_DIR > /dev/null
|
pushd $DEPLOYMENT_DIR > /dev/null
|
||||||
./decrypt-secrets.sh || exit 1
|
# ./decrypt-secrets.sh || exit 1
|
||||||
|
# . /tmp/secrets
|
||||||
|
|
||||||
|
gpg --decrypt --yes --batch --passphrase "$GPG_PASSPHRASE" --homedir /tmp/.gnupg -o /tmp/secrets secrets.asc
|
||||||
. /tmp/secrets
|
. /tmp/secrets
|
||||||
rm /tmp/secrets
|
rm /tmp/secrets
|
||||||
popd > /dev/null
|
popd > /dev/null
|
||||||
|
|||||||
@@ -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",
|
||||||
@@ -53,6 +62,16 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"topics": [ "IoT/Car/Values" ],
|
||||||
|
"handler": "Car",
|
||||||
|
"id": "Car",
|
||||||
|
"config": {
|
||||||
|
"databaseConnStr": "",
|
||||||
|
"attributes": {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"topics": [ "locative/event/#" ],
|
"topics": [ "locative/event/#" ],
|
||||||
"handler": "Locative",
|
"handler": "Locative",
|
||||||
@@ -156,20 +175,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": {
|
||||||
|
|||||||
20
deployment/secrets.asc
Normal file
20
deployment/secrets.asc
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
-----BEGIN PGP MESSAGE-----
|
||||||
|
|
||||||
|
jA0ECQMIetkwUzO5q5z+0ukB9IS9Z6rRbXzGHS4dOfwLMbyx2auDu7PYaAgHLHkI
|
||||||
|
25aul+Q2RMUc1WtWgtyIPyVrq84ctjx4AmnXU3Gbsqte6QJIk0RX8w886gTI+NeF
|
||||||
|
RJahlDNeL9LLltQInkFPDXgLC0u/8a+az0aVZUnfAHVhcYkkgQ0JZasc0VQjLqHV
|
||||||
|
dQ3sHmGj1sUC712AujE1f+T5J9CImBdK4r4sZeFq0c3km7hIpOJNkg8LX+0fj9Un
|
||||||
|
/LPPg0Qjq15dnb44UB6g+gsCUCJqTylGAMH4HLvsgRLbs4T4Za0O9lUKZ7UzuvlZ
|
||||||
|
MnbJLIyJt2zxBVQ6NeuchvTmb8Ppkrk2qrO2mXC4hB0YyGtmT3Dy178pNdy7mYR6
|
||||||
|
zLPx7wO+x4MOJOY8uzclHLucAfBhLTgTFCrje+268e99bXuFhAXOA2zqYSyhBI5M
|
||||||
|
XnHUr14XsTACy8CwZRoIpvy9Roe0N3pJq/kdkx/zJ3ieBUWazR5HYFtBeixcELHa
|
||||||
|
EIH9vZCqGi4NfatsZGYyGofVQhV9TnV5yyAruBDsdb0JIYIz1rznzW4megwR6O0K
|
||||||
|
I7W4cTtzT6XdUZQGyWHZO+FSEQ3zoFxLPWeVWj4MJSj0qvd/G2Z07tAw8MJueGRK
|
||||||
|
DsQJOwhrZVH79zuQE+zF+TR3K7A9O3pq0C618gXzXYnVIRoxYqAGo5RyPGlswxRS
|
||||||
|
3sAf8spYQ3iSvo2whpRJ1c7ytmGKPbA3+4YXmJLemCCxiJK3yNJya6xg/hVTeJlL
|
||||||
|
w76+IPGx+VwfURNt+JDf3Xfq2pnppDjW59a69FMraiWCovSl6cUGHr9X+mgQ+C39
|
||||||
|
7OUhKLHQP4s+Yeak5St8/MKKG57bC1k4j07sh9pCXiAPPST3gVhSDmAGPGUDdISd
|
||||||
|
ieOw/ofwzATB+qgEyhPWcRcR/RU0fYwz2q0AxdI6brLgxgGPO6gvQiulY0+MKtuZ
|
||||||
|
kYUnBJiOQ4PBqnPDhtUjGvjT8YAbadWj+pH44bCGd7Q0Kg==
|
||||||
|
=KCiQ
|
||||||
|
-----END PGP MESSAGE-----
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
U2FsdGVkX1+v6L4gc+CbYCZyo/UVN7QfmEntIBpk+GAHGf3d7m/4hfcYd39Eh2td
|
|
||||||
lXSmNdt1cdFw/UfZ1x1OlGm/fqLh/j/rWPgEc6BwEcDFDEXpTucTjUHNDonYNH8j
|
|
||||||
eDWeAGokfguqgQG16CBLHdeyocP0kTPJSrIKQgG1Mzzck/kfB1Z6Ggv4z5KEx2dy
|
|
||||||
2rrnm+BeFT1yITwoxa3iJeudcSQznNIqQa+Mx4fUsPV+yorahp4gs0PVVj9POnAT
|
|
||||||
yRhpQgkaq5oZNVcYrW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6GdHczQsH9gD28HN9+Ka2Cvficf
|
|
||||||
evO7IXe0RuvodQ3tB4LmeWoJB10G7Sko2EEfpFTDXke9Ak/5cGrpdPMtbXCAIm1o
|
|
||||||
B5UhrqNuUYSWdo0mGttbSjFR7pyLujsxLNnp8teBi33QOUhrSId5+mOvtFDGiZKa
|
|
||||||
QCC+W+BIh6IFIwnxH4dDxjz3M65NXzqNV+6mXEFU77cX+oTF4BRe0R/L4nPoaBAN
|
|
||||||
smRxtqBItpVFUdsOVb6bXg==
|
|
||||||
@@ -129,3 +129,54 @@ 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';
|
||||||
|
|
||||||
|
|
||||||
|
-- Status string `unit:"" json:"status"`
|
||||||
|
-- Timestamp string `unit:"" json:"timestamp"`
|
||||||
|
-- VoltageL1 float32 `unit:"V" json:"voltageL1"`
|
||||||
|
-- VoltageL2 float32 `unit:"V" json:"voltageL2"`
|
||||||
|
-- VoltageL3 float32 `unit:"V" json:"voltageL3"`
|
||||||
|
-- CurrentL1 float32 `unit:"A" json:"currentL1"`
|
||||||
|
-- CurrentL2 float32 `unit:"A" json:"currentL2"`
|
||||||
|
-- CurrentL3 float32 `unit:"A" json:"currentL3"`
|
||||||
|
-- PowerL1 float32 `unit:"W" json:"powerL1"`
|
||||||
|
-- PowerL2 float32 `unit:"W" json:"powerL2"`
|
||||||
|
-- PowerL3 float32 `unit:"W" json:"powerL3"`
|
||||||
|
-- TotalImportEnergy float32 `unit:"Wh" json:"totalImportEnergy"`
|
||||||
|
-- TotalExportEnergy float32 `unit:"Wh" json:"totalExportEnergy"`
|
||||||
|
-- Cnt int `unit:"" json:"cnt"`
|
||||||
|
|
||||||
|
|
||||||
|
create or replace view car_values_v as
|
||||||
|
select time,
|
||||||
|
cast(values->'VoltageL1'->>'value' as float) as voltage_l1,
|
||||||
|
cast(values->'VoltageL2'->>'value' as float) as voltage_l2,
|
||||||
|
cast(values->'VoltageL3'->>'value' as float) as voltage_l3,
|
||||||
|
cast(values->'CurrentL1'->>'value' as float) as current_l1,
|
||||||
|
cast(values->'CurrentL2'->>'value' as float) as current_l2,
|
||||||
|
cast(values->'CurrentL3'->>'value' as float) as current_l3,
|
||||||
|
cast(values->'PowerL1'->>'value' as float) as power_l1,
|
||||||
|
cast(values->'PowerL2'->>'value' as float) as power_l2,
|
||||||
|
cast(values->'PowerL3'->>'value' as float) as power_l3,
|
||||||
|
cast(values->'TotalImportEnergy'->>'value' as float) as total_import_energy,
|
||||||
|
cast(values->'TotalExportEnergy'->>'value' as float) as total_export_energy,
|
||||||
|
values->'Status'->>'value' as status,
|
||||||
|
device
|
||||||
|
from measurements
|
||||||
|
where application = 'Car';
|
||||||
@@ -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 {
|
||||||
|
|||||||
@@ -1,149 +1,153 @@
|
|||||||
package dispatcher
|
package dispatcher
|
||||||
|
|
||||||
import "log"
|
import (
|
||||||
import "time"
|
"fmt"
|
||||||
import "os"
|
"log"
|
||||||
import "fmt"
|
"net/url"
|
||||||
import "net/url"
|
"os"
|
||||||
import "udi/mqtt"
|
"time"
|
||||||
import "udi/config"
|
"udi/config"
|
||||||
import "udi/counter"
|
"udi/counter"
|
||||||
import "udi/handlers/handler"
|
"udi/handlers/car"
|
||||||
import "udi/handlers/ttn"
|
"udi/handlers/dt1t"
|
||||||
import "udi/handlers/iot"
|
"udi/handlers/handler"
|
||||||
import "udi/handlers/pv"
|
"udi/handlers/iot"
|
||||||
import "udi/handlers/mbgw3"
|
"udi/handlers/locative"
|
||||||
import "udi/handlers/sver"
|
"udi/handlers/mbgw3"
|
||||||
import "udi/handlers/svej"
|
"udi/handlers/prepared"
|
||||||
import "udi/handlers/dt1t"
|
"udi/handlers/pv"
|
||||||
import "udi/handlers/locative"
|
"udi/handlers/svej"
|
||||||
import "udi/handlers/snmp"
|
"udi/handlers/sver"
|
||||||
import "udi/handlers/z2m"
|
"udi/handlers/ttn"
|
||||||
|
"udi/handlers/z2m"
|
||||||
|
"udi/mqtt"
|
||||||
|
)
|
||||||
|
|
||||||
var handlerMap map[string]handler.Handler = make(map[string]handler.Handler)
|
var handlerMap map[string]handler.Handler = make(map[string]handler.Handler)
|
||||||
var archiverChannel chan handler.MessageT = make(chan handler.MessageT, 100)
|
var archiverChannel chan handler.MessageT = make(chan handler.MessageT, 100)
|
||||||
|
|
||||||
func InitDispatcher() {
|
func InitDispatcher() {
|
||||||
log.Printf("Dispatcher initializing")
|
log.Printf("Dispatcher initializing")
|
||||||
go archiver()
|
go archiver()
|
||||||
|
|
||||||
for _, mapping := range config.Config.TopicMappings {
|
for _, mapping := range config.Config.TopicMappings {
|
||||||
// log.Printf("Trying to initialize %s", mapping)
|
// log.Printf("Trying to initialize %s", mapping)
|
||||||
|
|
||||||
var factory interface{}
|
var factory interface{}
|
||||||
switch mapping.Handler {
|
switch mapping.Handler {
|
||||||
case "TTN":
|
case "TTN":
|
||||||
factory = ttn.New
|
factory = ttn.New
|
||||||
case "IoT":
|
case "IoT":
|
||||||
factory = iot.New
|
factory = iot.New
|
||||||
case "PV":
|
case "PV":
|
||||||
factory = pv.New
|
factory = pv.New
|
||||||
case "MBGW3":
|
case "MBGW3":
|
||||||
factory = mbgw3.New
|
factory = mbgw3.New
|
||||||
case "SVER":
|
case "SVER":
|
||||||
factory = sver.New
|
factory = sver.New
|
||||||
case "SVEJ":
|
case "SVEJ":
|
||||||
factory = svej.New
|
factory = svej.New
|
||||||
case "DT1T":
|
case "DT1T":
|
||||||
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:
|
case "Car":
|
||||||
factory = nil
|
factory = car.New
|
||||||
log.Printf("No handler %s found, ignore mapping", mapping.Handler)
|
default:
|
||||||
}
|
factory = nil
|
||||||
|
log.Printf("No handler %s found, ignore mapping", mapping.Handler)
|
||||||
|
}
|
||||||
|
|
||||||
fn, ok := factory.(func(string, config.HandlerConfigT) handler.Handler)
|
fn, ok := factory.(func(string, config.HandlerConfigT) handler.Handler)
|
||||||
if ! ok {
|
if !ok {
|
||||||
log.Println("Typ Assertion failed")
|
log.Println("Typ Assertion failed")
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
handler := fn(mapping.Id, mapping.Config)
|
handler := fn(mapping.Id, mapping.Config)
|
||||||
handlerMap[mapping.Id] = handler
|
handlerMap[mapping.Id] = handler
|
||||||
}
|
}
|
||||||
|
|
||||||
//log.Printf("handlerMap: %s", handlerMap)
|
//log.Printf("handlerMap: %s", handlerMap)
|
||||||
}
|
}
|
||||||
|
|
||||||
func storeMessage(filename string, item handler.MessageT) {
|
func storeMessage(filename string, item handler.MessageT) {
|
||||||
file, err := os.OpenFile(filename, os.O_APPEND | os.O_CREATE | os.O_WRONLY, 0644)
|
file, err := os.OpenFile(filename, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Unable to open archiving file %s, message is not archived: %s", filename, err)
|
log.Printf("Unable to open archiving file %s, message is not archived: %s", filename, err)
|
||||||
counter.F("Archived")
|
counter.F("Archived")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
archivingString := fmt.Sprintf("%s - %s - %s\n", item.Timestamp.Format("2006-01-02 15:04:05"), item.Topic, item.Payload)
|
archivingString := fmt.Sprintf("%s - %s - %s\n", item.Timestamp.Format("2006-01-02 15:04:05"), item.Topic, item.Payload)
|
||||||
_, err = file.WriteString(string(archivingString) + "\n")
|
_, err = file.WriteString(string(archivingString) + "\n")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Unable to write message, message is not archived: %s", err)
|
log.Printf("Unable to write message, message is not archived: %s", err)
|
||||||
counter.F("Archived")
|
counter.F("Archived")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
//log.Println("Successfully archived message")
|
//log.Println("Successfully archived message")
|
||||||
counter.S("Archived")
|
counter.S("Archived")
|
||||||
}
|
}
|
||||||
|
|
||||||
func archiver() {
|
func archiver() {
|
||||||
archivingRootDir := config.Config.Archiver.Dir
|
archivingRootDir := config.Config.Archiver.Dir
|
||||||
var lastArchivingDir string
|
var lastArchivingDir string
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case message := <- archiverChannel:
|
case message := <-archiverChannel:
|
||||||
currentDateStr := message.Timestamp.Format("2006/01/02/15")
|
currentDateStr := message.Timestamp.Format("2006/01/02/15")
|
||||||
currentArchivingDir := archivingRootDir + "/" + currentDateStr
|
currentArchivingDir := archivingRootDir + "/" + currentDateStr
|
||||||
if currentArchivingDir != lastArchivingDir {
|
if currentArchivingDir != lastArchivingDir {
|
||||||
err := os.MkdirAll(currentArchivingDir, 0755)
|
err := os.MkdirAll(currentArchivingDir, 0755)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Unable to create archiving dir %s: %s", currentArchivingDir, err)
|
log.Printf("Unable to create archiving dir %s: %s", currentArchivingDir, err)
|
||||||
counter.F("Archived")
|
counter.F("Archived")
|
||||||
}
|
}
|
||||||
lastArchivingDir = currentArchivingDir
|
lastArchivingDir = currentArchivingDir
|
||||||
//log.Printf("Archiving dir %s created", currentArchivingDir)
|
//log.Printf("Archiving dir %s created", currentArchivingDir)
|
||||||
}
|
}
|
||||||
archivingFilename := fmt.Sprintf("%s/%s", currentArchivingDir, url.PathEscape(message.Topic))
|
archivingFilename := fmt.Sprintf("%s/%s", currentArchivingDir, url.PathEscape(message.Topic))
|
||||||
storeMessage(archivingFilename, message)
|
storeMessage(archivingFilename, message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func InputDispatcher() {
|
func InputDispatcher() {
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case mqttMessage := <- mqtt.InputChannel:
|
case mqttMessage := <-mqtt.InputChannel:
|
||||||
//log.Printf("Message arrived in inputDispatcher, topic: %s\n", mqttMessage.Topic)
|
//log.Printf("Message arrived in inputDispatcher, topic: %s\n", mqttMessage.Topic)
|
||||||
message := handler.MessageT { time.Now(), mqttMessage.Topic, string(mqttMessage.Payload) }
|
message := handler.MessageT{time.Now(), mqttMessage.Topic, string(mqttMessage.Payload)}
|
||||||
archiverChannel <- message
|
archiverChannel <- message
|
||||||
handleMessage(message)
|
handleMessage(message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleMessage(message handler.MessageT) {
|
func handleMessage(message handler.MessageT) {
|
||||||
for _, mapping := range config.Config.TopicMappings {
|
for _, mapping := range config.Config.TopicMappings {
|
||||||
// log.Printf("Testing %s -> %s", mapping.Topics, mapping.Handler)
|
// log.Printf("Testing %s -> %s", mapping.Topics, mapping.Handler)
|
||||||
for _, subscribedTopic := range mapping.Topics {
|
for _, subscribedTopic := range mapping.Topics {
|
||||||
// log.Printf("Testing %s in %s", message.Topic, subscribedTopic)
|
// log.Printf("Testing %s in %s", message.Topic, subscribedTopic)
|
||||||
if mqtt.TopicMatchesSubscription(message.Topic, subscribedTopic) {
|
if mqtt.TopicMatchesSubscription(message.Topic, subscribedTopic) {
|
||||||
//log.Printf("Handle message in handler %s", mapping.Id)
|
//log.Printf("Handle message in handler %s", mapping.Id)
|
||||||
handler, exists := handlerMap[mapping.Id]
|
handler, exists := handlerMap[mapping.Id]
|
||||||
if exists {
|
if exists {
|
||||||
handler.Handle(message)
|
handler.Handle(message)
|
||||||
counter.S("Dispatched")
|
counter.S("Dispatched")
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
log.Printf("Handler %s not found, message %s is lost", mapping.Id, message)
|
log.Printf("Handler %s not found, message %s is lost", mapping.Id, message)
|
||||||
counter.F("Dispatched")
|
counter.F("Dispatched")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log.Printf("No match for topic %s, message %s is lost", message.Topic, message)
|
log.Printf("No match for topic %s, message %s is lost", message.Topic, message)
|
||||||
counter.F("Dispatched")
|
counter.F("Dispatched")
|
||||||
}
|
}
|
||||||
|
|||||||
94
src/udi/handlers/car/car.go
Normal file
94
src/udi/handlers/car/car.go
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
package car
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"log"
|
||||||
|
"reflect"
|
||||||
|
"time"
|
||||||
|
"udi/config"
|
||||||
|
"udi/database"
|
||||||
|
"udi/handlers/handler"
|
||||||
|
)
|
||||||
|
|
||||||
|
type CarHandler struct {
|
||||||
|
handler.CommonHandler
|
||||||
|
dbh *database.DatabaseHandle
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
{
|
||||||
|
"status": "Ok",
|
||||||
|
"timestamp": "2025-12-15T13:11:15.648243",
|
||||||
|
"voltageL1": 228.68,
|
||||||
|
"voltageL2": 227.69,
|
||||||
|
"voltageL3": 228.53,
|
||||||
|
"currentL1": 0.0,
|
||||||
|
"currentL2": 0.0,
|
||||||
|
"currentL3": 0.0,
|
||||||
|
"powerL1": 0.0,
|
||||||
|
"powerL2": 0.0,
|
||||||
|
"powerL3": 0.0,
|
||||||
|
"totalImportEnergy": 0.0,
|
||||||
|
"totalExportEnergy": 0.0,
|
||||||
|
"cnt": 399300}
|
||||||
|
*/
|
||||||
|
|
||||||
|
type CarValue struct {
|
||||||
|
Status string `unit:"" json:"status"`
|
||||||
|
Timestamp string `unit:"" json:"timestamp"`
|
||||||
|
VoltageL1 float32 `unit:"V" json:"voltageL1"`
|
||||||
|
VoltageL2 float32 `unit:"V" json:"voltageL2"`
|
||||||
|
VoltageL3 float32 `unit:"V" json:"voltageL3"`
|
||||||
|
CurrentL1 float32 `unit:"A" json:"currentL1"`
|
||||||
|
CurrentL2 float32 `unit:"A" json:"currentL2"`
|
||||||
|
CurrentL3 float32 `unit:"A" json:"currentL3"`
|
||||||
|
PowerL1 float32 `unit:"W" json:"powerL1"`
|
||||||
|
PowerL2 float32 `unit:"W" json:"powerL2"`
|
||||||
|
PowerL3 float32 `unit:"W" json:"powerL3"`
|
||||||
|
TotalImportEnergy float32 `unit:"Wh" json:"totalImportEnergy"`
|
||||||
|
TotalExportEnergy float32 `unit:"Wh" json:"totalExportEnergy"`
|
||||||
|
Cnt int `unit:"" json:"cnt"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func New(id string, config config.HandlerConfigT) handler.Handler {
|
||||||
|
t := &CarHandler{}
|
||||||
|
t.Id = id
|
||||||
|
t.dbh = database.NewDatabaseHandle()
|
||||||
|
log.Printf("Handler Car %d initialized", id)
|
||||||
|
return t
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *CarHandler) Handle(message handler.MessageT) {
|
||||||
|
//log.Printf("Handler Car %d processing %s -> %s", self.id, message.Topic, message.Payload)
|
||||||
|
|
||||||
|
var carValue CarValue
|
||||||
|
err := json.Unmarshal([]byte(message.Payload), &carValue)
|
||||||
|
if err != nil {
|
||||||
|
self.Lost("Unable to parse payload into carValue struct", err, message)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
variables := make(map[string]database.VariableType)
|
||||||
|
carValueStructValue := reflect.ValueOf(carValue)
|
||||||
|
for i := 0; i < carValueStructValue.NumField(); i++ {
|
||||||
|
field := carValueStructValue.Type().Field(i)
|
||||||
|
fieldValue := carValueStructValue.Field(i)
|
||||||
|
v := database.VariableType{
|
||||||
|
Label: "",
|
||||||
|
Variable: field.Name,
|
||||||
|
Unit: field.Tag.Get("unit"),
|
||||||
|
Value: fieldValue.Interface(),
|
||||||
|
}
|
||||||
|
variables[field.Name] = v
|
||||||
|
}
|
||||||
|
|
||||||
|
measurement := database.Measurement{
|
||||||
|
Time: time.Now(),
|
||||||
|
Application: "Car",
|
||||||
|
Device: "Powermeter",
|
||||||
|
Values: variables,
|
||||||
|
}
|
||||||
|
|
||||||
|
self.dbh.StoreMeasurement(&measurement)
|
||||||
|
self.S()
|
||||||
|
}
|
||||||
@@ -74,12 +74,22 @@ func (self *Mbgw3Handler) Handle(message handler.MessageT) {
|
|||||||
|
|
||||||
measurement.Values = make(map[string]database.VariableType)
|
measurement.Values = make(map[string]database.VariableType)
|
||||||
unitMap := map[string]string { "Energy": "Wh", "Power": "W", "Voltage": "V", "Current": "A", "Volume": "m3" }
|
unitMap := map[string]string { "Energy": "Wh", "Power": "W", "Voltage": "V", "Current": "A", "Volume": "m3" }
|
||||||
|
keyCount := make(map[string]int)
|
||||||
|
|
||||||
for k, v := range observation.Values {
|
for k, v := range observation.Values {
|
||||||
unit, exists := unitMap[k]
|
unit, exists := unitMap[k]
|
||||||
if ! exists {
|
if ! exists {
|
||||||
unit = "Unmapped Unit"
|
unit = "Unmapped Unit"
|
||||||
}
|
}
|
||||||
measurement.Values[k] = database.VariableType {
|
|
||||||
|
// Check if key already exists and create unique key if needed
|
||||||
|
keyCount[k]++
|
||||||
|
uniqueKey := k
|
||||||
|
if keyCount[k] > 1 {
|
||||||
|
uniqueKey = k + strconv.Itoa(keyCount[k])
|
||||||
|
}
|
||||||
|
|
||||||
|
measurement.Values[uniqueKey] = database.VariableType {
|
||||||
Label: "",
|
Label: "",
|
||||||
Variable: k,
|
Variable: k,
|
||||||
Unit: unit,
|
Unit: unit,
|
||||||
|
|||||||
@@ -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