Commit 1814dc5a by melchiormoulin Committed by GitHub

Alertmanager: Adds support for basic auth (#23231)

Add basicauth username and password to the alertmanager notifier UI
parent 98da152f
......@@ -398,6 +398,8 @@ The following sections detail the supported settings for each alert notification
| Name |
| ---- |
| url |
| basicAuthUser |
| basicAuthPassword |
#### Alert notification `teams`
......
......@@ -24,6 +24,15 @@ func init() {
<span class="gf-form-label width-10">Url</span>
<input type="text" required class="gf-form-input max-width-26" ng-model="ctrl.model.settings.url" placeholder="http://localhost:9093"></input>
</div>
<div class="gf-form">
<span class="gf-form-label width-10">Basic Auth User</span>
<input type="text" required class="gf-form-input max-width-26" ng-model="ctrl.model.settings.basicAuthUser" placeholder=""></input>
</div>
<div class="gf-form">
<span class="gf-form-label width-10">Basic Auth Password</span>
<input type="text" required class="gf-form-input max-width-26" ng-model="ctrl.model.settings.basicAuthPassword" placeholder=""></input>
</div>
</div>
`,
})
}
......@@ -34,10 +43,14 @@ func NewAlertmanagerNotifier(model *models.AlertNotification) (alerting.Notifier
if url == "" {
return nil, alerting.ValidationError{Reason: "Could not find url property in settings"}
}
basicAuthUser := model.Settings.Get("basicAuthUser").MustString()
basicAuthPassword := model.Settings.Get("basicAuthPassword").MustString()
return &AlertmanagerNotifier{
NotifierBase: NewNotifierBase(model),
URL: url,
BasicAuthUser: basicAuthUser,
BasicAuthPassword: basicAuthPassword,
log: log.New("alerting.notifier.prometheus-alertmanager"),
}, nil
}
......@@ -46,6 +59,8 @@ func NewAlertmanagerNotifier(model *models.AlertNotification) (alerting.Notifier
type AlertmanagerNotifier struct {
NotifierBase
URL string
BasicAuthUser string
BasicAuthPassword string
log log.Logger
}
......@@ -140,6 +155,8 @@ func (am *AlertmanagerNotifier) Notify(evalContext *alerting.EvalContext) error
cmd := &models.SendWebhookSync{
Url: am.URL + "/api/v1/alerts",
User: am.BasicAuthUser,
Password: am.BasicAuthPassword,
HttpMethod: "POST",
Body: string(body),
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment