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
2e809cae
Commit
2e809cae
authored
Jun 16, 2016
by
bergquist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tech(alerting): enforce POST for webhooks
parent
efea3bc9
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
22 additions
and
18 deletions
+22
-18
pkg/models/notifications.go
+2
-3
pkg/services/alerting/notifier.go
+7
-7
pkg/services/notifications/notifications.go
+2
-3
pkg/services/notifications/webhook.go
+11
-5
No files found.
pkg/models/notifications.go
View file @
2e809cae
...
@@ -14,10 +14,9 @@ type SendEmailCommand struct {
...
@@ -14,10 +14,9 @@ type SendEmailCommand struct {
type
SendWebhook
struct
{
type
SendWebhook
struct
{
Url
string
Url
string
Auth
User
string
User
string
Auth
Password
string
Password
string
Body
string
Body
string
Method
string
}
}
type
SendResetPasswordEmailCommand
struct
{
type
SendResetPasswordEmailCommand
struct
{
...
...
pkg/services/alerting/notifier.go
View file @
2e809cae
...
@@ -67,9 +67,8 @@ func (this *EmailNotifier) Dispatch(alertResult *AlertResult) {
...
@@ -67,9 +67,8 @@ func (this *EmailNotifier) Dispatch(alertResult *AlertResult) {
type
WebhookNotifier
struct
{
type
WebhookNotifier
struct
{
Url
string
Url
string
Method
string
User
string
AuthUser
string
Password
string
AuthPassword
string
log
log
.
Logger
log
log
.
Logger
}
}
...
@@ -77,7 +76,9 @@ func (this *WebhookNotifier) Dispatch(alertResult *AlertResult) {
...
@@ -77,7 +76,9 @@ func (this *WebhookNotifier) Dispatch(alertResult *AlertResult) {
this
.
log
.
Info
(
"Sending webhook"
)
this
.
log
.
Info
(
"Sending webhook"
)
cmd
:=
&
m
.
SendWebhook
{
cmd
:=
&
m
.
SendWebhook
{
Url
:
this
.
Url
,
Url
:
this
.
Url
,
Method
:
this
.
Method
,
User
:
this
.
User
,
Password
:
this
.
Password
,
Body
:
alertResult
.
Description
,
}
}
bus
.
Dispatch
(
cmd
)
bus
.
Dispatch
(
cmd
)
...
@@ -131,9 +132,8 @@ var createNotifier = func(notificationType string, settings *simplejson.Json) No
...
@@ -131,9 +132,8 @@ var createNotifier = func(notificationType string, settings *simplejson.Json) No
return
&
WebhookNotifier
{
return
&
WebhookNotifier
{
Url
:
settings
.
Get
(
"url"
)
.
MustString
(),
Url
:
settings
.
Get
(
"url"
)
.
MustString
(),
Method
:
settings
.
Get
(
"method"
)
.
MustString
(),
User
:
settings
.
Get
(
"user"
)
.
MustString
(),
AuthUser
:
settings
.
Get
(
"user"
)
.
MustString
(),
Password
:
settings
.
Get
(
"password"
)
.
MustString
(),
AuthPassword
:
settings
.
Get
(
"password"
)
.
MustString
(),
log
:
log
.
New
(
"alerting.notification.webhook"
),
log
:
log
.
New
(
"alerting.notification.webhook"
),
}
}
}
}
pkg/services/notifications/notifications.go
View file @
2e809cae
...
@@ -59,9 +59,8 @@ func Init() error {
...
@@ -59,9 +59,8 @@ func Init() error {
func
sendWebhook
(
cmd
*
m
.
SendWebhook
)
error
{
func
sendWebhook
(
cmd
*
m
.
SendWebhook
)
error
{
addToWebhookQueue
(
&
Webhook
{
addToWebhookQueue
(
&
Webhook
{
Url
:
cmd
.
Url
,
Url
:
cmd
.
Url
,
AuthUser
:
cmd
.
AuthUser
,
User
:
cmd
.
User
,
AuthPassword
:
cmd
.
AuthPassword
,
Password
:
cmd
.
Password
,
Method
:
cmd
.
Method
,
Body
:
cmd
.
Body
,
Body
:
cmd
.
Body
,
})
})
...
...
pkg/services/notifications/webhook.go
View file @
2e809cae
package
notifications
package
notifications
import
(
import
(
"bytes"
"net/http"
"net/http"
"time"
"time"
"github.com/grafana/grafana/pkg/log"
"github.com/grafana/grafana/pkg/log"
"github.com/grafana/grafana/pkg/util"
)
)
type
Webhook
struct
{
type
Webhook
struct
{
Url
string
Url
string
Auth
User
string
User
string
Auth
Password
string
Password
string
Body
string
Body
string
Method
string
}
}
var
webhookQueue
chan
*
Webhook
var
webhookQueue
chan
*
Webhook
...
@@ -40,9 +41,14 @@ func processWebhookQueue() {
...
@@ -40,9 +41,14 @@ func processWebhookQueue() {
func
sendWebRequest
(
webhook
*
Webhook
)
error
{
func
sendWebRequest
(
webhook
*
Webhook
)
error
{
webhookLog
.
Error
(
"Sending stuff! "
,
"url"
,
webhook
.
Url
)
webhookLog
.
Error
(
"Sending stuff! "
,
"url"
,
webhook
.
Url
)
client
:=
http
.
Client
{
Timeout
:
time
.
Duration
(
3
*
time
.
Second
)}
client
:=
http
.
Client
{
Timeout
:
time
.
Duration
(
3
*
time
.
Second
),
}
request
,
err
:=
http
.
NewRequest
(
webhook
.
Method
,
webhook
.
Url
,
nil
/*io.reader*/
)
request
,
err
:=
http
.
NewRequest
(
"POST"
,
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
...
...
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