feat(webhook): add httpmethod to webhook

closes #6255
pull/6318/head
bergquist 9 years ago
parent 9429434cb5
commit d1eceedf55
  1. 2
      pkg/models/notifications.go
  2. 3
      pkg/services/alerting/notifiers/webhook.go
  3. 2
      pkg/services/notifications/notifications.go
  4. 9
      pkg/services/notifications/webhook.go
  5. 2
      public/app/features/alerting/notification_edit_ctrl.ts
  6. 17
      public/app/features/alerting/partials/notification_edit.html

@ -21,6 +21,7 @@ type SendWebhook struct {
User string
Password string
Body string
HttpMethod string
}
type SendWebhookSync struct {
@ -28,6 +29,7 @@ type SendWebhookSync struct {
User string
Password string
Body string
HttpMethod string
}
type SendResetPasswordEmailCommand struct {

@ -24,6 +24,7 @@ func NewWebHookNotifier(model *m.AlertNotification) (alerting.Notifier, error) {
Url: url,
User: model.Settings.Get("user").MustString(),
Password: model.Settings.Get("password").MustString(),
HttpMethod: model.Settings.Get("httpMethod").MustString("POST"),
log: log.New("alerting.notifier.webhook"),
}, nil
}
@ -33,6 +34,7 @@ type WebhookNotifier struct {
Url string
User string
Password string
HttpMethod string
log log.Logger
}
@ -63,6 +65,7 @@ func (this *WebhookNotifier) Notify(evalContext *alerting.EvalContext) error {
User: this.User,
Password: this.Password,
Body: string(body),
HttpMethod: this.HttpMethod,
}
if err := bus.DispatchCtx(evalContext.Ctx, cmd); err != nil {

@ -65,6 +65,7 @@ func SendWebhookSync(ctx context.Context, cmd *m.SendWebhookSync) error {
User: cmd.User,
Password: cmd.Password,
Body: cmd.Body,
HttpMethod: cmd.HttpMethod,
})
}
@ -74,6 +75,7 @@ func sendWebhook(cmd *m.SendWebhook) error {
User: cmd.User,
Password: cmd.Password,
Body: cmd.Body,
HttpMethod: cmd.HttpMethod,
})
return nil

@ -19,6 +19,7 @@ type Webhook struct {
User string
Password string
Body string
HttpMethod string
}
var webhookQueue chan *Webhook
@ -44,13 +45,17 @@ func processWebhookQueue() {
}
func sendWebRequestSync(ctx context.Context, webhook *Webhook) error {
webhookLog.Debug("Sending webhook", "url", webhook.Url)
webhookLog.Debug("Sending webhook", "url", webhook.Url, "http method", webhook.HttpMethod)
client := &http.Client{
Timeout: time.Duration(10 * time.Second),
}
request, err := http.NewRequest(http.MethodPost, webhook.Url, bytes.NewReader([]byte(webhook.Body)))
if webhook.HttpMethod == "" {
webhook.HttpMethod = http.MethodPost
}
request, err := http.NewRequest(webhook.HttpMethod, webhook.Url, bytes.NewReader([]byte(webhook.Body)))
if webhook.User != "" && webhook.Password != "" {
request.Header.Add("Authorization", util.GetBasicAuthHeader(webhook.User, webhook.Password))
}

@ -18,7 +18,7 @@ export class AlertNotificationEditCtrl {
this.model = {
type: 'email',
settings: {
severityFilter: 'none'
httpMethod: 'POST'
},
isDefault: false
};

@ -32,18 +32,23 @@
<div class="gf-form-group" ng-if="ctrl.model.type === 'webhook'">
<h3 class="page-heading">Webhook settings</h3>
<div class="gf-form">
<span class="gf-form-label width-6">Url</span>
<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"></input>
</div>
<div class="gf-form-inline">
<div class="gf-form">
<span class="gf-form-label width-6">Username</span>
<input type="text" class="gf-form-input max-width-10" ng-model="ctrl.model.settings.username"></input>
<span class="gf-form-label width-10">Http Method</span>
<div class="gf-form-select-wrapper width-14">
<select class="gf-form-input" ng-model="ctrl.model.settings.httpMethod" ng-options="t for t in ['POST', 'PUT']">
</select>
</div>
</div>
<div class="gf-form">
<span class="gf-form-label width-6">Password</span>
<input type="text" class="gf-form-input max-width-10" ng-model="ctrl.model.settings.password"></input>
<span class="gf-form-label width-10">Username</span>
<input type="text" class="gf-form-input max-width-14" ng-model="ctrl.model.settings.username"></input>
</div>
<div class="gf-form">
<span class="gf-form-label width-10">Password</span>
<input type="text" class="gf-form-input max-width-14" ng-model="ctrl.model.settings.password"></input>
</div>
</div>

Loading…
Cancel
Save