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
7f1d7cef
Commit
7f1d7cef
authored
Oct 02, 2018
by
bergquist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
reminder: uses UpdatedAt to track state changes.
parent
9e09b2b9
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
14 additions
and
18 deletions
+14
-18
pkg/models/alert_notifications.go
+2
-1
pkg/services/alerting/notifier.go
+2
-2
pkg/services/alerting/notifiers/base.go
+2
-2
pkg/services/alerting/notifiers/base_test.go
+3
-3
pkg/services/alerting/rule.go
+1
-0
pkg/services/sqlstore/alert_notification.go
+3
-5
pkg/services/sqlstore/migrations/alert_mig.go
+1
-5
No files found.
pkg/models/alert_notifications.go
View file @
7f1d7cef
...
...
@@ -19,6 +19,7 @@ type AlertNotificationStateType string
var
(
AlertNotificationStatePending
=
AlertNotificationStateType
(
"pending"
)
AlertNotificationStateCompleted
=
AlertNotificationStateType
(
"completed"
)
AlertNotificationStateUnknown
=
AlertNotificationStateType
(
"unknown"
)
)
type
AlertNotification
struct
{
...
...
@@ -90,10 +91,10 @@ type AlertNotificationState struct {
OrgId
int64
AlertId
int64
NotifierId
int64
SentAt
int64
State
AlertNotificationStateType
Version
int64
UpdatedAt
int64
AlertRuleStateUpdatedVersion
int64
}
type
SetAlertNotificationStateToPendingCommand
struct
{
...
...
pkg/services/alerting/notifier.go
View file @
7f1d7cef
...
...
@@ -68,7 +68,7 @@ func (n *notificationService) sendAndMarkAsComplete(evalContext *EvalContext, no
if
err
!=
nil
{
n
.
log
.
Error
(
"failed to send notification"
,
"id"
,
not
.
GetNotifierId
())
}
else
{
notifierState
.
state
.
Sent
At
=
time
.
Now
()
.
UTC
()
.
Unix
()
notifierState
.
state
.
Updated
At
=
time
.
Now
()
.
UTC
()
.
Unix
()
}
if
evalContext
.
IsTestRun
{
...
...
@@ -185,7 +185,7 @@ func (n *notificationService) getNeededNotifiers(orgId int64, notificationIds []
err
=
bus
.
DispatchCtx
(
evalContext
.
Ctx
,
query
)
if
err
!=
nil
{
n
.
log
.
Error
(
"Could not get notification state."
,
"notifier"
,
notification
.
Id
)
n
.
log
.
Error
(
"Could not get notification state."
,
"notifier"
,
notification
.
Id
,
"error"
,
err
)
continue
}
...
...
pkg/services/alerting/notifiers/base.go
View file @
7f1d7cef
...
...
@@ -53,8 +53,8 @@ func defaultShouldNotify(context *alerting.EvalContext, sendReminder bool, frequ
if
context
.
PrevAlertState
==
context
.
Rule
.
State
&&
sendReminder
{
// Do not notify if interval has not elapsed
lastNotify
:=
time
.
Unix
(
notificationState
.
Sent
At
,
0
)
if
notificationState
.
Sent
At
!=
0
&&
lastNotify
.
Add
(
frequency
)
.
After
(
time
.
Now
())
{
lastNotify
:=
time
.
Unix
(
notificationState
.
Updated
At
,
0
)
if
notificationState
.
Updated
At
!=
0
&&
lastNotify
.
Add
(
frequency
)
.
After
(
time
.
Now
())
{
return
false
}
...
...
pkg/services/alerting/notifiers/base_test.go
View file @
7f1d7cef
...
...
@@ -84,7 +84,7 @@ func TestShouldSendAlertNotification(t *testing.T) {
prevState
:
m
.
AlertStateAlerting
,
frequency
:
time
.
Minute
*
10
,
sendReminder
:
true
,
state
:
&
m
.
AlertNotificationState
{
Sent
At
:
tnow
.
Add
(
-
time
.
Minute
)
.
Unix
()},
state
:
&
m
.
AlertNotificationState
{
Updated
At
:
tnow
.
Add
(
-
time
.
Minute
)
.
Unix
()},
expect
:
true
,
},
...
...
@@ -104,7 +104,7 @@ func TestShouldSendAlertNotification(t *testing.T) {
prevState
:
m
.
AlertStateAlerting
,
frequency
:
time
.
Minute
*
10
,
sendReminder
:
true
,
state
:
&
m
.
AlertNotificationState
{
Sent
At
:
tnow
.
Add
(
-
time
.
Minute
)
.
Unix
()},
state
:
&
m
.
AlertNotificationState
{
Updated
At
:
tnow
.
Add
(
-
time
.
Minute
)
.
Unix
()},
expect
:
false
,
},
...
...
@@ -114,7 +114,7 @@ func TestShouldSendAlertNotification(t *testing.T) {
prevState
:
m
.
AlertStateAlerting
,
frequency
:
time
.
Minute
*
10
,
sendReminder
:
true
,
state
:
&
m
.
AlertNotificationState
{
Sent
At
:
tnow
.
Add
(
-
11
*
time
.
Minute
)
.
Unix
()},
state
:
&
m
.
AlertNotificationState
{
Updated
At
:
tnow
.
Add
(
-
11
*
time
.
Minute
)
.
Unix
()},
expect
:
true
,
},
...
...
pkg/services/alerting/rule.go
View file @
7f1d7cef
...
...
@@ -102,6 +102,7 @@ func NewRuleFromDBAlert(ruleDef *m.Alert) (*Rule, error) {
model
.
State
=
ruleDef
.
State
model
.
NoDataState
=
m
.
NoDataOption
(
ruleDef
.
Settings
.
Get
(
"noDataState"
)
.
MustString
(
"no_data"
))
model
.
ExecutionErrorState
=
m
.
ExecutionErrorOption
(
ruleDef
.
Settings
.
Get
(
"executionErrorState"
)
.
MustString
(
"alerting"
))
model
.
StateChanges
=
ruleDef
.
StateChanges
for
_
,
v
:=
range
ruleDef
.
Settings
.
Get
(
"notifications"
)
.
MustArray
()
{
jsonModel
:=
simplejson
.
NewFromAny
(
v
)
...
...
pkg/services/sqlstore/alert_notification.go
View file @
7f1d7cef
...
...
@@ -249,12 +249,11 @@ func SetAlertNotificationStateToCompleteCommand(ctx context.Context, cmd *m.SetA
sql
:=
`UPDATE alert_notification_state SET
state = ?,
version = ?,
sent_at = ?,
updated_at = ?
WHERE
id = ?`
_
,
err
:=
sess
.
Exec
(
sql
,
cmd
.
State
.
State
,
cmd
.
State
.
Version
,
cmd
.
State
.
SentAt
,
timeNow
()
.
Unix
(),
cmd
.
State
.
Id
)
_
,
err
:=
sess
.
Exec
(
sql
,
cmd
.
State
.
State
,
cmd
.
State
.
Version
,
timeNow
()
.
Unix
(),
cmd
.
State
.
Id
)
if
err
!=
nil
{
return
err
...
...
@@ -325,7 +324,7 @@ func GetAlertNotificationState(ctx context.Context, cmd *m.GetNotificationStateQ
OrgId
:
cmd
.
OrgId
,
AlertId
:
cmd
.
AlertId
,
NotifierId
:
cmd
.
NotifierId
,
State
:
"unknown"
,
State
:
m
.
AlertNotificationStateUnknown
,
UpdatedAt
:
timeNow
()
.
Unix
(),
}
...
...
@@ -354,10 +353,9 @@ func GetAlertNotificationState(ctx context.Context, cmd *m.GetNotificationStateQ
}
func
getAlertNotificationState
(
sess
*
DBSession
,
cmd
*
m
.
GetNotificationStateQuery
,
nj
*
m
.
AlertNotificationState
)
(
bool
,
error
)
{
exist
,
err
:=
sess
.
return
sess
.
Where
(
"alert_notification_state.org_id = ?"
,
cmd
.
OrgId
)
.
Where
(
"alert_notification_state.alert_id = ?"
,
cmd
.
AlertId
)
.
Where
(
"alert_notification_state.notifier_id = ?"
,
cmd
.
NotifierId
)
.
Get
(
nj
)
return
exist
,
err
}
pkg/services/sqlstore/migrations/alert_mig.go
View file @
7f1d7cef
...
...
@@ -117,10 +117,10 @@ func addAlertMigrations(mg *Migrator) {
{
Name
:
"org_id"
,
Type
:
DB_BigInt
,
Nullable
:
false
},
{
Name
:
"alert_id"
,
Type
:
DB_BigInt
,
Nullable
:
false
},
{
Name
:
"notifier_id"
,
Type
:
DB_BigInt
,
Nullable
:
false
},
{
Name
:
"sent_at"
,
Type
:
DB_BigInt
,
Nullable
:
false
},
{
Name
:
"state"
,
Type
:
DB_NVarchar
,
Length
:
50
,
Nullable
:
false
},
{
Name
:
"version"
,
Type
:
DB_BigInt
,
Nullable
:
false
},
{
Name
:
"updated_at"
,
Type
:
DB_BigInt
,
Nullable
:
false
},
{
Name
:
"alert_rule_state_updated_version"
,
Type
:
DB_BigInt
,
Nullable
:
false
},
},
Indices
:
[]
*
Index
{
{
Cols
:
[]
string
{
"org_id"
,
"alert_id"
,
"notifier_id"
},
Type
:
UniqueIndex
},
...
...
@@ -130,8 +130,4 @@ func addAlertMigrations(mg *Migrator) {
mg
.
AddMigration
(
"create alert_notification_state table v1"
,
NewAddTableMigration
(
alert_notification_state
))
mg
.
AddMigration
(
"add index alert_notification_state org_id & alert_id & notifier_id"
,
NewAddIndexMigration
(
alert_notification_state
,
alert_notification_state
.
Indices
[
0
]))
mg
.
AddMigration
(
"Add alert_rule_state_updated_version to alert_notification_state"
,
NewAddColumnMigration
(
alert_notification_state
,
&
Column
{
Name
:
"alert_rule_state_updated_version"
,
Type
:
DB_BigInt
,
Nullable
:
true
,
}))
}
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