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
8551ffa0
Unverified
Commit
8551ffa0
authored
Sep 28, 2018
by
Marcus Efraimsson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
alert -> ok with reminders enabled should send
parent
a0e1a1a1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
31 deletions
+49
-31
pkg/services/alerting/notifiers/base.go
+11
-4
pkg/services/alerting/notifiers/base_test.go
+38
-27
No files found.
pkg/services/alerting/notifiers/base.go
View file @
8551ffa0
...
...
@@ -51,19 +51,26 @@ func defaultShouldNotify(context *alerting.EvalContext, sendReminder bool, frequ
return
false
}
if
context
.
PrevAlertState
==
context
.
Rule
.
State
&&
sendReminder
{
// Do not notify if interval has not elapsed
lastNotify
:=
time
.
Unix
(
notificationState
.
SentAt
,
0
)
if
sendReminder
&&
!
lastNotify
.
IsZero
()
&&
lastNotify
.
Add
(
frequency
)
.
After
(
time
.
Now
())
{
if
!
lastNotify
.
IsZero
()
&&
lastNotify
.
Add
(
frequency
)
.
After
(
time
.
Now
())
{
return
false
}
// Do not notify if alert state if
OK or pending even on repeated notify
if
sendReminder
&&
(
context
.
Rule
.
State
==
models
.
AlertStateOK
||
context
.
Rule
.
State
==
models
.
AlertStatePending
)
{
// Do not notify if alert state is
OK or pending even on repeated notify
if
context
.
Rule
.
State
==
models
.
AlertStateOK
||
context
.
Rule
.
State
==
models
.
AlertStatePending
{
return
false
}
}
// Do not notify when we become OK for the first time.
if
(
context
.
PrevAlertState
==
models
.
AlertStatePending
)
&&
(
context
.
Rule
.
State
==
models
.
AlertStateOK
)
{
if
context
.
PrevAlertState
==
models
.
AlertStatePending
&&
context
.
Rule
.
State
==
models
.
AlertStateOK
{
return
false
}
// Do not notify when we OK -> Pending
if
context
.
PrevAlertState
==
models
.
AlertStateOK
&&
context
.
Rule
.
State
==
models
.
AlertStatePending
{
return
false
}
...
...
pkg/services/alerting/notifiers/base_test.go
View file @
8551ffa0
...
...
@@ -20,34 +20,34 @@ func TestShouldSendAlertNotification(t *testing.T) {
newState
m
.
AlertStateType
sendReminder
bool
frequency
time
.
Duration
journals
*
m
.
AlertNotificationState
state
*
m
.
AlertNotificationState
expect
bool
}{
{
name
:
"pending -> ok should not trigger an notification"
,
newState
:
m
.
AlertState
Pending
,
prevState
:
m
.
AlertState
OK
,
newState
:
m
.
AlertState
OK
,
prevState
:
m
.
AlertState
Pending
,
sendReminder
:
false
,
journals
:
&
m
.
AlertNotificationState
{},
state
:
&
m
.
AlertNotificationState
{},
expect
:
false
,
},
{
name
:
"ok -> alerting should trigger an notification"
,
newState
:
m
.
AlertState
OK
,
prevState
:
m
.
AlertState
Alerting
,
newState
:
m
.
AlertState
Alerting
,
prevState
:
m
.
AlertState
OK
,
sendReminder
:
false
,
journals
:
&
m
.
AlertNotificationState
{},
state
:
&
m
.
AlertNotificationState
{},
expect
:
true
,
},
{
name
:
"ok -> pending should not trigger an notification"
,
newState
:
m
.
AlertState
OK
,
prevState
:
m
.
AlertState
Pending
,
newState
:
m
.
AlertState
Pending
,
prevState
:
m
.
AlertState
OK
,
sendReminder
:
false
,
journals
:
&
m
.
AlertNotificationState
{},
state
:
&
m
.
AlertNotificationState
{},
expect
:
false
,
},
...
...
@@ -56,66 +56,77 @@ func TestShouldSendAlertNotification(t *testing.T) {
newState
:
m
.
AlertStateOK
,
prevState
:
m
.
AlertStateOK
,
sendReminder
:
false
,
journals
:
&
m
.
AlertNotificationState
{},
state
:
&
m
.
AlertNotificationState
{},
expect
:
false
,
},
{
name
:
"ok ->
alerting should
trigger an notification"
,
name
:
"ok ->
ok with reminder should not
trigger an notification"
,
newState
:
m
.
AlertStateOK
,
prevState
:
m
.
AlertState
Alerting
,
prevState
:
m
.
AlertState
OK
,
sendReminder
:
true
,
journals
:
&
m
.
AlertNotificationState
{},
state
:
&
m
.
AlertNotificationState
{},
expect
:
false
,
},
{
name
:
"alerting -> ok should trigger an notification"
,
newState
:
m
.
AlertStateOK
,
prevState
:
m
.
AlertStateAlerting
,
sendReminder
:
false
,
state
:
&
m
.
AlertNotificationState
{},
expect
:
true
,
},
{
name
:
"
ok -> ok with reminder should not trigger an notification
"
,
name
:
"
alerting -> ok should trigger an notification when reminders enabled
"
,
newState
:
m
.
AlertStateOK
,
prevState
:
m
.
AlertStateOK
,
prevState
:
m
.
AlertStateAlerting
,
frequency
:
time
.
Minute
*
10
,
sendReminder
:
true
,
journals
:
&
m
.
AlertNotificationState
{
},
state
:
&
m
.
AlertNotificationState
{
SentAt
:
tnow
.
Add
(
-
time
.
Minute
)
.
Unix
()
},
expect
:
fals
e
,
expect
:
tru
e
,
},
{
name
:
"alerting -> alerting with reminder and no
journaling
should trigger"
,
name
:
"alerting -> alerting with reminder and no
state
should trigger"
,
newState
:
m
.
AlertStateAlerting
,
prevState
:
m
.
AlertStateAlerting
,
frequency
:
time
.
Minute
*
10
,
sendReminder
:
true
,
journals
:
&
m
.
AlertNotificationState
{},
state
:
&
m
.
AlertNotificationState
{},
expect
:
true
,
},
{
name
:
"alerting -> alerting with reminder and
successful recent journal event
should not trigger"
,
name
:
"alerting -> alerting with reminder and
last notification sent 1 minute ago
should not trigger"
,
newState
:
m
.
AlertStateAlerting
,
prevState
:
m
.
AlertStateAlerting
,
frequency
:
time
.
Minute
*
10
,
sendReminder
:
true
,
journals
:
&
m
.
AlertNotificationState
{
SentAt
:
tnow
.
Add
(
-
time
.
Minute
)
.
Unix
()},
state
:
&
m
.
AlertNotificationState
{
SentAt
:
tnow
.
Add
(
-
time
.
Minute
)
.
Unix
()},
expect
:
false
,
},
{
name
:
"alerting -> alerting with reminder and
failed recent journal event
should trigger"
,
name
:
"alerting -> alerting with reminder and
last notifciation sent 11 minutes ago
should trigger"
,
newState
:
m
.
AlertStateAlerting
,
prevState
:
m
.
AlertStateAlerting
,
frequency
:
time
.
Minute
*
10
,
sendReminder
:
true
,
state
:
&
m
.
AlertNotificationState
{
SentAt
:
tnow
.
Add
(
-
11
*
time
.
Minute
)
.
Unix
()},
expect
:
true
,
journals
:
&
m
.
AlertNotificationState
{
SentAt
:
tnow
.
Add
(
-
time
.
Hour
)
.
Unix
()},
},
}
for
_
,
tc
:=
range
tcs
{
evalContext
:=
alerting
.
NewEvalContext
(
context
.
TODO
(),
&
alerting
.
Rule
{
State
:
tc
.
new
State
,
State
:
tc
.
prev
State
,
})
evalContext
.
Rule
.
State
=
tc
.
prev
State
if
defaultShouldNotify
(
evalContext
,
t
rue
,
tc
.
frequency
,
tc
.
journals
)
!=
tc
.
expect
{
evalContext
.
Rule
.
State
=
tc
.
new
State
if
defaultShouldNotify
(
evalContext
,
t
c
.
sendReminder
,
tc
.
frequency
,
tc
.
state
)
!=
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