diff --git a/README.md b/README.md index 6deb0e7..87211f1 100644 --- a/README.md +++ b/README.md @@ -77,6 +77,9 @@ alertmanager { # Basic authentication (https://prometheus.io/docs/alerting/latest/https/) user user password pass + # By default the Alertmanager URL gets parsed from the webhook. In case that + # Alertmanger is not reachable under that URL, it can be overwritten here. + url https://alertmanager.xenrox.net } # When the alert-mode is set to single, ntfy-alertmanager will cache each single alert diff --git a/config.go b/config.go index f0e1506..ef80b24 100644 --- a/config.go +++ b/config.go @@ -53,6 +53,7 @@ type alertmanagerConfig struct { User string Password string SilenceDuration time.Duration + URL string } func readConfig(path string) (*config, error) { @@ -262,6 +263,13 @@ func readConfig(path string) (*config, error) { return nil, err } } + + d = amDir.Children.Get("url") + if d != nil { + if err := d.ParseParams(&config.am.URL); err != nil { + return nil, err + } + } } return config, nil diff --git a/config_test.go b/config_test.go index a2ab6a4..0c03fed 100644 --- a/config_test.go +++ b/config_test.go @@ -58,6 +58,7 @@ alertmanager { # Basic authentication (https://prometheus.io/docs/alerting/latest/https/) user user password pass + url https://alertmanager.xenrox.net } # When the alert-mode is set to single, ntfy-alertmanager will cache each single alert @@ -90,6 +91,7 @@ cache { SilenceDuration: time.Hour * 24, User: "user", Password: "pass", + URL: "https://alertmanager.xenrox.net", }, } diff --git a/silence.go b/silence.go index b5c5a6b..7d207e6 100644 --- a/silence.go +++ b/silence.go @@ -87,7 +87,13 @@ func (rcv *receiver) handleSilences(w http.ResponseWriter, r *http.Request) { } client := &http.Client{Timeout: time.Second * 3} - url := sb.AlertManagerURL + "/api/v2/silences" + + url := sb.AlertManagerURL + if rcv.cfg.am.URL != "" { + url = rcv.cfg.am.URL + } + url += "/api/v2/silences" + req, err := http.NewRequest(http.MethodPost, url, bytes.NewBuffer(b)) if err != nil { rcv.logger.Debugf("silences: %v", err)