Skip to content

Commit

Permalink
new reloadConfig function
Browse files Browse the repository at this point in the history
  • Loading branch information
dmachard committed Oct 24, 2023
1 parent a650c77 commit e6a49f7
Show file tree
Hide file tree
Showing 34 changed files with 318 additions and 5 deletions.
10 changes: 10 additions & 0 deletions collectors/dnstap.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,16 @@ func (c *Dnstap) ReadConfig() {
}
}

func (c *Dnstap) ReloadConfig(config *dnsutils.Config) {
c.LogInfo("reload config...")

// save the new config
c.config = config

// read again
c.ReadConfig()
}

func (c *Dnstap) LogInfo(msg string, v ...interface{}) {
c.logger.Info("["+c.name+"] collector=dnstap - "+msg, v...)
}
Expand Down
10 changes: 10 additions & 0 deletions collectors/dnstap_proxifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,16 @@ func (c *DnstapProxifier) ReadConfig() {
c.sockPath = c.config.Collectors.DnstapProxifier.SockPath
}

func (c *DnstapProxifier) ReloadConfig(config *dnsutils.Config) {
c.LogInfo("reload config...")

// save the new config
c.config = config

// read again
c.ReadConfig()
}

func (c *DnstapProxifier) LogInfo(msg string, v ...interface{}) {
c.logger.Info("["+c.name+"] collector=dnstaprelay - "+msg, v...)
}
Expand Down
10 changes: 10 additions & 0 deletions collectors/file_ingestor.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,16 @@ func (c *FileIngestor) ReadConfig() {
c.config.Collectors.FileIngestor.WatchMode)
}

func (c *FileIngestor) ReloadConfig(config *dnsutils.Config) {
c.LogInfo("reload config...")

// save the new config
c.config = config

// read again
c.ReadConfig()
}

func (c *FileIngestor) LogInfo(msg string, v ...interface{}) {
c.logger.Info("["+c.name+"] collector=fileingestor - "+msg, v...)
}
Expand Down
10 changes: 10 additions & 0 deletions collectors/file_tail.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ func (c *Tail) ReadConfig() {
//tbc
}

func (c *Tail) ReloadConfig(config *dnsutils.Config) {
c.LogInfo("reload config...")

// save the new config
c.config = config

// read again
c.ReadConfig()
}

func (c *Tail) LogInfo(msg string, v ...interface{}) {
c.logger.Info("["+c.name+"] collector=tail - "+msg, v...)
}
Expand Down
10 changes: 10 additions & 0 deletions collectors/powerdns.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,16 @@ func (c *ProtobufPowerDNS) ReadConfig() {
}
}

func (c *ProtobufPowerDNS) ReloadConfig(config *dnsutils.Config) {
c.LogInfo("reload config...")

// save the new config
c.config = config

// read again
c.ReadConfig()
}

func (c *ProtobufPowerDNS) LogInfo(msg string, v ...interface{}) {
c.logger.Info("["+c.name+"] collector=powerdns - "+msg, v...)
}
Expand Down
10 changes: 10 additions & 0 deletions collectors/sniffer_afpacket.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,16 @@ func (c *AfpacketSniffer) ReadConfig() {
c.device = c.config.Collectors.AfpacketLiveCapture.Device
}

func (c *AfpacketSniffer) ReloadConfig(config *dnsutils.Config) {
c.LogInfo("reload config...")

// save the new config
c.config = config

// read again
c.ReadConfig()
}

