From 64583e37108b66c84b32a363817ccf569bc7c2e7 Mon Sep 17 00:00:00 2001 From: cubicroot Date: Thu, 21 Apr 2022 18:52:57 +0200 Subject: [PATCH] Handle lables and annotations --- config.example.yml | 4 ++-- internal/api/alertmanager/handler.go | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/config.example.yml b/config.example.yml index 3c5ccc2..526457e 100644 --- a/config.example.yml +++ b/config.example.yml @@ -63,7 +63,7 @@ formatting: # This settings are only relevant if you want to use PushBits with alertmanager alertmanager: - # The name of the entry in the alerts annotations that should be used for the title + # The name of the entry in the alerts annotations or lables that should be used for the title annotationtitle: title - # The name of the entry in the alerts annotations that should be used for the message + # The name of the entry in the alerts annotations or labels that should be used for the message annotationmessage: message diff --git a/internal/api/alertmanager/handler.go b/internal/api/alertmanager/handler.go index 07436b8..cb634a9 100644 --- a/internal/api/alertmanager/handler.go +++ b/internal/api/alertmanager/handler.go @@ -95,14 +95,16 @@ func (alert *alert) ToNotification(titleAnnotation, messageAnnotation string) mo if titleString, ok := alert.Annotiations[titleAnnotation]; ok { title.WriteString(titleString) + } else if titleString, ok := alert.Labels[titleAnnotation]; ok { + title.WriteString(titleString) } else { title.WriteString("Unknown Title") } - title.WriteString(" - ") - title.WriteString(alert.StartsAt) if messageString, ok := alert.Annotiations[messageAnnotation]; ok { message.WriteString(messageString) + } else if messageString, ok := alert.Labels[messageAnnotation]; ok { + message.WriteString(messageString) } else { message.WriteString("Unknown Message") }