Skip to content

Commit

Permalink
fix: notifications would still happen even if not in config
Browse files Browse the repository at this point in the history
  • Loading branch information
whiskeyjimbo committed Dec 26, 2024
1 parent 47a2961 commit f895413
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,15 @@ func main() {
logger.Fatal(err)
}

notifier := notifications.NewLogNotifier(logger)
if err := notifier.Initialize(ctx); err != nil {
logger.Fatal(err)
var notifier notifications.Notifier
for _, n := range config.Notifications {
if n.Type == string(notifications.LogNotification) {
notifier = notifications.NewLogNotifier(logger)
if err := notifier.Initialize(ctx); err != nil {
logger.Fatal(err)
}
break
}
}

metrics.StartMetricsServer(logger)
Expand Down Expand Up @@ -131,15 +137,18 @@ func monitorHost(
"error", ruleResult.Error,
)
} else if ruleResult.Satisfied {
notifier.SendNotification(ctx, notifications.Notification{
Message: fmt.Sprintf("Rule condition met: %s", rule.Name),
Level: notifications.WarningLevel,
Tags: hostTags,
Host: host,
Port: checkConfig.Port,
Protocol: string(checkConfig.Protocol),
})
if notifier != nil {
notifier.SendNotification(ctx, notifications.Notification{
Message: fmt.Sprintf("Rule condition met: %s", rule.Name),
Level: notifications.WarningLevel,
Tags: hostTags,
Host: host,
Port: checkConfig.Port,
Protocol: string(checkConfig.Protocol),
})
}
}
lastRuleEval[rule.Name] = time.Now()
}

sleepUntilNextCheck(interval, time.Since(checkStart))
Expand Down

0 comments on commit f895413

Please sign in to comment.