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
638d3bcb
Commit
638d3bcb
authored
Nov 02, 2016
by
utkarshcmu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Removed NoData option
parent
de0fa3d4
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
12 additions
and
89 deletions
+12
-89
pkg/services/alerting/notifiers/pagerduty.go
+9
-26
pkg/services/alerting/notifiers/pagerduty_test.go
+2
-53
public/app/features/alerting/partials/notification_edit.html
+1
-10
No files found.
pkg/services/alerting/notifiers/pagerduty.go
View file @
638d3bcb
...
...
@@ -19,54 +19,37 @@ func NewPagerdutyNotifier(model *m.AlertNotification) (alerting.Notifier, error)
return
nil
,
alerting
.
ValidationError
{
Reason
:
"Could not find integration key property in settings"
}
}
alertingStates
:=
make
([]
m
.
AlertStateType
,
0
)
alertingStates
=
append
(
alertingStates
,
m
.
AlertStateAlerting
)
if
model
.
Settings
.
Get
(
"alertOnExecError"
)
.
MustBool
()
{
alertingStates
=
append
(
alertingStates
,
m
.
AlertStateExecError
)
}
if
model
.
Settings
.
Get
(
"alertOnNoData"
)
.
MustBool
()
{
alertingStates
=
append
(
alertingStates
,
m
.
AlertStateNoData
)
}
return
&
PagerdutyNotifier
{
NotifierBase
:
NewNotifierBase
(
model
.
Id
,
model
.
IsDefault
,
model
.
Name
,
model
.
Type
,
model
.
Settings
),
NotifierBase
:
NewNotifierBase
(
model
.
Id
,
model
.
IsDefault
,
model
.
Name
,
model
.
Type
,
model
.
Settings
),
Key
:
key
,
Alert
ingStates
:
alertingStates
,
Alert
OnExecError
:
model
.
Settings
.
Get
(
"alertOnExecError"
)
.
MustBool
()
,
log
:
log
.
New
(
"alerting.notifier.pagerduty"
),
},
nil
}
type
PagerdutyNotifier
struct
{
NotifierBase
Key
string
Alert
ingStates
[]
m
.
AlertStateType
log
log
.
Logger
Key
string
Alert
OnExecError
bool
log
log
.
Logger
}
func
(
this
*
PagerdutyNotifier
)
Notify
(
evalContext
*
alerting
.
EvalContext
)
error
{
this
.
log
.
Info
(
"Notifying Pagerduty"
)
metrics
.
M_Alerting_Notification_Sent_PagerDuty
.
Inc
(
1
)
shouldNotify
:=
false
for
_
,
state
:=
range
this
.
AlertingStates
{
if
evalContext
.
Rule
.
State
==
state
{
shouldNotify
=
true
break
}
}
if
shouldNotify
{
if
(
evalContext
.
Rule
.
State
==
m
.
AlertStateAlerting
)
||
((
this
.
AlertOnExecError
)
&&
(
evalContext
.
Rule
.
State
==
m
.
AlertStateExecError
))
{
// Pagerduty Events API URL
pgEventsUrl
:=
"https://events.pagerduty.com/generic/2010-04-15/create_event.json"
bodyJSON
:=
simplejson
.
New
()
bodyJSON
.
Set
(
"service_key"
,
this
.
Key
)
bodyJSON
.
Set
(
"description"
,
evalContext
.
Rule
.
Name
+
"-"
+
evalContext
.
Rule
.
Message
)
bodyJSON
.
Set
(
"description"
,
evalContext
.
Rule
.
Name
+
"-"
+
evalContext
.
Rule
.
Message
)
bodyJSON
.
Set
(
"client"
,
"Grafana"
)
bodyJSON
.
Set
(
"event_type"
,
"trigger"
)
ruleUrl
,
err
:=
evalContext
.
GetRuleUrl
()
if
err
!=
nil
{
this
.
log
.
Error
(
"Failed get rule link"
,
"error"
,
err
)
...
...
pkg/services/alerting/notifiers/pagerduty_test.go
View file @
638d3bcb
...
...
@@ -26,59 +26,10 @@ func TestPagerdutyNotifier(t *testing.T) {
So
(
err
,
ShouldNotBeNil
)
})
Convey
(
"settings with only integrationKey should contain AlertStateAlerting"
,
func
()
{
json
:=
`
{
"integrationKey": "abcdefgh0123456789"
}`
settingsJSON
,
_
:=
simplejson
.
NewJson
([]
byte
(
json
))
model
:=
&
m
.
AlertNotification
{
Name
:
"pagerduty_testing"
,
Type
:
"pagerduty"
,
Settings
:
settingsJSON
,
}
not
,
err
:=
NewPagerdutyNotifier
(
model
)
pagerdutyNotifier
:=
not
.
(
*
PagerdutyNotifier
)
So
(
err
,
ShouldBeNil
)
So
(
pagerdutyNotifier
.
Name
,
ShouldEqual
,
"pagerduty_testing"
)
So
(
pagerdutyNotifier
.
Type
,
ShouldEqual
,
"pagerduty"
)
So
(
pagerdutyNotifier
.
Key
,
ShouldEqual
,
"abcdefgh0123456789"
)
So
(
pagerdutyNotifier
.
AlertingStates
,
ShouldContain
,
m
.
AlertStateAlerting
)
})
Convey
(
"settings with alertOnNoData should contain AlertStateNoData too"
,
func
()
{
json
:=
`
{
"integrationKey": "abcdefgh0123456789",
"alertOnNoData": true
}`
settingsJSON
,
_
:=
simplejson
.
NewJson
([]
byte
(
json
))
model
:=
&
m
.
AlertNotification
{
Name
:
"pagerduty_testing"
,
Type
:
"pagerduty"
,
Settings
:
settingsJSON
,
}
not
,
err
:=
NewPagerdutyNotifier
(
model
)
pagerdutyNotifier
:=
not
.
(
*
PagerdutyNotifier
)
So
(
err
,
ShouldBeNil
)
So
(
pagerdutyNotifier
.
Name
,
ShouldEqual
,
"pagerduty_testing"
)
So
(
pagerdutyNotifier
.
Type
,
ShouldEqual
,
"pagerduty"
)
So
(
pagerdutyNotifier
.
Key
,
ShouldEqual
,
"abcdefgh0123456789"
)
So
(
pagerdutyNotifier
.
AlertingStates
,
ShouldContain
,
m
.
AlertStateNoData
)
So
(
pagerdutyNotifier
.
AlertingStates
,
ShouldContain
,
m
.
AlertStateAlerting
)
})
Convey
(
"settings with alertOnNoData, alertOnExecError should contain both"
,
func
()
{
Convey
(
"settings with alertOnExecError should trigger incident"
,
func
()
{
json
:=
`
{
"integrationKey": "abcdefgh0123456789",
"alertOnNoData": true,
"alertOnExecError": true
}`
...
...
@@ -96,9 +47,7 @@ func TestPagerdutyNotifier(t *testing.T) {
So
(
pagerdutyNotifier
.
Name
,
ShouldEqual
,
"pagerduty_testing"
)
So
(
pagerdutyNotifier
.
Type
,
ShouldEqual
,
"pagerduty"
)
So
(
pagerdutyNotifier
.
Key
,
ShouldEqual
,
"abcdefgh0123456789"
)
So
(
pagerdutyNotifier
.
AlertingStates
,
ShouldContain
,
m
.
AlertStateNoData
)
So
(
pagerdutyNotifier
.
AlertingStates
,
ShouldContain
,
m
.
AlertStateAlerting
)
So
(
pagerdutyNotifier
.
AlertingStates
,
ShouldContain
,
m
.
AlertStateExecError
)
So
(
pagerdutyNotifier
.
AlertOnExecError
,
ShouldContain
,
true
)
})
})
...
...
public/app/features/alerting/partials/notification_edit.html
View file @
638d3bcb
...
...
@@ -106,19 +106,10 @@
<div
class=
"gf-form"
>
<gf-form-switch
class=
"gf-form"
label=
"Alert on No Data"
label-class=
"width-12"
checked=
"ctrl.model.settings.alertOnNoData"
tooltip=
"Trigger incident on No Data"
>
</gf-form-switch>
</div>
<div
class=
"gf-form"
>
<gf-form-switch
class=
"gf-form"
label=
"Alert on Exec Error"
label-class=
"width-12"
checked=
"ctrl.model.settings.alertOnExecError"
tooltip=
"Trigger incident on Exec
ution
Error"
>
tooltip=
"Trigger incident on Exec Error"
>
</gf-form-switch>
</div>
</div>
...
...
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