From 87dbdb83005f311b411e5f73519309dce3e798f5 Mon Sep 17 00:00:00 2001 From: bergquist Date: Mon, 5 Dec 2016 10:44:31 +0100 Subject: [PATCH 1/3] webhook: adds json content-type closes #6822 --- pkg/services/notifications/webhook.go | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/pkg/services/notifications/webhook.go b/pkg/services/notifications/webhook.go index de1303d8131..ac46a43f294 100644 --- a/pkg/services/notifications/webhook.go +++ b/pkg/services/notifications/webhook.go @@ -6,7 +6,6 @@ import ( "fmt" "io/ioutil" "net/http" - "time" "golang.org/x/net/context/ctxhttp" @@ -22,8 +21,10 @@ type Webhook struct { HttpMethod string } -var webhookQueue chan *Webhook -var webhookLog log.Logger +var ( + webhookQueue chan *Webhook + webhookLog log.Logger +) func initWebhookQueue() { webhookLog = log.New("notifications.webhook") @@ -47,24 +48,22 @@ func processWebhookQueue() { func sendWebRequestSync(ctx context.Context, webhook *Webhook) error { webhookLog.Debug("Sending webhook", "url", webhook.Url, "http method", webhook.HttpMethod) - client := &http.Client{ - Timeout: time.Duration(10 * time.Second), - } - 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)) - } - if err != nil { return err } - resp, err := ctxhttp.Do(ctx, client, request) + request.Header.Add("Content-Type", "application/json") + request.Header.Add("User-Agent", "Grafana") + if webhook.User != "" && webhook.Password != "" { + request.Header.Add("Authorization", util.GetBasicAuthHeader(webhook.User, webhook.Password)) + } + + resp, err := ctxhttp.Do(ctx, http.DefaultClient, request) if err != nil { return err } @@ -73,11 +72,11 @@ func sendWebRequestSync(ctx context.Context, webhook *Webhook) error { return nil } + defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) if err != nil { return err } - defer resp.Body.Close() webhookLog.Debug("Webhook failed", "statuscode", resp.Status, "body", string(body)) return fmt.Errorf("Webhook response status %v", resp.Status) From 4a2a935c8f4ccc16829a07f88a7692be9f4a1bc7 Mon Sep 17 00:00:00 2001 From: bergquist Date: Mon, 5 Dec 2016 10:45:22 +0100 Subject: [PATCH 2/3] changelog: adds note about closing #6822 --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7ab51de161e..5a67690a710 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ ### Bugfixes * **Alerting**: Add alert message to webhook notifications [#6807](https://github.com/grafana/grafana/issues/6807) +* **Webhooks**: Add content type json to outgoing webhooks [#6822](https://github.com/grafana/grafana/issues/6822) # 4.0.1 (2016-12-02) From 48a14cb4c608af23b9af4888102c65ae5798da59 Mon Sep 17 00:00:00 2001 From: silvestre-abruzzo Date: Mon, 5 Dec 2016 10:50:23 +0100 Subject: [PATCH 3/3] Use correct domain in render.js (#6813) Phantomjs is always rendering login page because domain is not considered. According to http://phantomjs.org/api/webpage/method/add-cookie.html a correct domain must be passed. Probably this change is now necessary due to https://github.com/grafana/grafana/issues/6660 --- vendor/phantomjs/render.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vendor/phantomjs/render.js b/vendor/phantomjs/render.js index 2f62bfce955..b9039f1f482 100644 --- a/vendor/phantomjs/render.js +++ b/vendor/phantomjs/render.js @@ -22,7 +22,7 @@ phantom.addCookie({ 'name': 'renderKey', 'value': params.renderKey, - 'domain': 'localhost', + 'domain': params.domain, }); page.viewportSize = {