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
89557dd6
Commit
89557dd6
authored
Jan 16, 2018
by
John Baublitz
Committed by
Leonard Gram
Mar 13, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Modify Grafana Pagerduty notifier to use Pagerduty API V2
parent
da190007
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
10 deletions
+26
-10
pkg/services/alerting/notifiers/pagerduty.go
+26
-10
No files found.
pkg/services/alerting/notifiers/pagerduty.go
View file @
89557dd6
package
notifiers
import
(
"os"
"time"
"strconv"
"fmt"
...
...
@@ -38,7 +40,7 @@ func init() {
}
var
(
pagerdutyEventApiUrl
string
=
"https://events.pagerduty.com/
generic/2010-04-15/create_event.json
"
pagerdutyEventApiUrl
string
=
"https://events.pagerduty.com/
v2/enqueue
"
)
func
NewPagerdutyNotifier
(
model
*
m
.
AlertNotification
)
(
alerting
.
Notifier
,
error
)
{
...
...
@@ -85,28 +87,39 @@ func (this *PagerdutyNotifier) Notify(evalContext *alerting.EvalContext) error {
this
.
log
.
Info
(
"Notifying Pagerduty"
,
"event_type"
,
eventType
)
payloadJSON
:=
simplejson
.
New
()
payloadJSON
.
Set
(
"summary"
,
evalContext
.
Rule
.
Name
+
" - "
+
evalContext
.
Rule
.
Message
)
if
hostname
,
err
:=
os
.
Hostname
();
err
==
nil
{
payloadJSON
.
Set
(
"source"
,
hostname
)
}
payloadJSON
.
Set
(
"severity"
,
"critical"
)
payloadJSON
.
Set
(
"timestamp"
,
time
.
Now
())
payloadJSON
.
Set
(
"component"
,
"Grafana"
)
payloadJSON
.
Set
(
"custom_details"
,
customData
)
bodyJSON
:=
simplejson
.
New
()
bodyJSON
.
Set
(
"service_key"
,
this
.
Key
)
bodyJSON
.
Set
(
"description"
,
evalContext
.
Rule
.
Name
+
" - "
+
evalContext
.
Rule
.
Message
)
bodyJSON
.
Set
(
"client"
,
"Grafana"
)
bodyJSON
.
Set
(
"details"
,
customData
)
bodyJSON
.
Set
(
"event_type"
,
eventType
)
bodyJSON
.
Set
(
"incident_key"
,
"alertId-"
+
strconv
.
FormatInt
(
evalContext
.
Rule
.
Id
,
10
))
bodyJSON
.
Set
(
"routing_key"
,
this
.
Key
)
bodyJSON
.
Set
(
"event_action"
,
eventType
)
bodyJSON
.
Set
(
"dedup_key"
,
"alertId-"
+
strconv
.
FormatInt
(
evalContext
.
Rule
.
Id
,
10
))
bodyJSON
.
Set
(
"payload"
,
payloadJSON
)
ruleUrl
,
err
:=
evalContext
.
GetRuleUrl
()
if
err
!=
nil
{
this
.
log
.
Error
(
"Failed get rule link"
,
"error"
,
err
)
return
err
}
bodyJSON
.
Set
(
"client_url"
,
ruleUrl
)
links
:=
make
([]
interface
{},
1
)
linkJSON
:=
simplejson
.
New
()
linkJSON
.
Set
(
"href"
,
ruleUrl
)
links
[
0
]
=
linkJSON
bodyJSON
.
Set
(
"links"
,
links
)
if
evalContext
.
ImagePublicUrl
!=
""
{
contexts
:=
make
([]
interface
{},
1
)
imageJSON
:=
simplejson
.
New
()
imageJSON
.
Set
(
"type"
,
"image"
)
imageJSON
.
Set
(
"src"
,
evalContext
.
ImagePublicUrl
)
contexts
[
0
]
=
imageJSON
bodyJSON
.
Set
(
"
context
s"
,
contexts
)
bodyJSON
.
Set
(
"
image
s"
,
contexts
)
}
body
,
_
:=
bodyJSON
.
MarshalJSON
()
...
...
@@ -115,6 +128,9 @@ func (this *PagerdutyNotifier) Notify(evalContext *alerting.EvalContext) error {
Url
:
pagerdutyEventApiUrl
,
Body
:
string
(
body
),
HttpMethod
:
"POST"
,
HttpHeader
:
map
[
string
]
string
{
"Content-Type"
:
"application/json"
,
},
}
if
err
:=
bus
.
DispatchCtx
(
evalContext
.
Ctx
,
cmd
);
err
!=
nil
{
...
...
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