Summary and environment type are hoisted into discord embed field name
This commit is contained in:
@@ -9,6 +9,12 @@ import (
|
||||
"github.com/specklesystems/alertmanager-discord/pkg/discord"
|
||||
)
|
||||
|
||||
const (
|
||||
keySummary = "summary"
|
||||
keyEnvironmentType = "source_environment_type"
|
||||
keyEnvironmentName = "source_environment_name"
|
||||
)
|
||||
|
||||
func TranslateAlertManagerToDiscord(status string, amo *alertmanager.Out, alerts []alertmanager.Alert) discord.Out {
|
||||
DO := discord.Out{}
|
||||
|
||||
@@ -31,6 +37,11 @@ func TranslateAlertManagerToDiscord(status string, amo *alertmanager.Out, alerts
|
||||
}
|
||||
|
||||
for _, alert := range alerts {
|
||||
fieldName := fmt.Sprintf("[%s/%s] Alert details", alert.Labels[keyEnvironmentType], alert.Labels[keyEnvironmentName])
|
||||
if summary, ok := alert.Annotations[keySummary]; ok {
|
||||
fieldName = fmt.Sprintf("[%s/%s] %s", alert.Labels[keyEnvironmentType], alert.Labels[keyEnvironmentName], summary)
|
||||
}
|
||||
|
||||
var details strings.Builder
|
||||
details.WriteString("Annotations:\n")
|
||||
|
||||
@@ -42,6 +53,10 @@ func TranslateAlertManagerToDiscord(status string, amo *alertmanager.Out, alerts
|
||||
sort.Strings(annotationKeys)
|
||||
|
||||
for _, key := range annotationKeys {
|
||||
if key == keySummary {
|
||||
// if there is a summary, it is already the field name so no need to repeat it
|
||||
continue
|
||||
}
|
||||
details.WriteString(fmt.Sprintf("%s: %s\n", key, alert.Annotations[key]))
|
||||
}
|
||||
|
||||
@@ -55,11 +70,15 @@ func TranslateAlertManagerToDiscord(status string, amo *alertmanager.Out, alerts
|
||||
sort.Strings(labelKeys)
|
||||
|
||||
for _, key := range labelKeys {
|
||||
if key == keyEnvironmentName || key == keyEnvironmentType {
|
||||
// if these keys exist, we have already added them to the field name
|
||||
continue
|
||||
}
|
||||
details.WriteString(fmt.Sprintf(" %s: %s\n", key, alert.Labels[key]))
|
||||
}
|
||||
|
||||
RichEmbed.Fields = append(RichEmbed.Fields, discord.EmbedField{
|
||||
Name: "Alert details",
|
||||
Name: fieldName,
|
||||
Value: details.String(),
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user