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`
......
......@@ -20,9 +20,18 @@ func init() {
Factory: NewAlertmanagerNotifier,
OptionsTemplate: `
<h3 class="page-heading">Alertmanager settings</h3>
<div class="gf-form">
<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 class="gf-form">
<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,19 +43,25 @@ 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,
log: log.New("alerting.notifier.prometheus-alertmanager"),
NotifierBase: NewNotifierBase(model),
URL: url,
BasicAuthUser: basicAuthUser,
BasicAuthPassword: basicAuthPassword,
log: log.New("alerting.notifier.prometheus-alertmanager"),
}, nil
}
// AlertmanagerNotifier sends alert notifications to the alert manager
type AlertmanagerNotifier struct {
NotifierBase
URL string
log log.Logger
URL string
BasicAuthUser string
BasicAuthPassword string
log log.Logger
}
// ShouldNotify returns true if the notifiers should be used depending on state
......@@ -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