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
9289cba6
Commit
9289cba6
authored
Oct 02, 2018
by
bergquist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
merges defaultShouldNotify and ShouldNotify
parent
67e5f625
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
13 deletions
+11
-13
pkg/services/alerting/notifiers/base.go
+8
-12
pkg/services/alerting/notifiers/base_test.go
+3
-1
No files found.
pkg/services/alerting/notifiers/base.go
View file @
9289cba6
...
@@ -45,16 +45,17 @@ func NewNotifierBase(model *models.AlertNotification) NotifierBase {
...
@@ -45,16 +45,17 @@ func NewNotifierBase(model *models.AlertNotification) NotifierBase {
}
}
}
}
func
defaultShouldNotify
(
context
*
alerting
.
EvalContext
,
sendReminder
bool
,
frequency
time
.
Duration
,
notificationState
*
models
.
AlertNotificationState
)
bool
{
// ShouldNotify checks this evaluation should send an alert notification
func
(
n
*
NotifierBase
)
ShouldNotify
(
ctx
context
.
Context
,
context
*
alerting
.
EvalContext
,
notiferState
*
models
.
AlertNotificationState
)
bool
{
// Only notify on state change.
// Only notify on state change.
if
context
.
PrevAlertState
==
context
.
Rule
.
State
&&
!
s
endReminder
{
if
context
.
PrevAlertState
==
context
.
Rule
.
State
&&
!
n
.
S
endReminder
{
return
false
return
false
}
}
if
context
.
PrevAlertState
==
context
.
Rule
.
State
&&
s
endReminder
{
if
context
.
PrevAlertState
==
context
.
Rule
.
State
&&
n
.
S
endReminder
{
// Do not notify if interval has not elapsed
// Do not notify if interval has not elapsed
lastNotify
:=
time
.
Unix
(
notif
ication
State
.
UpdatedAt
,
0
)
lastNotify
:=
time
.
Unix
(
notif
er
State
.
UpdatedAt
,
0
)
if
notif
icationState
.
UpdatedAt
!=
0
&&
lastNotify
.
Add
(
f
requency
)
.
After
(
time
.
Now
())
{
if
notif
erState
.
UpdatedAt
!=
0
&&
lastNotify
.
Add
(
n
.
F
requency
)
.
After
(
time
.
Now
())
{
return
false
return
false
}
}
...
@@ -75,8 +76,8 @@ func defaultShouldNotify(context *alerting.EvalContext, sendReminder bool, frequ
...
@@ -75,8 +76,8 @@ func defaultShouldNotify(context *alerting.EvalContext, sendReminder bool, frequ
}
}
// Do not notifu if state pending and it have been updated last minute
// Do not notifu if state pending and it have been updated last minute
if
notif
ication
State
.
State
==
models
.
AlertNotificationStatePending
{
if
notif
er
State
.
State
==
models
.
AlertNotificationStatePending
{
lastUpdated
:=
time
.
Unix
(
notif
ication
State
.
UpdatedAt
,
0
)
lastUpdated
:=
time
.
Unix
(
notif
er
State
.
UpdatedAt
,
0
)
if
lastUpdated
.
Add
(
1
*
time
.
Minute
)
.
After
(
time
.
Now
())
{
if
lastUpdated
.
Add
(
1
*
time
.
Minute
)
.
After
(
time
.
Now
())
{
return
false
return
false
}
}
...
@@ -85,11 +86,6 @@ func defaultShouldNotify(context *alerting.EvalContext, sendReminder bool, frequ
...
@@ -85,11 +86,6 @@ func defaultShouldNotify(context *alerting.EvalContext, sendReminder bool, frequ
return
true
return
true
}
}
// ShouldNotify checks this evaluation should send an alert notification
func
(
n
*
NotifierBase
)
ShouldNotify
(
ctx
context
.
Context
,
c
*
alerting
.
EvalContext
,
notiferState
*
models
.
AlertNotificationState
)
bool
{
return
defaultShouldNotify
(
c
,
n
.
SendReminder
,
n
.
Frequency
,
notiferState
)
}
func
(
n
*
NotifierBase
)
GetType
()
string
{
func
(
n
*
NotifierBase
)
GetType
()
string
{
return
n
.
Type
return
n
.
Type
}
}
...
...
pkg/services/alerting/notifiers/base_test.go
View file @
9289cba6
...
@@ -142,7 +142,9 @@ func TestShouldSendAlertNotification(t *testing.T) {
...
@@ -142,7 +142,9 @@ func TestShouldSendAlertNotification(t *testing.T) {
})
})
evalContext
.
Rule
.
State
=
tc
.
newState
evalContext
.
Rule
.
State
=
tc
.
newState
if
defaultShouldNotify
(
evalContext
,
tc
.
sendReminder
,
tc
.
frequency
,
tc
.
state
)
!=
tc
.
expect
{
nb
:=
&
NotifierBase
{
SendReminder
:
tc
.
sendReminder
,
Frequency
:
tc
.
frequency
}
if
nb
.
ShouldNotify
(
evalContext
.
Ctx
,
evalContext
,
tc
.
state
)
!=
tc
.
expect
{
t
.
Errorf
(
"failed test %s.
\n
expected
\n
%+v
\n
to return: %v"
,
tc
.
name
,
tc
,
tc
.
expect
)
t
.
Errorf
(
"failed test %s.
\n
expected
\n
%+v
\n
to return: %v"
,
tc
.
name
,
tc
,
tc
.
expect
)
}
}
}
}
...
...
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