my own modifications, part 1

This commit is contained in:
2024-01-25 12:35:27 +01:00
parent b68e929c57
commit 5b77a6a059
20 changed files with 402 additions and 543 deletions

47
src/smq/config/config.go Normal file
View File

@ -0,0 +1,47 @@
package config
import (
"encoding/json"
"os"
"log"
)
type OIDTopicObject struct {
OID string `json:"oid"`
Label string `json:"label"`
Diff string `json:"diff"`
}
// SNMPEndpointObject is the SNMP Endpoint definition
type SNMPEndpointObject struct {
Endpoint string `json:"endpoint"`
Label string `json:"label"`
Community string `json:"community"`
OIDTopics []OIDTopicObject `json:"oidTopics"`
}
type MQTTConfigObject struct {
Broker string `json:"broker"`
Username string `json:"username"`
Password string `json:"password"`
TlsEnable string `json:"tlsEnable"`
Topic string `json:"topic"`
}
type ConfigObject struct {
Mqtt MQTTConfigObject `json:"mqtt"`
Interval int `json:"interval"`
SNMPEndpoints []SNMPEndpointObject `json:"snmpEndpoints"`
}
var Config ConfigObject
func LoadConfiguration() {
cfg := os.Getenv("SNMP_MQTT_CONF")
log.Printf("cfg: %s", cfg)
err := json.Unmarshal([]byte(cfg), &Config)
if err != nil {
log.Fatalf("Unable to parse configuration: %v", err)
}
}