diff --git a/README.md b/README.md index 87211f1..5f611ff 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,11 @@ labels { } } +# Set tags for resolved alerts +resolved { + tags "resolved,partying_face" +} + ntfy { # URL of the ntfy topic - required topic https://ntfy.sh/alertmanager-alerts diff --git a/config.go b/config.go index ef80b24..de285a6 100644 --- a/config.go +++ b/config.go @@ -26,6 +26,7 @@ type config struct { labels labels cache cacheConfig am alertmanagerConfig + resolved resolvedConfig } type ntfyConfig struct { @@ -56,6 +57,10 @@ type alertmanagerConfig struct { URL string } +type resolvedConfig struct { + Tags []string +} + func readConfig(path string) (*config, error) { cfg, err := scfg.Load(path) if err != nil { @@ -272,5 +277,18 @@ func readConfig(path string) (*config, error) { } } + resolvedDir := cfg.Get("resolved") + if resolvedDir != nil { + d = resolvedDir.Children.Get("tags") + if d != nil { + var tags string + if err := d.ParseParams(&tags); err != nil { + return nil, err + } + + config.resolved.Tags = strings.Split(tags, ",") + } + } + return config, nil } diff --git a/config_test.go b/config_test.go index 0c03fed..0fcdc3d 100644 --- a/config_test.go +++ b/config_test.go @@ -41,6 +41,10 @@ labels { } } +resolved { + tags "resolved,partying_face" +} + ntfy { # URL of the ntfy topic - required topic https://ntfy.sh/alertmanager-alerts @@ -93,6 +97,9 @@ cache { Password: "pass", URL: "https://alertmanager.xenrox.net", }, + resolved: resolvedConfig{ + Tags: []string{"resolved", "partying_face"}, + }, } configPath := filepath.Join(t.TempDir(), "config") diff --git a/main.go b/main.go index d158722..cd0500c 100644 --- a/main.go +++ b/main.go @@ -89,6 +89,10 @@ func (rcv *receiver) singleAlertNotifications(p *payload) []*notification { } var tags []string + if alert.Status == "resolved" { + tags = append(tags, rcv.cfg.resolved.Tags...) + } + for _, labelName := range rcv.cfg.labels.Order { val, ok := alert.Labels[labelName] if !ok { @@ -176,6 +180,10 @@ func (rcv *receiver) multiAlertNotification(p *payload) *notification { var priority string var tags []string + if p.Status == "resolved" { + tags = append(tags, rcv.cfg.resolved.Tags...) + } + for _, labelName := range rcv.cfg.labels.Order { val, ok := p.CommonLabels[labelName] if !ok {