alertmanger: Add setting to overwrite URL

This commit is contained in:
Thorben Günther 2023-02-12 14:58:37 +01:00
parent 7bb448b5eb
commit 81ff7bd90e
No known key found for this signature in database
GPG key ID: 415CD778D8C5AFED
4 changed files with 20 additions and 1 deletions

View file

@ -77,6 +77,9 @@ alertmanager {
# Basic authentication (https://prometheus.io/docs/alerting/latest/https/) # Basic authentication (https://prometheus.io/docs/alerting/latest/https/)
user user user user
password pass 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 # When the alert-mode is set to single, ntfy-alertmanager will cache each single alert

View file

@ -53,6 +53,7 @@ type alertmanagerConfig struct {
User string User string
Password string Password string
SilenceDuration time.Duration SilenceDuration time.Duration
URL string
} }
func readConfig(path string) (*config, error) { func readConfig(path string) (*config, error) {
@ -262,6 +263,13 @@ func readConfig(path string) (*config, error) {
return nil, err 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 return config, nil

View file

@ -58,6 +58,7 @@ alertmanager {
# Basic authentication (https://prometheus.io/docs/alerting/latest/https/) # Basic authentication (https://prometheus.io/docs/alerting/latest/https/)
user user user user
password pass password pass
url https://alertmanager.xenrox.net
} }
# When the alert-mode is set to single, ntfy-alertmanager will cache each single alert # When the alert-mode is set to single, ntfy-alertmanager will cache each single alert
@ -90,6 +91,7 @@ cache {
SilenceDuration: time.Hour * 24, SilenceDuration: time.Hour * 24,
User: "user", User: "user",
Password: "pass", Password: "pass",
URL: "https://alertmanager.xenrox.net",
}, },
} }

View file

@ -87,7 +87,13 @@ func (rcv *receiver) handleSilences(w http.ResponseWriter, r *http.Request) {
} }
client := &http.Client{Timeout: time.Second * 3} 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)) req, err := http.NewRequest(http.MethodPost, url, bytes.NewBuffer(b))
if err != nil { if err != nil {
rcv.logger.Debugf("silences: %v", err) rcv.logger.Debugf("silences: %v", err)