mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Alerting: Configure alert manager data source as an external AM (#52081)
Co-authored-by: Jean-Philippe Quéméner <JohnnyQQQQ@users.noreply.github.com> Co-authored-by: gotjosh <josue.abreu@gmail.com> Co-authored-by: brendamuir <100768211+brendamuir@users.noreply.github.com>
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
|
||||
"github.com/benbjohnson/clock"
|
||||
|
||||
"github.com/grafana/grafana/pkg/api/datasource"
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/services/datasources"
|
||||
"github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
|
||||
@@ -126,6 +127,8 @@ func (d *AlertsRouter) SyncAndApplyConfigFromDatabase() error {
|
||||
continue
|
||||
}
|
||||
|
||||
d.logger.Debug("alertmanagers found in the configuration", "alertmanagers", cfg.Alertmanagers)
|
||||
|
||||
// We have a running sender, check if we need to apply a new config.
|
||||
if ok {
|
||||
if d.externalAlertmanagersCfgHash[cfg.OrgID] == cfg.AsSHA256() {
|
||||
@@ -218,16 +221,17 @@ func (d *AlertsRouter) alertmanagersFromDatasources(orgID int64) ([]string, erro
|
||||
}
|
||||
|
||||
func (d *AlertsRouter) buildExternalURL(ds *datasources.DataSource) (string, error) {
|
||||
amURL := ds.Url
|
||||
// if basic auth is enabled we need to build the url with basic auth baked in
|
||||
if !ds.BasicAuth {
|
||||
return amURL, nil
|
||||
}
|
||||
|
||||
parsed, err := url.Parse(ds.Url)
|
||||
// We re-use the same parsing logic as the datasource to make sure it matches whatever output the user received
|
||||
// when doing the healthcheck.
|
||||
parsed, err := datasource.ValidateURL(datasources.DS_ALERTMANAGER, ds.Url)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to parse alertmanager datasource url: %w", err)
|
||||
}
|
||||
// if basic auth is enabled we need to build the url with basic auth baked in
|
||||
if !ds.BasicAuth {
|
||||
return parsed.String(), nil
|
||||
}
|
||||
|
||||
password := d.secretService.GetDecryptedValue(context.Background(), ds.SecureJsonData, "basicAuthPassword", "")
|
||||
if password == "" {
|
||||
return "", fmt.Errorf("basic auth enabled but no password set")
|
||||
|
||||
Reference in New Issue
Block a user