reloader
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful

This commit is contained in:
2023-12-05 17:09:22 +01:00
parent a5209dad8f
commit ff659b648c
2 changed files with 20 additions and 11 deletions

View File

@ -18,6 +18,8 @@ metadata:
namespace: udi
labels:
app: udi
annotations:
secret.reloader.stakater.com/reload: "udi-conf,udi-db-cred"
spec:
replicas: 1
selector:

View File

@ -24,6 +24,7 @@ type SingleValueExtractorHandler struct {
const TOPIC_SEL = "topic"
const PAYLOAD_SEL = "payload"
const PAYLOAD_FULL_SEL = "payload-full"
const CONSTANT_SEL = "constant"
type localConfig struct {
@ -76,18 +77,20 @@ func NewSveHandler(config config.HandlerConfigT) handler.Handler {
// empty device is valid
localConfig.device = config.Attributes["device"]
if config.Attributes["valueFrom"] != TOPIC_SEL && config.Attributes["valueFrom"] != PAYLOAD_SEL {
if config.Attributes["valueFrom"] != TOPIC_SEL && config.Attributes["valueFrom"] != PAYLOAD_SEL && config.Attributes["valueFrom"] != PAYLOAD_FULL_SEL {
log.Printf("Error: invalid value %s for valueFrom", config.Attributes["valueFrom"])
return t
}
localConfig.valueFrom = config.Attributes["valueFrom"]
valuePart, err2 := strconv.Atoi(config.Attributes["valuePart"])
if err2 != nil {
log.Printf("Error: unable to convert valuePart to number: %s", err2)
return t
if config.Attributes["valueFrom"] != PAYLOAD_FULL_SEL {
valuePart, err2 := strconv.Atoi(config.Attributes["valuePart"])
if err2 != nil {
log.Printf("Error: unable to convert valuePart to number: %s", err2)
return t
}
localConfig.valuePart = valuePart
}
localConfig.valuePart = valuePart
if config.Attributes["unitFrom"] != TOPIC_SEL && config.Attributes["unitFrom"] != PAYLOAD_SEL && config.Attributes["unitFrom"] != CONSTANT_SEL {
log.Printf("Error: invalid value %s for unitFrom", config.Attributes["unitFrom"])
@ -95,12 +98,14 @@ func NewSveHandler(config config.HandlerConfigT) handler.Handler {
}
localConfig.unitFrom = config.Attributes["unitFrom"]
unitPart, err3 := strconv.Atoi(config.Attributes["unitPart"])
if err3 != nil {
log.Printf("Error: unable to convert unitPart to number: %s", err3)
return t
if config.Attributes["unitFrom"] != CONSTANT_SEL {
unitPart, err3 := strconv.Atoi(config.Attributes["unitPart"])
if err3 != nil {
log.Printf("Error: unable to convert unitPart to number: %s", err3)
return t
}
localConfig.unitPart = unitPart
}
localConfig.unitPart = unitPart
// empty unit is valid
localConfig.unit = config.Attributes["unit"]
@ -183,6 +188,8 @@ func (self *SingleValueExtractorHandler) Handle(message handler.MessageT) {
return
}
variable.Value = payloadMatches[self.config.valuePart]
case PAYLOAD_FULL_SEL:
variable.Value = message.Payload
}
switch self.config.unitFrom {