Skip to content

Commit

Permalink
* some cleanup of the status reporting infrastructure
Browse files Browse the repository at this point in the history
  • Loading branch information
johanix committed Sep 13, 2024
1 parent 50c287f commit f9af353
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 61 deletions.
2 changes: 1 addition & 1 deletion apihandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func APIcommand(conf *Config) func(w http.ResponseWriter, r *http.Request) {

conf.Internal.ComponentStatusCh <- tapir.ComponentStatusUpdate{
Component: "status",
Status: "status",
Status: tapir.StatusReport,
Response: rt,
}

Expand Down
6 changes: 1 addition & 5 deletions config.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Johan Stenstam, [email protected]
* Copyright (c) 2024Johan Stenstam, [email protected]
*/

package main
Expand Down Expand Up @@ -183,7 +183,3 @@ func ValidateBySection(config *Config, configsections map[string]interface{}, cf
}
return nil
}

func (td *TemData) ProcessTapirGlobalConfig(tpkg tapir.TapirMsg) {
log.Printf("TapirProcessGlobalConfig: %+v", tpkg)
}
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ func main() {
}
}

go td.ConfigUpdater(&Gconfig, stopch) // Note that ConfigUpdater must as early as possible
go td.StatusUpdater(&Gconfig, stopch) // Note that StatusUpdater must as early as possible
go td.RefreshEngine(&Gconfig, stopch)

