Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
b81e97c9
Commit
b81e97c9
authored
Dec 05, 2016
by
bergquist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
webhook: adds json content-type
closes #6822
parent
0403f53b
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
13 deletions
+12
-13
pkg/services/notifications/webhook.go
+12
-13
No files found.
pkg/services/notifications/webhook.go
View file @
b81e97c9
...
@@ -6,7 +6,6 @@ import (
...
@@ -6,7 +6,6 @@ import (
"fmt"
"fmt"
"io/ioutil"
"io/ioutil"
"net/http"
"net/http"
"time"
"golang.org/x/net/context/ctxhttp"
"golang.org/x/net/context/ctxhttp"
...
@@ -22,8 +21,10 @@ type Webhook struct {
...
@@ -22,8 +21,10 @@ type Webhook struct {
HttpMethod
string
HttpMethod
string
}
}
var
webhookQueue
chan
*
Webhook
var
(
var
webhookLog
log
.
Logger
webhookQueue
chan
*
Webhook
webhookLog
log
.
Logger
)
func
initWebhookQueue
()
{
func
initWebhookQueue
()
{
webhookLog
=
log
.
New
(
"notifications.webhook"
)
webhookLog
=
log
.
New
(
"notifications.webhook"
)
...
@@ -47,24 +48,22 @@ func processWebhookQueue() {
...
@@ -47,24 +48,22 @@ func processWebhookQueue() {
func
sendWebRequestSync
(
ctx
context
.
Context
,
webhook
*
Webhook
)
error
{
func
sendWebRequestSync
(
ctx
context
.
Context
,
webhook
*
Webhook
)
error
{
webhookLog
.
Debug
(
"Sending webhook"
,
"url"
,
webhook
.
Url
,
"http method"
,
webhook
.
HttpMethod
)
webhookLog
.
Debug
(
"Sending webhook"
,
"url"
,
webhook
.
Url
,
"http method"
,
webhook
.
HttpMethod
)
client
:=
&
http
.
Client
{
Timeout
:
time
.
Duration
(
10
*
time
.
Second
),
}
if
webhook
.
HttpMethod
==
""
{
if
webhook
.
HttpMethod
==
""
{
webhook
.
HttpMethod
=
http
.
MethodPost
webhook
.
HttpMethod
=
http
.
MethodPost
}
}
request
,
err
:=
http
.
NewRequest
(
webhook
.
HttpMethod
,
webhook
.
Url
,
bytes
.
NewReader
([]
byte
(
webhook
.
Body
)))
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
{
if
err
!=
nil
{
return
err
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
{
if
err
!=
nil
{
return
err
return
err
}
}
...
@@ -73,11 +72,11 @@ func sendWebRequestSync(ctx context.Context, webhook *Webhook) error {
...
@@ -73,11 +72,11 @@ func sendWebRequestSync(ctx context.Context, webhook *Webhook) error {
return
nil
return
nil
}
}
defer
resp
.
Body
.
Close
()
body
,
err
:=
ioutil
.
ReadAll
(
resp
.
Body
)
body
,
err
:=
ioutil
.
ReadAll
(
resp
.
Body
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
defer
resp
.
Body
.
Close
()
webhookLog
.
Debug
(
"Webhook failed"
,
"statuscode"
,
resp
.
Status
,
"body"
,
string
(
body
))
webhookLog
.
Debug
(
"Webhook failed"
,
"statuscode"
,
resp
.
Status
,
"body"
,
string
(
body
))
return
fmt
.
Errorf
(
"Webhook response status %v"
,
resp
.
Status
)
return
fmt
.
Errorf
(
"Webhook response status %v"
,
resp
.
Status
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment