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
b45a1bd4
Commit
b45a1bd4
authored
Oct 02, 2018
by
bergquist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
avoid exporting notificationState and notificationStateSlice
parent
9022e871
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
10 additions
and
10 deletions
+10
-10
pkg/services/alerting/interfaces.go
+3
-3
pkg/services/alerting/notifier.go
+6
-6
pkg/services/alerting/test_notification.go
+1
-1
No files found.
pkg/services/alerting/interfaces.go
View file @
b45a1bd4
...
@@ -30,14 +30,14 @@ type Notifier interface {
...
@@ -30,14 +30,14 @@ type Notifier interface {
GetFrequency
()
time
.
Duration
GetFrequency
()
time
.
Duration
}
}
type
N
otifierState
struct
{
type
n
otifierState
struct
{
notifier
Notifier
notifier
Notifier
state
*
models
.
AlertNotificationState
state
*
models
.
AlertNotificationState
}
}
type
NotifierStateSlice
[]
*
N
otifierState
type
notifierStateSlice
[]
*
n
otifierState
func
(
notifiers
N
otifierStateSlice
)
ShouldUploadImage
()
bool
{
func
(
notifiers
n
otifierStateSlice
)
ShouldUploadImage
()
bool
{
for
_
,
ns
:=
range
notifiers
{
for
_
,
ns
:=
range
notifiers
{
if
ns
.
notifier
.
NeedsImage
()
{
if
ns
.
notifier
.
NeedsImage
()
{
return
true
return
true
...
...
pkg/services/alerting/notifier.go
View file @
b45a1bd4
...
@@ -58,7 +58,7 @@ func (n *notificationService) SendIfNeeded(context *EvalContext) error {
...
@@ -58,7 +58,7 @@ func (n *notificationService) SendIfNeeded(context *EvalContext) error {
return
n
.
sendNotifications
(
context
,
notifierStates
)
return
n
.
sendNotifications
(
context
,
notifierStates
)
}
}
func
(
n
*
notificationService
)
sendAndMarkAsComplete
(
evalContext
*
EvalContext
,
notifierState
*
N
otifierState
)
error
{
func
(
n
*
notificationService
)
sendAndMarkAsComplete
(
evalContext
*
EvalContext
,
notifierState
*
n
otifierState
)
error
{
not
:=
notifierState
.
notifier
not
:=
notifierState
.
notifier
n
.
log
.
Debug
(
"Sending notification"
,
"type"
,
not
.
GetType
(),
"id"
,
not
.
GetNotifierId
(),
"isDefault"
,
not
.
GetIsDefault
())
n
.
log
.
Debug
(
"Sending notification"
,
"type"
,
not
.
GetType
(),
"id"
,
not
.
GetNotifierId
(),
"isDefault"
,
not
.
GetIsDefault
())
metrics
.
M_Alerting_Notification_Sent
.
WithLabelValues
(
not
.
GetType
())
.
Inc
()
metrics
.
M_Alerting_Notification_Sent
.
WithLabelValues
(
not
.
GetType
())
.
Inc
()
...
@@ -92,7 +92,7 @@ func (n *notificationService) sendAndMarkAsComplete(evalContext *EvalContext, no
...
@@ -92,7 +92,7 @@ func (n *notificationService) sendAndMarkAsComplete(evalContext *EvalContext, no
return
nil
return
nil
}
}
func
(
n
*
notificationService
)
sendNotification
(
evalContext
*
EvalContext
,
notifierState
*
N
otifierState
)
error
{
func
(
n
*
notificationService
)
sendNotification
(
evalContext
*
EvalContext
,
notifierState
*
n
otifierState
)
error
{
if
!
evalContext
.
IsTestRun
{
if
!
evalContext
.
IsTestRun
{
setPendingCmd
:=
&
m
.
SetAlertNotificationStateToPendingCommand
{
setPendingCmd
:=
&
m
.
SetAlertNotificationStateToPendingCommand
{
Id
:
notifierState
.
state
.
NotifierId
,
Id
:
notifierState
.
state
.
NotifierId
,
...
@@ -117,7 +117,7 @@ func (n *notificationService) sendNotification(evalContext *EvalContext, notifie
...
@@ -117,7 +117,7 @@ func (n *notificationService) sendNotification(evalContext *EvalContext, notifie
return
n
.
sendAndMarkAsComplete
(
evalContext
,
notifierState
)
return
n
.
sendAndMarkAsComplete
(
evalContext
,
notifierState
)
}
}
func
(
n
*
notificationService
)
sendNotifications
(
evalContext
*
EvalContext
,
notifierStates
N
otifierStateSlice
)
error
{
func
(
n
*
notificationService
)
sendNotifications
(
evalContext
*
EvalContext
,
notifierStates
n
otifierStateSlice
)
error
{
for
_
,
notifierState
:=
range
notifierStates
{
for
_
,
notifierState
:=
range
notifierStates
{
err
:=
n
.
sendNotification
(
evalContext
,
notifierState
)
err
:=
n
.
sendNotification
(
evalContext
,
notifierState
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -168,14 +168,14 @@ func (n *notificationService) uploadImage(context *EvalContext) (err error) {
...
@@ -168,14 +168,14 @@ func (n *notificationService) uploadImage(context *EvalContext) (err error) {
return
nil
return
nil
}
}
func
(
n
*
notificationService
)
getNeededNotifiers
(
orgId
int64
,
notificationIds
[]
int64
,
evalContext
*
EvalContext
)
(
N
otifierStateSlice
,
error
)
{
func
(
n
*
notificationService
)
getNeededNotifiers
(
orgId
int64
,
notificationIds
[]
int64
,
evalContext
*
EvalContext
)
(
n
otifierStateSlice
,
error
)
{
query
:=
&
m
.
GetAlertNotificationsToSendQuery
{
OrgId
:
orgId
,
Ids
:
notificationIds
}
query
:=
&
m
.
GetAlertNotificationsToSendQuery
{
OrgId
:
orgId
,
Ids
:
notificationIds
}
if
err
:=
bus
.
Dispatch
(
query
);
err
!=
nil
{
if
err
:=
bus
.
Dispatch
(
query
);
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
var
result
N
otifierStateSlice
var
result
n
otifierStateSlice
for
_
,
notification
:=
range
query
.
Result
{
for
_
,
notification
:=
range
query
.
Result
{
not
,
err
:=
n
.
createNotifierFor
(
notification
)
not
,
err
:=
n
.
createNotifierFor
(
notification
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -196,7 +196,7 @@ func (n *notificationService) getNeededNotifiers(orgId int64, notificationIds []
...
@@ -196,7 +196,7 @@ func (n *notificationService) getNeededNotifiers(orgId int64, notificationIds []
}
}
if
not
.
ShouldNotify
(
evalContext
.
Ctx
,
evalContext
,
query
.
Result
)
{
if
not
.
ShouldNotify
(
evalContext
.
Ctx
,
evalContext
,
query
.
Result
)
{
result
=
append
(
result
,
&
N
otifierState
{
result
=
append
(
result
,
&
n
otifierState
{
notifier
:
not
,
notifier
:
not
,
state
:
query
.
Result
,
state
:
query
.
Result
,
})
})
...
...
pkg/services/alerting/test_notification.go
View file @
b45a1bd4
...
@@ -39,7 +39,7 @@ func handleNotificationTestCommand(cmd *NotificationTestCommand) error {
...
@@ -39,7 +39,7 @@ func handleNotificationTestCommand(cmd *NotificationTestCommand) error {
return
err
return
err
}
}
return
notifier
.
sendNotifications
(
createTestEvalContext
(
cmd
),
N
otifierStateSlice
{{
notifier
:
notifiers
}})
return
notifier
.
sendNotifications
(
createTestEvalContext
(
cmd
),
n
otifierStateSlice
{{
notifier
:
notifiers
}})
}
}
func
createTestEvalContext
(
cmd
*
NotificationTestCommand
)
*
EvalContext
{
func
createTestEvalContext
(
cmd
*
NotificationTestCommand
)
*
EvalContext
{
...
...
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