Expand Down Expand Up @@ -235,7 +236,7 @@ func main() {

statusch <- tapir.ComponentStatusUpdate{
Component: "main-boot",
Status: "ok",
Status: tapir.StatusOK,
Msg: "TAPIR Policy Processor started",
TimeStamp: time.Now(),
}
Expand Down
46 changes: 23 additions & 23 deletions refreshengine.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Johan Stenstam, [email protected]
* Copyright (c) 2024 Johan Stenstam, [email protected]
*/
package main

Expand Down Expand Up @@ -102,41 +102,41 @@ func (td *TemData) RefreshEngine(conf *Config, stopch chan struct{}) {
_, err := td.ProcessTapirUpdate(tm)
if err != nil {
Gconfig.Internal.ComponentStatusCh <- tapir.ComponentStatusUpdate{
Status: "fail",
Status: tapir.StatusFail,
Component: "tapir-observation",
Msg: fmt.Sprintf("ProcessTapirUpdate error: %v", err),
}
log.Printf("RefreshEngine: Error from ProcessTapirUpdate(): %v", err)
}
Gconfig.Internal.ComponentStatusCh <- tapir.ComponentStatusUpdate{
Status: "ok",
Status: tapir.StatusOK,
Component: "tapir-observation",
Msg: fmt.Sprintf("ProcessTapirUpdate: MQTT observation message received"),
}
log.Printf("RefreshEngine: Tapir Observation update evaluated.")

case "global-config":
if !strings.HasSuffix(tpkg.Topic, "config") {
log.Printf("RefreshEngine: received global-config message on wrong topic: %s. Ignored", tpkg.Topic)
Gconfig.Internal.ComponentStatusCh <- tapir.ComponentStatusUpdate{
Status: "fail",
Component: "mqtt-config",
Msg: fmt.Sprintf("RefreshEngine: received global-config message on wrong topic: %s. Ignored", tpkg.Topic),
}
continue
}
td.ProcessTapirGlobalConfig(tm)
log.Printf("RefreshEngine: Tapir Global Config evaluated.")
Gconfig.Internal.ComponentStatusCh <- tapir.ComponentStatusUpdate{
Status: "ok",
Component: "mqtt-config",
Msg: fmt.Sprintf("RefreshEngine: Tapir Global Config evaluated."),
}
// case "global-config":
// if !strings.HasSuffix(tpkg.Topic, "config") {
// log.Printf("RefreshEngine: received global-config message on wrong topic: %s. Ignored", tpkg.Topic)
// Gconfig.Internal.ComponentStatusCh <- tapir.ComponentStatusUpdate{
// Status: "fail",
// Component: "mqtt-config",
// Msg: fmt.Sprintf("RefreshEngine: received global-config message on wrong topic: %s. Ignored", tpkg.Topic),
// }
// continue
// }
// td.ProcessTapirGlobalConfig(tm)
// log.Printf("RefreshEngine: Tapir Global Config evaluated.")
// Gconfig.Internal.ComponentStatusCh <- tapir.ComponentStatusUpdate{
// Status: "ok",
// Component: "mqtt-config",
// Msg: fmt.Sprintf("RefreshEngine: Tapir Global Config evaluated."),
// }

default:
log.Printf("RefreshEngine: Tapir Message: unknown msg type: %s", tm.MsgType)
Gconfig.Internal.ComponentStatusCh <- tapir.ComponentStatusUpdate{
Status: "fail",
Status: tapir.StatusFail,
Component: "mqtt-unknown",
Msg: fmt.Sprintf("RefreshEngine: Tapir Message: unknown msg type: %s", tm.MsgType),
}
Expand Down Expand Up @@ -446,7 +446,7 @@ func (td *TemData) NotifyDownstreams() error {
dest := net.JoinHostPort(d.Address, strconv.Itoa(d.Port))
csu := tapir.ComponentStatusUpdate{
Component: "downstream-notify",
Status: "fail",
Status: tapir.StatusFail,
Msg: fmt.Sprintf("Notifying downstream %s about new SOA serial (%d) for RPZ zone %s", dest, td.Rpz.Axfr.SOA.Serial, td.Rpz.ZoneName),
TimeStamp: time.Now(),
}
Expand Down Expand Up @@ -478,7 +478,7 @@ func (td *TemData) NotifyDownstreams() error {
td.Logger.Println(csu.Msg)
continue
}
csu.Status = "success"
csu.Status = tapir.StatusOK
csu.Msg = fmt.Sprintf("Downstream %s responded correctly to NOTIFY(%s) about new SOA serial (%d)", dest, td.Rpz.ZoneName, td.Rpz.Axfr.SOA.Serial)
Gconfig.Internal.ComponentStatusCh <- csu
td.Logger.Println(csu.Msg)
Expand Down
20 changes: 1 addition & 19 deletions sources.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) DNS TAPIR
* Copyright (c) 2024 Johan Stenstam, [email protected]
*/
package main

Expand Down Expand Up @@ -172,24 +172,6 @@ func (td *TemData) ParseSourcesNG() error {
td.Logger.Printf("ParseSourcesNG: MQTT Engine already created")
}

// Ensure that the MQTT Engine listens on the DNS TAPIR config topic
cfgtopic := viper.GetString("tapir.config.topic")
if cfgtopic != "" {
if td.Debug {
td.Logger.Printf("ParseSourcesNG: Fetching MQTT validator key for topic %s", cfgtopic)
}
valkey, err := tapir.FetchMqttValidatorKey(cfgtopic, viper.GetString("tapir.config.validatorkey"))
if err != nil {
TEMExiter("Error fetching MQTT validator key for topic %s: %v", cfgtopic, err)
}
// err = td.MqttEngine.AddTopic(cfgtopic, nil, valkey)
topicdata, err := td.MqttEngine.SubToTopic(cfgtopic, valkey, nil, "struct", true) // XXX: should have a channel to the config processor
if err != nil {
TEMExiter("Error adding topic %s to MQTT Engine: %v", cfgtopic, err)
}
td.Logger.Printf("ParseSourcesNG: Topic data for topic %s: %+v", cfgtopic, topicdata)
}

for name, src := range srcs {
if !*src.Active {
td.Logger.Printf("*** ParseSourcesNG: Source \"%s\" is not active. Ignored.", name)
Expand Down
20 changes: 10 additions & 10 deletions statusupdater.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (td *TemData) StatusUpdater(conf *Config, stopch chan struct{}) {
case csu = <-td.ComponentStatusCh:
log.Printf("StatusUpdater: got status update message: %v", csu)
switch csu.Status {
case "fail", "warn", "ok":
case tapir.StatusFail, tapir.StatusWarn, tapir.StatusOK:
log.Printf("StatusUpdater: status failure: %s", csu.Msg)
var sur tapir.StatusUpdaterResponse
switch {
Expand All @@ -96,34 +96,34 @@ func (td *TemData) StatusUpdater(conf *Config, stopch chan struct{}) {
comp.Status = csu.Status
comp.Msg = csu.Msg
switch csu.Status {
case "fail":
case tapir.StatusFail:
comp.NumFails++
comp.LastFail = csu.TimeStamp
comp.ErrorMsg = csu.Msg
case "warn":
comp.NumWarns++
case tapir.StatusWarn:
comp.NumWarnings++
comp.LastWarn = csu.TimeStamp
comp.ErrorMsg = csu.Msg
case "ok":
comp.WarningMsg = csu.Msg
case tapir.StatusOK:
comp.NumFails = 0
comp.NumWarns = 0
comp.NumWarnings = 0
comp.LastSuccess = csu.TimeStamp
}
s.ComponentStatus[csu.Component] = comp
dirty = true
sur.Msg = fmt.Sprintf("StatusUpdater: %s report for known component: %s", csu.Status, csu.Component)
default:
log.Printf("StatusUpdater: %s report for unknown component: %s", csu.Status, csu.Component)
log.Printf("StatusUpdater: %s report for unknown component: %s", tapir.StatusToString[csu.Status], csu.Component)
sur.Error = true
sur.ErrorMsg = fmt.Sprintf("StatusUpdater: %s report for unknown component: %s", csu.Status, csu.Component)
sur.ErrorMsg = fmt.Sprintf("StatusUpdater: %s report for unknown component: %s", tapir.StatusToString[csu.Status], csu.Component)
sur.Msg = fmt.Sprintf("StatusUpdater: known components are: %v", known_components)
}

if csu.Response != nil {
csu.Response <- sur
}

case "status":
case tapir.StatusReport:
log.Printf("StatusUpdater: request for status report. Response: %v", csu.Response)
if csu.Response != nil {
csu.Response <- tapir.StatusUpdaterResponse{
Expand Down
4 changes: 2 additions & 2 deletions xfr.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ func (td *TemData) RpzIxfrOut(w dns.ResponseWriter, r *dns.Msg) (uint32, int, er
td.Logger.Printf("Error from transfer.Out(): %v", err)
td.ComponentStatusCh <- tapir.ComponentStatusUpdate{
Component: "rpz-ixfr",
Status: "fail",
Status: tapir.StatusFail,
Msg: fmt.Sprintf("Error from transfer.Out(): %v", err),
TimeStamp: time.Now(),
}
Expand Down Expand Up @@ -315,7 +315,7 @@ func (td *TemData) RpzIxfrOut(w dns.ResponseWriter, r *dns.Msg) (uint32, int, er

td.ComponentStatusCh <- tapir.ComponentStatusUpdate{
Component: "rpz-ixfr",
Status: "ok",
Status: tapir.StatusOK,
TimeStamp: time.Now(),
}

Expand Down

0 comments on commit f9af353

Please sign in to comment.