func (c *AfpacketSniffer) Channel() chan dnsutils.DnsMessage {
return nil
}
Expand Down
10 changes: 10 additions & 0 deletions collectors/sniffer_afpacket_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ func (c *AfpacketSniffer) Loggers() []chan dnsutils.DnsMessage {
func (c *AfpacketSniffer) ReadConfig() {
}

func (c *AfpacketSniffer) ReloadConfig(config *dnsutils.Config) {
c.LogInfo("reload config...")

// save the new config
c.config = config

// read again
c.ReadConfig()
}

func (c *AfpacketSniffer) Channel() chan dnsutils.DnsMessage {
return nil
}
Expand Down
10 changes: 10 additions & 0 deletions collectors/sniffer_afpacket_freebsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ func (c *AfpacketSniffer) Loggers() []chan dnsutils.DnsMessage {
func (c *AfpacketSniffer) ReadConfig() {
}

func (c *AfpacketSniffer) ReloadConfig(config *dnsutils.Config) {
c.LogInfo("reload config...")

// save the new config
c.config = config

// read again
c.ReadConfig()
}

func (c *AfpacketSniffer) Channel() chan dnsutils.DnsMessage {
return nil
}
Expand Down
10 changes: 10 additions & 0 deletions collectors/sniffer_afpacket_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ func (c *AfpacketSniffer) Loggers() []chan dnsutils.DnsMessage {
func (c *AfpacketSniffer) ReadConfig() {
}

func (c *AfpacketSniffer) ReloadConfig(config *dnsutils.Config) {
c.LogInfo("reload config...")

// save the new config
c.config = config

// read again
c.ReadConfig()
}

func (c *AfpacketSniffer) Channel() chan dnsutils.DnsMessage {
return nil
}
Expand Down
10 changes: 10 additions & 0 deletions collectors/sniffer_xdp.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,16 @@ func (c *XdpSniffer) ReadConfig() {
c.identity = c.config.GetServerIdentity()
}

func (c *XdpSniffer) ReloadConfig(config *dnsutils.Config) {
c.LogInfo("reload config...")

// save the new config
c.config = config

// read again
c.ReadConfig()
}

func (c *XdpSniffer) Channel() chan dnsutils.DnsMessage {
return nil
}
Expand Down
10 changes: 10 additions & 0 deletions collectors/sniffer_xdp_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ func (c *XdpSniffer) ReadConfig() {
c.identity = c.config.GetServerIdentity()
}

func (c *XdpSniffer) ReloadConfig(config *dnsutils.Config) {
c.LogInfo("reload config...")

// save the new config
c.config = config

// read again
c.ReadConfig()
}

func (c *XdpSniffer) Channel() chan dnsutils.DnsMessage {
return nil
}
Expand Down
10 changes: 10 additions & 0 deletions collectors/tzsp.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,16 @@ func (c *TzspSniffer) ReadConfig() {
// TODO: Implement
}

func (c *TzspSniffer) ReloadConfig(config *dnsutils.Config) {
c.LogInfo("reload config...")

// save the new config
c.config = config

// read again
c.ReadConfig()
}

func (c *TzspSniffer) Listen() error {
c.logger.Info("running in background...")

Expand Down
10 changes: 10 additions & 0 deletions collectors/tzsp_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ func (c *TzspSniffer) Loggers() []chan dnsutils.DnsMessage {
func (c *TzspSniffer) ReadConfig() {
}

func (c *TzspSniffer) ReloadConfig(config *dnsutils.Config) {
c.LogInfo("reload config...")

// save the new config
c.config = config

// read again
c.ReadConfig()
}

func (c *TzspSniffer) Channel() chan dnsutils.DnsMessage {
return nil
}
Expand Down
10 changes: 10 additions & 0 deletions collectors/tzsp_freebsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ func (c *TzspSniffer) Loggers() []chan dnsutils.DnsMessage {
func (c *TzspSniffer) ReadConfig() {
}

func (c *TzspSniffer) ReloadConfig(config *dnsutils.Config) {
c.LogInfo("reload config...")

// save the new config
c.config = config

// read again
c.ReadConfig()
}

func (c *TzspSniffer) Channel() chan dnsutils.DnsMessage {
return nil
}
Expand Down
10 changes: 10 additions & 0 deletions collectors/tzsp_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ func (c *TzspSniffer) Loggers() []chan dnsutils.DnsMessage {
func (c *TzspSniffer) ReadConfig() {
}

func (c *TzspSniffer) ReloadConfig(config *dnsutils.Config) {
c.LogInfo("reload config...")

// save the new config
c.config = config

// read again
c.ReadConfig()
}

func (c *TzspSniffer) Channel() chan dnsutils.DnsMessage {
return nil
}
Expand Down
10 changes: 5 additions & 5 deletions dnscollector.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ func main() {
for {
select {
case <-sigHUP:
logger.Info("main - sig hup - reloading config...")
logger.Info("main - SIGHUP received")

// read config
err := dnsutils.ReloadConfig(configPath, config)
Expand All @@ -303,18 +303,18 @@ func main() {
InitLogger(logger, config)

for _, output := range config.Multiplexer.Loggers {
_ = GetItemConfig("loggers", config, output)
newcfg := GetItemConfig("loggers", config, output)
if _, ok := mapLoggers[output.Name]; ok {
fmt.Println(output.Name)
mapLoggers[output.Name].ReloadConfig(newcfg)
} else {
logger.Info("main - reload config logger=%v doest not exist", output.Name)
}
}

for _, input := range config.Multiplexer.Collectors {
_ = GetItemConfig("collectors", config, input)
newcfg := GetItemConfig("collectors", config, input)
if _, ok := mapCollectors[input.Name]; ok {
fmt.Println(input.Name)
mapCollectors[input.Name].ReloadConfig(newcfg)
} else {
logger.Info("main - reload config collector=%v doest not exist", input.Name)
}
Expand Down
1 change: 1 addition & 0 deletions dnsutils/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ type Worker interface {
Run()
Channel() chan DnsMessage
ReadConfig()
ReloadConfig(config *Config)
}
10 changes: 10 additions & 0 deletions loggers/dnstapclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@ func (o *DnstapSender) ReadConfig() {
}
}

func (o *DnstapSender) ReloadConfig(config *dnsutils.Config) {
o.LogInfo("reload config...")

// save the new config
o.config = config

// read again
o.ReadConfig()
}

func (o *DnstapSender) LogInfo(msg string, v ...interface{}) {
o.logger.Info("["+o.name+"] logger=dnstap - "+msg, v...)
}
Expand Down
10 changes: 10 additions & 0 deletions loggers/elasticsearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,16 @@ func (c *ElasticSearchClient) ReadConfig() {
c.bulkUrl = u.String()
}

func (o *ElasticSearchClient) ReloadConfig(config *dnsutils.Config) {
o.LogInfo("reload config...")

// save the new config
o.config = config

// read again
o.ReadConfig()
}

func (o *ElasticSearchClient) Channel() chan dnsutils.DnsMessage {
return o.inputChan
}
Expand Down
2 changes: 2 additions & 0 deletions loggers/fakelogger.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ func (c *FakeLogger) SetLoggers(loggers []dnsutils.Worker) {}

func (o *FakeLogger) ReadConfig() {}

func (o *FakeLogger) ReloadConfig(config *dnsutils.Config) {}

func (o *FakeLogger) Stop() {}

func (o *FakeLogger) Channel() chan dnsutils.DnsMessage {
Expand Down
10 changes: 10 additions & 0 deletions loggers/falco.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@ func (c *FalcoClient) ReadConfig() {
c.url = c.config.Loggers.FalcoClient.URL
}

func (c *FalcoClient) ReloadConfig(config *dnsutils.Config) {
c.LogInfo("reload config...")

// save the new config
c.config = config

// read again
c.ReadConfig()
}

func (f *FalcoClient) Channel() chan dnsutils.DnsMessage {
return f.inputChan
}
Expand Down
10 changes: 10 additions & 0 deletions loggers/fluentd.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ func (o *FluentdClient) ReadConfig() {
}
}

func (o *FluentdClient) ReloadConfig(config *dnsutils.Config) {
o.LogInfo("reload config...")

// save the new config
o.config = config

// read again
o.ReadConfig()
}

func (o *FluentdClient) LogInfo(msg string, v ...interface{}) {
o.logger.Info("["+o.name+"] logger=fluentd - "+msg, v...)
}
Expand Down
10 changes: 10 additions & 0 deletions loggers/influxdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@ func (o *InfluxDBClient) ReadConfig() {
}
}

func (o *InfluxDBClient) ReloadConfig(config *dnsutils.Config) {
o.LogInfo("reload config...")

// save the new config
o.config = config

// read again
o.ReadConfig()
}

func (o *InfluxDBClient) LogInfo(msg string, v ...interface{}) {
o.logger.Info("["+o.name+"] logger=influxdb - "+msg, v...)
}
Expand Down
Loading

0 comments on commit e6a49f7

Please sign in to comment.