Compare commits
34 Commits
Author | SHA1 | Date | |
---|---|---|---|
4debe45592
|
|||
71773968c9
|
|||
574e2886f5
|
|||
e25693fb84
|
|||
ff49d285dc
|
|||
8c3977162b
|
|||
b99b47ca40
|
|||
c40805b4cb
|
|||
a2eb38b414
|
|||
64cf45e22f
|
|||
9310a86687
|
|||
f4b404e2b1
|
|||
29148a13f4
|
|||
0356e9dcee
|
|||
a5b981357d
|
|||
57bbc6135e
|
|||
d704f7ba5e
|
|||
d0567a48f1
|
|||
ee22996433
|
|||
4130befdbf
|
|||
77c5df0697
|
|||
d4ee4c49de
|
|||
ae938d10b9 | |||
799ef9e00b | |||
311e732841 | |||
51e482e94e
|
|||
a1b98d3438
|
|||
166c414af1
|
|||
cedb1dfa5a
|
|||
a21fae4f8a
|
|||
1b6ac5d762
|
|||
95831d5e47
|
|||
c3dce9faab
|
|||
c332373691
|
@ -1,5 +1,50 @@
|
||||
steps:
|
||||
build:
|
||||
image: golang:1.22.5-alpine3.20
|
||||
commands:
|
||||
- GOPATH=/woodpecker/go
|
||||
- cd src/udi
|
||||
- go mod tidy
|
||||
- go build -a -installsuffix nocgo -o udi main.go
|
||||
- cp udi ../..
|
||||
|
||||
scan:
|
||||
image: quay.io/wollud1969/woodpecker-helper:0.5.1
|
||||
environment:
|
||||
TRIVY_TOKEN:
|
||||
from_secret: trivy_token
|
||||
TRIVY_URL:
|
||||
from_secret: trivy_url
|
||||
DTRACK_API_KEY:
|
||||
from_secret: dtrack_api_key
|
||||
DTRACK_API_URL:
|
||||
from_secret: dtrack_api_url
|
||||
commands:
|
||||
- export GOPATH=/woodpecker/go # the export is required, otherwise trivy will not consider the variable
|
||||
- HOME=/home/`id -nu`
|
||||
- TAG="${CI_COMMIT_TAG:-$CI_COMMIT_SHA}"
|
||||
- |
|
||||
trivy fs \
|
||||
--server $TRIVY_URL \
|
||||
--token $TRIVY_TOKEN \
|
||||
--format cyclonedx \
|
||||
--scanners license \
|
||||
--output /tmp/sbom.xml \
|
||||
.
|
||||
- cat /tmp/sbom.xml
|
||||
- |
|
||||
curl -X "POST" \
|
||||
-H "Content-Type: multipart/form-data" \
|
||||
-H "X-Api-Key: $DTRACK_API_KEY" \
|
||||
-F "autoCreate=true" \
|
||||
-F "projectName=$CI_REPO" \
|
||||
-F "projectVersion=$TAG" \
|
||||
-F "bom=@/tmp/sbom.xml"\
|
||||
"$DTRACK_API_URL/api/v1/bom"
|
||||
when:
|
||||
- event: [push, tag]
|
||||
|
||||
dockerize:
|
||||
image: plugins/kaniko
|
||||
settings:
|
||||
repo: ${FORGE_NAME}/${CI_REPO}
|
||||
@ -15,14 +60,14 @@ steps:
|
||||
- event: [push, tag]
|
||||
|
||||
deploy:
|
||||
image: portainer/kubectl-shell:latest
|
||||
secrets:
|
||||
- source: kube_config
|
||||
target: KUBE_CONFIG_CONTENT
|
||||
- source: encryption_key
|
||||
target: ENCRYPTION_KEY
|
||||
- source: secrets_checksum
|
||||
target: MD5_CHECKSUM
|
||||
image: quay.io/wollud1969/woodpecker-helper:0.5.1
|
||||
environment:
|
||||
KUBE_CONFIG_CONTENT:
|
||||
from_secret: kube_config
|
||||
ENCRYPTION_KEY:
|
||||
from_secret: encryption_key
|
||||
MD5_CHECKSUM:
|
||||
from_secret: secrets_checksum
|
||||
commands:
|
||||
- export IMAGE_TAG=$CI_COMMIT_TAG
|
||||
- printf "$KUBE_CONFIG_CONTENT" > /tmp/kubeconfig
|
||||
|
11
Dockerfile
11
Dockerfile
@ -1,15 +1,8 @@
|
||||
FROM golang:1.22.5-alpine3.20 as builder
|
||||
|
||||
RUN mkdir -p /go/src
|
||||
COPY ./src/ /go/src
|
||||
WORKDIR /go/src/udi
|
||||
RUN go build -a -installsuffix nocgo -o udi main.go
|
||||
|
||||
|
||||
FROM scratch
|
||||
|
||||
ENV UDI_CONF ""
|
||||
|
||||
COPY --from=builder /go/src/udi ./
|
||||
COPY udi ./
|
||||
|
||||
ENTRYPOINT ["./udi"]
|
||||
|
||||
|
@ -10,6 +10,7 @@ if [ "$MD5_CHECKSUM" = "" ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
SECRETS_CIPHERTEXT_FILE=secrets.enc
|
||||
SECRETS_PLAINTEXT_FILE=/tmp/secrets
|
||||
TMP_FILE=`mktemp`
|
||||
@ -37,7 +38,7 @@ if [ "$MD5_CHECKSUM" != "$CALCULATED_CHECKSUM" ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# cat $TMP_FILE
|
||||
#cat $TMP_FILE
|
||||
mv $TMP_FILE $SECRETS_PLAINTEXT_FILE
|
||||
|
||||
|
||||
|
@ -58,7 +58,7 @@ for NAMESPACE_DIR in `find $INSTANCES_DIR -type d -mindepth 1 -maxdepth 1`; do
|
||||
NEW_UDI_DB_PASSWORD="${!PASSWORD_VARIABLE}"
|
||||
DATABASE_VARIABLE=$VARIABLE_PREFIX"_PGDATABASE"
|
||||
NEW_UDI_DB_DATABASE="${!DATABASE_VARIABLE}"
|
||||
NEW_UDI_DB_HOST=timescaledb.database.svc.cluster.local
|
||||
NEW_UDI_DB_HOST=database.database1.svc.cluster.local
|
||||
|
||||
kubectl create secret generic $INSTANCE-udi-db-cred \
|
||||
--dry-run=client \
|
||||
|
@ -1,2 +1,2 @@
|
||||
loguru==0.7.2
|
||||
loguru==0.7.3
|
||||
psycopg2==2.9.9
|
||||
|
@ -118,3 +118,14 @@ create or replace view router_v as
|
||||
cast(values->'wan-out'->>'value' as int) as wanOutOctetsPerSeconds
|
||||
from measurements
|
||||
where application = 'SNMP' and device = '172.16.3.1';
|
||||
|
||||
create or replace view lora_sht21_v as
|
||||
select time,
|
||||
cast(values->'Humidity'->>'value' as float) as humidity,
|
||||
cast(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-gy21' and
|
||||
m.device = d.label;
|
||||
|
@ -41,3 +41,4 @@ create or replace view cubecell_threeway_battery_v as
|
||||
from measurements
|
||||
where application = 'de-hottis-saerbeck-monitoring' and
|
||||
device = 'eui-70b3d57ed0068fa4';
|
||||
|
||||
|
@ -25,7 +25,7 @@ func NewDatabaseHandle() *DatabaseHandle {
|
||||
} else {
|
||||
db.dbh = conn
|
||||
db.initialized = true
|
||||
//log.Println("Database connection opened")
|
||||
log.Println("Database connection opened")
|
||||
}
|
||||
return &db
|
||||
}
|
||||
@ -44,7 +44,7 @@ func (self *DatabaseHandle) StoreMeasurement(measurement *Measurement) {
|
||||
return
|
||||
}
|
||||
|
||||
//log.Println("Successfully stored measurement")
|
||||
log.Println("Successfully stored measurement")
|
||||
counter.S("Stored")
|
||||
}
|
||||
|
||||
|
@ -18,8 +18,8 @@ require (
|
||||
github.com/jackc/puddle/v2 v2.2.1 // indirect
|
||||
github.com/jinzhu/inflection v1.0.0 // indirect
|
||||
github.com/jinzhu/now v1.1.5 // indirect
|
||||
golang.org/x/crypto v0.25.0 // indirect
|
||||
golang.org/x/net v0.27.0 // indirect
|
||||
golang.org/x/sync v0.7.0 // indirect
|
||||
golang.org/x/text v0.16.0 // indirect
|
||||
golang.org/x/crypto v0.32.0 // indirect
|
||||
golang.org/x/net v0.34.0 // indirect
|
||||
golang.org/x/sync v0.10.0 // indirect
|
||||
golang.org/x/text v0.21.0 // indirect
|
||||
)
|
||||
|
@ -28,14 +28,14 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
|
||||
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
||||
golang.org/x/crypto v0.25.0 h1:ypSNr+bnYL2YhwoMt2zPxHFmbAN1KZs/njMG3hxUp30=
|
||||
golang.org/x/crypto v0.25.0/go.mod h1:T+wALwcMOSE0kXgUAnPAHqTLW+XHgcELELW8VaDgm/M=
|
||||
golang.org/x/net v0.27.0 h1:5K3Njcw06/l2y9vpGCSdcxWOYHOUk3dVNGDXN+FvAys=
|
||||
golang.org/x/net v0.27.0/go.mod h1:dDi0PyhWNoiUOrAS8uXv/vnScO4wnHQO4mj9fn/RytE=
|
||||
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
|
||||
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||
golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4=
|
||||
golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI=
|
||||
golang.org/x/crypto v0.32.0 h1:euUpcYgM8WcP71gNpTqQCn6rC2t6ULUPiOzfWaXVVfc=
|
||||
golang.org/x/crypto v0.32.0/go.mod h1:ZnnJkOaASj8g0AjIduWNlq2NRxL0PlBrbKVyZ6V/Ugc=
|
||||
golang.org/x/net v0.34.0 h1:Mb7Mrk043xzHgnRM88suvJFwzVrRfHEHJEl5/71CKw0=
|
||||
golang.org/x/net v0.34.0/go.mod h1:di0qlW3YNM5oh6GqDGQr92MyTozJPmybPK4Ev/Gm31k=
|
||||
golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ=
|
||||
golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
|
||||
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
|
||||
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=
|
||||
|
@ -38,6 +38,7 @@ func New(id string, config config.HandlerConfigT) handler.Handler {
|
||||
t.Id = id
|
||||
|
||||
t.dbh = database.NewDatabaseHandle()
|
||||
log.Printf("Handler DT1T %d initialized", id)
|
||||
t.ready = true
|
||||
return t
|
||||
}
|
||||
|
@ -31,6 +31,7 @@ func New(id string, config config.HandlerConfigT) handler.Handler {
|
||||
}
|
||||
t.Id = id
|
||||
t.dbh = database.NewDatabaseHandle()
|
||||
log.Printf("Handler Locative %d initialized", id)
|
||||
return t
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,7 @@ package mbgw3
|
||||
|
||||
import (
|
||||
"time"
|
||||
"log"
|
||||
"strconv"
|
||||
"encoding/json"
|
||||
"udi/config"
|
||||
@ -31,6 +32,7 @@ func New(id string, config config.HandlerConfigT) handler.Handler {
|
||||
}
|
||||
t.Id = id
|
||||
t.dbh = database.NewDatabaseHandle()
|
||||
log.Printf("Handler MBGW3 %d initialized", id)
|
||||
return t
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,7 @@ package pv
|
||||
import (
|
||||
"reflect"
|
||||
"time"
|
||||
"log"
|
||||
"encoding/json"
|
||||
"udi/config"
|
||||
"udi/handlers/handler"
|
||||
@ -41,6 +42,7 @@ func New(id string, config config.HandlerConfigT) handler.Handler {
|
||||
}
|
||||
t.Id = id
|
||||
t.dbh = database.NewDatabaseHandle()
|
||||
log.Printf("Handler PV %d initialized", id)
|
||||
return t
|
||||
}
|
||||
|
||||
|
@ -33,11 +33,12 @@ func New(id string, config config.HandlerConfigT) handler.Handler {
|
||||
}
|
||||
t.Id = id
|
||||
t.dbh = database.NewDatabaseHandle()
|
||||
log.Printf("Handler SNMP %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)
|
||||
// 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)
|
||||
@ -66,7 +67,7 @@ func (self *SnmpHandler) Handle(message handler.MessageT) {
|
||||
}
|
||||
}
|
||||
|
||||
# log.Printf("Prepared measurement item: %s", measurement)
|
||||
// log.Printf("Prepared measurement item: %s", measurement)
|
||||
|
||||
self.dbh.StoreMeasurement(&measurement)
|
||||
self.S()
|
||||
|
@ -76,6 +76,7 @@ func New(id string, config config.HandlerConfigT) handler.Handler {
|
||||
t.Id = id
|
||||
t.ready = true
|
||||
t.dbh = database.NewDatabaseHandle()
|
||||
log.Printf("Handler SVEJ %d initialized", id)
|
||||
return t
|
||||
}
|
||||
|
||||
|
@ -111,6 +111,7 @@ func New(id string, config config.HandlerConfigT) handler.Handler {
|
||||
t.Id = id
|
||||
t.ready = true
|
||||
t.dbh = database.NewDatabaseHandle()
|
||||
log.Printf("Handler SVER %d initialized", id)
|
||||
return t
|
||||
}
|
||||
|
||||
|
55
src/udi/handlers/ttn/models/hottisGy21/hottisGY21.go
Normal file
55
src/udi/handlers/ttn/models/hottisGy21/hottisGY21.go
Normal file
@ -0,0 +1,55 @@
|
||||
package hottisGy21
|
||||
|
||||
import (
|
||||
//"log"
|
||||
"fmt"
|
||||
"bytes"
|
||||
"encoding/base64"
|
||||
"encoding/binary"
|
||||
"udi/database"
|
||||
)
|
||||
|
||||
type hottisGy21Values struct {
|
||||
Connected uint8
|
||||
Status uint8
|
||||
RawHumidity uint16
|
||||
RawTemperature uint16
|
||||
}
|
||||
|
||||
|
||||
func Parse(fPort int, _ []byte, frmPayload string, variables *map[string]database.VariableType, attributes *map[string]interface{}, _ *database.Device) error {
|
||||
if fPort != 2 {
|
||||
return fmt.Errorf("Unexpected fPort %d", fPort)
|
||||
}
|
||||
|
||||
b, err := base64.StdEncoding.DecodeString(frmPayload)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Unable to base64-decode payload: %v", err)
|
||||
}
|
||||
|
||||
var values hottisGy21Values
|
||||
err = binary.Read(bytes.NewReader(b), binary.LittleEndian, &values)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Unable to cast into struct: %v", err)
|
||||
}
|
||||
var temperature float32 = -46.85 + 175.72 * (float32(values.RawTemperature) / 65536.0)
|
||||
var humidity float32 = -6 + 125 * (float32(values.RawHumidity) / 65536.0);
|
||||
|
||||
// log.Printf("CO2: %f, Temp: %f, Hum: %f, Status: %d", co2concentration, temperature, humidity, values.Status)
|
||||
|
||||
(*variables)["Humidity"] = database.VariableType {
|
||||
Label: "Humidity",
|
||||
Variable: "Humidity",
|
||||
Unit: "%",
|
||||
Value: humidity,
|
||||
}
|
||||
(*variables)["Temperature"] = database.VariableType {
|
||||
Label: "Temperature",
|
||||
Variable: "Temperature",
|
||||
Unit: "°C",
|
||||
Value: temperature,
|
||||
}
|
||||
|
||||
(*attributes)["Status"] = values.Status
|
||||
return nil
|
||||
}
|
@ -2,7 +2,7 @@ package ttn
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
//"log"
|
||||
"log"
|
||||
"time"
|
||||
"encoding/json"
|
||||
"udi/config"
|
||||
@ -14,6 +14,7 @@ import (
|
||||
"udi/handlers/ttn/models/draginoLsn50"
|
||||
"udi/handlers/ttn/models/rawPayloadPrinter"
|
||||
"udi/handlers/ttn/models/hottisScd30"
|
||||
"udi/handlers/ttn/models/hottisGy21"
|
||||
"udi/handlers/ttn/models/hottisThreeWayThermometer"
|
||||
"udi/database"
|
||||
)
|
||||
@ -85,6 +86,7 @@ func New(id string, config config.HandlerConfigT) handler.Handler {
|
||||
}
|
||||
t.Id = id
|
||||
t.dbh = database.NewDatabaseHandle()
|
||||
log.Printf("Handler TTN %d initialized", id)
|
||||
return t
|
||||
}
|
||||
|
||||
@ -153,6 +155,8 @@ func (self *TTNHandler) Handle(message handler.MessageT) {
|
||||
parser = rawPayloadPrinter.Parse
|
||||
case "hottis-scd30":
|
||||
parser = hottisScd30.Parse
|
||||
case "hottis-gy21":
|
||||
parser = hottisGy21.Parse
|
||||
case "hottis-threeway-thermometer":
|
||||
parser = hottisThreeWayThermometer.Parse
|
||||
default:
|
||||
|
@ -55,6 +55,7 @@ func New(id string, config config.HandlerConfigT) handler.Handler {
|
||||
}
|
||||
t.Id = id
|
||||
t.dbh = database.NewDatabaseHandle()
|
||||
log.Printf("Handler Z2M %d initialized", id)
|
||||
return t
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user