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
d1eceedf
Commit
d1eceedf
authored
Oct 18, 2016
by
bergquist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(webhook): add httpmethod to webhook
closes #6255
parent
9429434c
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
57 additions
and
40 deletions
+57
-40
pkg/models/notifications.go
+10
-8
pkg/services/alerting/notifiers/webhook.go
+11
-8
pkg/services/notifications/notifications.go
+10
-8
pkg/services/notifications/webhook.go
+11
-6
public/app/features/alerting/notification_edit_ctrl.ts
+1
-1
public/app/features/alerting/partials/notification_edit.html
+14
-9
No files found.
pkg/models/notifications.go
View file @
d1eceedf
...
...
@@ -17,17 +17,19 @@ type SendEmailCommandSync struct {
}
type
SendWebhook
struct
{
Url
string
User
string
Password
string
Body
string
Url
string
User
string
Password
string
Body
string
HttpMethod
string
}
type
SendWebhookSync
struct
{
Url
string
User
string
Password
string
Body
string
Url
string
User
string
Password
string
Body
string
HttpMethod
string
}
type
SendResetPasswordEmailCommand
struct
{
...
...
pkg/services/alerting/notifiers/webhook.go
View file @
d1eceedf
...
...
@@ -24,16 +24,18 @@ 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
}
type
WebhookNotifier
struct
{
NotifierBase
Url
string
User
string
Password
string
log
log
.
Logger
Url
string
User
string
Password
string
HttpMethod
string
log
log
.
Logger
}
func
(
this
*
WebhookNotifier
)
Notify
(
evalContext
*
alerting
.
EvalContext
)
error
{
...
...
@@ -59,10 +61,11 @@ func (this *WebhookNotifier) Notify(evalContext *alerting.EvalContext) error {
body
,
_
:=
bodyJSON
.
MarshalJSON
()
cmd
:=
&
m
.
SendWebhookSync
{
Url
:
this
.
Url
,
User
:
this
.
User
,
Password
:
this
.
Password
,
Body
:
string
(
body
),
Url
:
this
.
Url
,
User
:
this
.
User
,
Password
:
this
.
Password
,
Body
:
string
(
body
),
HttpMethod
:
this
.
HttpMethod
,
}
if
err
:=
bus
.
DispatchCtx
(
evalContext
.
Ctx
,
cmd
);
err
!=
nil
{
...
...
pkg/services/notifications/notifications.go
View file @
d1eceedf
...
...
@@ -61,19 +61,21 @@ func Init() error {
func
SendWebhookSync
(
ctx
context
.
Context
,
cmd
*
m
.
SendWebhookSync
)
error
{
return
sendWebRequestSync
(
ctx
,
&
Webhook
{
Url
:
cmd
.
Url
,
User
:
cmd
.
User
,
Password
:
cmd
.
Password
,
Body
:
cmd
.
Body
,
Url
:
cmd
.
Url
,
User
:
cmd
.
User
,
Password
:
cmd
.
Password
,
Body
:
cmd
.
Body
,
HttpMethod
:
cmd
.
HttpMethod
,
})
}
func
sendWebhook
(
cmd
*
m
.
SendWebhook
)
error
{
addToWebhookQueue
(
&
Webhook
{
Url
:
cmd
.
Url
,
User
:
cmd
.
User
,
Password
:
cmd
.
Password
,
Body
:
cmd
.
Body
,
Url
:
cmd
.
Url
,
User
:
cmd
.
User
,
Password
:
cmd
.
Password
,
Body
:
cmd
.
Body
,
HttpMethod
:
cmd
.
HttpMethod
,
})
return
nil
...
...
pkg/services/notifications/webhook.go
View file @
d1eceedf
...
...
@@ -15,10 +15,11 @@ import (
)
type
Webhook
struct
{
Url
string
User
string
Password
string
Body
string
Url
string
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
))
}
...
...
public/app/features/alerting/notification_edit_ctrl.ts
View file @
d1eceedf
...
...
@@ -18,7 +18,7 @@ export class AlertNotificationEditCtrl {
this
.
model
=
{
type
:
'email'
,
settings
:
{
severityFilter
:
'none
'
httpMethod
:
'POST
'
},
isDefault
:
false
};
...
...
public/app/features/alerting/partials/notification_edit.html
View file @
d1eceedf
...
...
@@ -32,19 +32,24 @@
<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>
</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>
<div
class=
"gf-form"
>
<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-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>
<div
class=
"gf-form-group"
ng-if=
"ctrl.model.type === 'slack'"
>
...
...
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