alertmanger: Add setting to overwrite URL
This commit is contained in:
parent
7bb448b5eb
commit
81ff7bd90e
4 changed files with 20 additions and 1 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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",
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue