changes
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"mqtt": {
|
"mqtt": {
|
||||||
"broker": "mqtt://172.23.1.102:1883",
|
"broker": "mqtt://172.23.1.101:8883",
|
||||||
"username": "archiver",
|
"username": "archiver",
|
||||||
"tlsEnable": "true"
|
"tlsEnable": "true"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -14,9 +14,9 @@
|
|||||||
"cem/#"
|
"cem/#"
|
||||||
],
|
],
|
||||||
"syslog": {
|
"syslog": {
|
||||||
"enable": "false",
|
"enable": "true",
|
||||||
"network": "udp",
|
"network": "udp",
|
||||||
"server": "syslog-server:514",
|
"server": "172.20.0.10:514",
|
||||||
"facility": "local0",
|
"facility": "local0",
|
||||||
"severity": "info",
|
"severity": "info",
|
||||||
"tag": "mqtt-archiver"
|
"tag": "mqtt-archiver"
|
||||||
|
|||||||
@@ -13,14 +13,16 @@ func InitSyslog() {
|
|||||||
if config.Config.Syslog.Enable == "true" {
|
if config.Config.Syslog.Enable == "true" {
|
||||||
// Parse facility
|
// Parse facility
|
||||||
facility := parseFacility(config.Config.Syslog.Facility)
|
facility := parseFacility(config.Config.Syslog.Facility)
|
||||||
|
|
||||||
// Parse severity
|
// Parse severity
|
||||||
severity := parseSeverity(config.Config.Syslog.Severity)
|
severity := parseSeverity(config.Config.Syslog.Severity)
|
||||||
|
|
||||||
// Combine to priority
|
// Combine to priority
|
||||||
priority := facility | severity
|
priority := facility | severity
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
|
// Connect to remote syslog server
|
||||||
syslogWriter, err = syslog.Dial(
|
syslogWriter, err = syslog.Dial(
|
||||||
config.Config.Syslog.Network,
|
config.Config.Syslog.Network,
|
||||||
config.Config.Syslog.Server,
|
config.Config.Syslog.Server,
|
||||||
@@ -41,7 +43,7 @@ func WriteSyslog(message Message) {
|
|||||||
log.Printf("Failed to marshal message to JSON: %v", err)
|
log.Printf("Failed to marshal message to JSON: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send to syslog based on configured severity
|
// Send to syslog based on configured severity
|
||||||
switch config.Config.Syslog.Severity {
|
switch config.Config.Syslog.Severity {
|
||||||
case "emerg":
|
case "emerg":
|
||||||
@@ -89,7 +91,7 @@ func parseFacility(facility string) syslog.Priority {
|
|||||||
"local6": syslog.LOG_LOCAL6,
|
"local6": syslog.LOG_LOCAL6,
|
||||||
"local7": syslog.LOG_LOCAL7,
|
"local7": syslog.LOG_LOCAL7,
|
||||||
}
|
}
|
||||||
|
|
||||||
if f, ok := facilities[facility]; ok {
|
if f, ok := facilities[facility]; ok {
|
||||||
return f
|
return f
|
||||||
}
|
}
|
||||||
@@ -107,7 +109,7 @@ func parseSeverity(severity string) syslog.Priority {
|
|||||||
"info": syslog.LOG_INFO,
|
"info": syslog.LOG_INFO,
|
||||||
"debug": syslog.LOG_DEBUG,
|
"debug": syslog.LOG_DEBUG,
|
||||||
}
|
}
|
||||||
|
|
||||||
if s, ok := severities[severity]; ok {
|
if s, ok := severities[severity]; ok {
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ type ConfigT struct {
|
|||||||
Mqtt struct {
|
Mqtt struct {
|
||||||
Broker string `json:"broker"`
|
Broker string `json:"broker"`
|
||||||
Username string `json:"username"`
|
Username string `json:"username"`
|
||||||
Password string
|
Password string `json:"password"`
|
||||||
TlsEnable string `json:"tlsEnable"`
|
TlsEnable string `json:"tlsEnable"`
|
||||||
} `json:"mqtt"`
|
} `json:"mqtt"`
|
||||||
IncludeTopics []string `json:"includeTopics"`
|
IncludeTopics []string `json:"includeTopics"`
|
||||||
@@ -37,5 +37,8 @@ func LoadConfiguration() {
|
|||||||
log.Fatalf("Unable to parse configuration: %s", err)
|
log.Fatalf("Unable to parse configuration: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
Config.Mqtt.Password = os.Getenv("MQTT_PASSWORD")
|
// Load password from environment variable only if not set in config
|
||||||
|
if Config.Mqtt.Password == "" {
|
||||||
|
Config.Mqtt.Password = os.Getenv("MQTT_PASSWORD")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user