Skip to content

Commit 98ba0d5

Browse files
authored
Merge pull request #16 from NETWAYS/fix/heartbeat
Fix heartbeat alerts no being created with status OK
2 parents 92be743 + 724a817 commit 98ba0d5

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

internal/api/listener.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,11 @@ func (l *Listener) manageIcingaService(ctx context.Context, payload WebhookPaylo
230230
// Get the Plugin Output from the first Annotation we find that has some data
231231
pluginOutput := l.generatePluginOutput(alert, exitCode)
232232

233+
// heartbeat alerts will use exit code OK since they always fire and the active check will set it to not OK
234+
if _, ok := alert.Labels["heartbeat"]; ok {
235+
exitCode = 0
236+
}
237+
233238
action := icinga2.Action{
234239
ExitStatus: exitCode,
235240
PluginOutput: pluginOutput,
@@ -247,8 +252,9 @@ func (l *Listener) manageIcingaService(ctx context.Context, payload WebhookPaylo
247252
return nil
248253
}
249254

255+
// updateOrCreateService either updates an existing service or creates a new service
250256
func (l *Listener) updateOrCreateService(ctx context.Context, serviceName, displayName string, exitCode int, alert Alert) (icinga2.Service, error) {
251-
heartbeatInterval := time.Duration(0)
257+
heartbeatInterval := time.Duration(-1)
252258

253259
if val, ok := alert.Labels["heartbeat"]; ok {
254260
if alert.Status == alertStatusResolved {
@@ -355,7 +361,7 @@ func (l *Listener) prepareService(serviceName string, displayName string, alert
355361
}
356362

357363
// Check if this is a heartbeat service and adjust serviceData accordingly
358-
if heartbeatInterval.Seconds() > 0.0 {
364+
if heartbeatInterval.Seconds() > 0 {
359365
// Set dummy text to message annotation on alert
360366
svc.Vars["dummy_text"] = alert.Annotations["message"]
361367
// Set exitStatus for missed heartbeat to Alert's severity

0 commit comments

Comments
 (0)