~xenrox/ntfy-alertmanager

9b4b135a393f89a677f224b82b0e6ca755fbd62c — Jackson Chen 7 months ago 3baffc9
implement priority for resolved alerts
4 files changed, 13 insertions(+), 0 deletions(-)

M config.scfg
M config/config.go
M config/config_test.go
M main.go
M config.scfg => config.scfg +1 -0
@@ 40,6 40,7 @@ labels {
resolved {
    tags "resolved,partying_face"
    icon "https://foo.com/resolved.png"
    priority 1
}

ntfy {

M config/config.go => config/config.go +8 -0
@@ 79,6 79,7 @@ type alertmanagerConfig struct {
type resolvedConfig struct {
	Tags []string
	Icon string
	Priority string
}

// ReadConfig reads an scfg formatted file and returns the configuration struct.


@@ 415,6 416,13 @@ func ReadConfig(path string) (*Config, error) {
				return nil, err
			}
		}

		d = resolvedDir.Children.Get("priority")
		if d != nil {
			if err := d.ParseParams(&config.Resolved.Priority); err != nil {
				return nil, err
			}
		}
	}

	return config, nil

M config/config_test.go => config/config_test.go +2 -0
@@ 41,6 41,7 @@ labels {
resolved {
    tags "resolved,partying_face"
    icon "https://foo.com/resolved.png"
    resolved 1
}

ntfy {


@@ 106,6 107,7 @@ cache {
		Resolved: resolvedConfig{
			Tags: []string{"resolved", "partying_face"},
			Icon: "https://foo.com/resolved.png",
			Priority: "1",
		},
	}


M main.go => main.go +2 -0
@@ 117,6 117,7 @@ func (br *bridge) singleAlertNotifications(p *payload) []*notification {
		if alert.Status == "resolved" {
			tags = append(tags, br.cfg.Resolved.Tags...)
			n.icon = br.cfg.Resolved.Icon
			n.priority = br.cfg.Resolved.Priority
		}

		n.emailAddress = br.cfg.Ntfy.EmailAddress


@@ 226,6 227,7 @@ func (br *bridge) multiAlertNotification(p *payload) *notification {
	if p.Status == "resolved" {
		tags = append(tags, br.cfg.Resolved.Tags...)
		n.icon = br.cfg.Resolved.Icon
		n.priority = br.cfg.Resolved.Priority
	}

	n.emailAddress = br.cfg.Ntfy.EmailAddress