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
d4d2b6d7
Commit
d4d2b6d7
authored
Mar 15, 2018
by
Corentin Chary
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
notitfiers: avoid ShouldNotify duplication
parent
777c1024
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
7 additions
and
60 deletions
+7
-60
pkg/services/alerting/notifiers/base.go
+6
-0
pkg/services/alerting/notifiers/dingding.go
+0
-4
pkg/services/alerting/notifiers/email.go
+0
-4
pkg/services/alerting/notifiers/hipchat.go
+0
-4
pkg/services/alerting/notifiers/kafka.go
+0
-4
pkg/services/alerting/notifiers/line.go
+0
-4
pkg/services/alerting/notifiers/opsgenie.go
+0
-4
pkg/services/alerting/notifiers/pagerduty.go
+0
-4
pkg/services/alerting/notifiers/pushover.go
+0
-4
pkg/services/alerting/notifiers/sensu.go
+0
-4
pkg/services/alerting/notifiers/slack.go
+0
-4
pkg/services/alerting/notifiers/teams.go
+0
-4
pkg/services/alerting/notifiers/telegram.go
+1
-4
pkg/services/alerting/notifiers/threema.go
+0
-4
pkg/services/alerting/notifiers/victorops.go
+0
-4
pkg/services/alerting/notifiers/webhook.go
+0
-4
No files found.
pkg/services/alerting/notifiers/base.go
View file @
d4d2b6d7
...
@@ -27,15 +27,21 @@ func NewNotifierBase(id int64, isDefault bool, name, notifierType string, model
...
@@ -27,15 +27,21 @@ func NewNotifierBase(id int64, isDefault bool, name, notifierType string, model
}
}
func
defaultShouldNotify
(
context
*
alerting
.
EvalContext
)
bool
{
func
defaultShouldNotify
(
context
*
alerting
.
EvalContext
)
bool
{
// Only notify on state change.
if
context
.
PrevAlertState
==
context
.
Rule
.
State
{
if
context
.
PrevAlertState
==
context
.
Rule
.
State
{
return
false
return
false
}
}
// Do not notify when we become OK for the first time.
if
(
context
.
PrevAlertState
==
m
.
AlertStatePending
)
&&
(
context
.
Rule
.
State
==
m
.
AlertStateOK
)
{
if
(
context
.
PrevAlertState
==
m
.
AlertStatePending
)
&&
(
context
.
Rule
.
State
==
m
.
AlertStateOK
)
{
return
false
return
false
}
}
return
true
return
true
}
}
func
(
n
*
NotifierBase
)
ShouldNotify
(
context
*
alerting
.
EvalContext
)
bool
{
return
defaultShouldNotify
(
context
)
}
func
(
n
*
NotifierBase
)
GetType
()
string
{
func
(
n
*
NotifierBase
)
GetType
()
string
{
return
n
.
Type
return
n
.
Type
}
}
...
...
pkg/services/alerting/notifiers/dingding.go
View file @
d4d2b6d7
...
@@ -38,10 +38,6 @@ func NewDingDingNotifier(model *m.AlertNotification) (alerting.Notifier, error)
...
@@ -38,10 +38,6 @@ func NewDingDingNotifier(model *m.AlertNotification) (alerting.Notifier, error)
},
nil
},
nil
}
}
func
(
this
*
DingDingNotifier
)
ShouldNotify
(
context
*
alerting
.
EvalContext
)
bool
{
return
defaultShouldNotify
(
context
)
}
type
DingDingNotifier
struct
{
type
DingDingNotifier
struct
{
NotifierBase
NotifierBase
Url
string
Url
string
...
...
pkg/services/alerting/notifiers/email.go
View file @
d4d2b6d7
...
@@ -58,10 +58,6 @@ func NewEmailNotifier(model *m.AlertNotification) (alerting.Notifier, error) {
...
@@ -58,10 +58,6 @@ func NewEmailNotifier(model *m.AlertNotification) (alerting.Notifier, error) {
},
nil
},
nil
}
}
func
(
this
*
EmailNotifier
)
ShouldNotify
(
context
*
alerting
.
EvalContext
)
bool
{
return
defaultShouldNotify
(
context
)
}
func
(
this
*
EmailNotifier
)
Notify
(
evalContext
*
alerting
.
EvalContext
)
error
{
func
(
this
*
EmailNotifier
)
Notify
(
evalContext
*
alerting
.
EvalContext
)
error
{
this
.
log
.
Info
(
"Sending alert notification to"
,
"addresses"
,
this
.
Addresses
)
this
.
log
.
Info
(
"Sending alert notification to"
,
"addresses"
,
this
.
Addresses
)
...
...
pkg/services/alerting/notifiers/hipchat.go
View file @
d4d2b6d7
...
@@ -75,10 +75,6 @@ type HipChatNotifier struct {
...
@@ -75,10 +75,6 @@ type HipChatNotifier struct {
log
log
.
Logger
log
log
.
Logger
}
}
func
(
this
*
HipChatNotifier
)
ShouldNotify
(
context
*
alerting
.
EvalContext
)
bool
{
return
defaultShouldNotify
(
context
)
}
func
(
this
*
HipChatNotifier
)
Notify
(
evalContext
*
alerting
.
EvalContext
)
error
{
func
(
this
*
HipChatNotifier
)
Notify
(
evalContext
*
alerting
.
EvalContext
)
error
{
this
.
log
.
Info
(
"Executing hipchat notification"
,
"ruleId"
,
evalContext
.
Rule
.
Id
,
"notification"
,
this
.
Name
)
this
.
log
.
Info
(
"Executing hipchat notification"
,
"ruleId"
,
evalContext
.
Rule
.
Id
,
"notification"
,
this
.
Name
)
...
...
pkg/services/alerting/notifiers/kafka.go
View file @
d4d2b6d7
...
@@ -57,10 +57,6 @@ type KafkaNotifier struct {
...
@@ -57,10 +57,6 @@ type KafkaNotifier struct {
log
log
.
Logger
log
log
.
Logger
}
}
func
(
this
*
KafkaNotifier
)
ShouldNotify
(
context
*
alerting
.
EvalContext
)
bool
{
return
defaultShouldNotify
(
context
)
}
func
(
this
*
KafkaNotifier
)
Notify
(
evalContext
*
alerting
.
EvalContext
)
error
{
func
(
this
*
KafkaNotifier
)
Notify
(
evalContext
*
alerting
.
EvalContext
)
error
{
state
:=
evalContext
.
Rule
.
State
state
:=
evalContext
.
Rule
.
State
...
...
pkg/services/alerting/notifiers/line.go
View file @
d4d2b6d7
...
@@ -51,10 +51,6 @@ type LineNotifier struct {
...
@@ -51,10 +51,6 @@ type LineNotifier struct {
log
log
.
Logger
log
log
.
Logger
}
}
func
(
this
*
LineNotifier
)
ShouldNotify
(
context
*
alerting
.
EvalContext
)
bool
{
return
defaultShouldNotify
(
context
)
}
func
(
this
*
LineNotifier
)
Notify
(
evalContext
*
alerting
.
EvalContext
)
error
{
func
(
this
*
LineNotifier
)
Notify
(
evalContext
*
alerting
.
EvalContext
)
error
{
this
.
log
.
Info
(
"Executing line notification"
,
"ruleId"
,
evalContext
.
Rule
.
Id
,
"notification"
,
this
.
Name
)
this
.
log
.
Info
(
"Executing line notification"
,
"ruleId"
,
evalContext
.
Rule
.
Id
,
"notification"
,
this
.
Name
)
...
...
pkg/services/alerting/notifiers/opsgenie.go
View file @
d4d2b6d7
...
@@ -72,10 +72,6 @@ type OpsGenieNotifier struct {
...
@@ -72,10 +72,6 @@ type OpsGenieNotifier struct {
log
log
.
Logger
log
log
.
Logger
}
}
func
(
this
*
OpsGenieNotifier
)
ShouldNotify
(
context
*
alerting
.
EvalContext
)
bool
{
return
defaultShouldNotify
(
context
)
}
func
(
this
*
OpsGenieNotifier
)
Notify
(
evalContext
*
alerting
.
EvalContext
)
error
{
func
(
this
*
OpsGenieNotifier
)
Notify
(
evalContext
*
alerting
.
EvalContext
)
error
{
var
err
error
var
err
error
...
...
pkg/services/alerting/notifiers/pagerduty.go
View file @
d4d2b6d7
...
@@ -65,10 +65,6 @@ type PagerdutyNotifier struct {
...
@@ -65,10 +65,6 @@ type PagerdutyNotifier struct {
log
log
.
Logger
log
log
.
Logger
}
}
func
(
this
*
PagerdutyNotifier
)
ShouldNotify
(
context
*
alerting
.
EvalContext
)
bool
{
return
defaultShouldNotify
(
context
)
}
func
(
this
*
PagerdutyNotifier
)
Notify
(
evalContext
*
alerting
.
EvalContext
)
error
{
func
(
this
*
PagerdutyNotifier
)
Notify
(
evalContext
*
alerting
.
EvalContext
)
error
{
if
evalContext
.
Rule
.
State
==
m
.
AlertStateOK
&&
!
this
.
AutoResolve
{
if
evalContext
.
Rule
.
State
==
m
.
AlertStateOK
&&
!
this
.
AutoResolve
{
...
...
pkg/services/alerting/notifiers/pushover.go
View file @
d4d2b6d7
...
@@ -123,10 +123,6 @@ type PushoverNotifier struct {
...
@@ -123,10 +123,6 @@ type PushoverNotifier struct {
log
log
.
Logger
log
log
.
Logger
}
}
func
(
this
*
PushoverNotifier
)
ShouldNotify
(
context
*
alerting
.
EvalContext
)
bool
{
return
defaultShouldNotify
(
context
)
}
func
(
this
*
PushoverNotifier
)
Notify
(
evalContext
*
alerting
.
EvalContext
)
error
{
func
(
this
*
PushoverNotifier
)
Notify
(
evalContext
*
alerting
.
EvalContext
)
error
{
ruleUrl
,
err
:=
evalContext
.
GetRuleUrl
()
ruleUrl
,
err
:=
evalContext
.
GetRuleUrl
()
if
err
!=
nil
{
if
err
!=
nil
{
...
...
pkg/services/alerting/notifiers/sensu.go
View file @
d4d2b6d7
...
@@ -71,10 +71,6 @@ type SensuNotifier struct {
...
@@ -71,10 +71,6 @@ type SensuNotifier struct {
log
log
.
Logger
log
log
.
Logger
}
}
func
(
this
*
SensuNotifier
)
ShouldNotify
(
context
*
alerting
.
EvalContext
)
bool
{
return
defaultShouldNotify
(
context
)
}
func
(
this
*
SensuNotifier
)
Notify
(
evalContext
*
alerting
.
EvalContext
)
error
{
func
(
this
*
SensuNotifier
)
Notify
(
evalContext
*
alerting
.
EvalContext
)
error
{
this
.
log
.
Info
(
"Sending sensu result"
)
this
.
log
.
Info
(
"Sending sensu result"
)
...
...
pkg/services/alerting/notifiers/slack.go
View file @
d4d2b6d7
...
@@ -98,10 +98,6 @@ type SlackNotifier struct {
...
@@ -98,10 +98,6 @@ type SlackNotifier struct {
log
log
.
Logger
log
log
.
Logger
}
}
func
(
this
*
SlackNotifier
)
ShouldNotify
(
context
*
alerting
.
EvalContext
)
bool
{
return
defaultShouldNotify
(
context
)
}
func
(
this
*
SlackNotifier
)
Notify
(
evalContext
*
alerting
.
EvalContext
)
error
{
func
(
this
*
SlackNotifier
)
Notify
(
evalContext
*
alerting
.
EvalContext
)
error
{
this
.
log
.
Info
(
"Executing slack notification"
,
"ruleId"
,
evalContext
.
Rule
.
Id
,
"notification"
,
this
.
Name
)
this
.
log
.
Info
(
"Executing slack notification"
,
"ruleId"
,
evalContext
.
Rule
.
Id
,
"notification"
,
this
.
Name
)
...
...
pkg/services/alerting/notifiers/teams.go
View file @
d4d2b6d7
...
@@ -47,10 +47,6 @@ type TeamsNotifier struct {
...
@@ -47,10 +47,6 @@ type TeamsNotifier struct {
log
log
.
Logger
log
log
.
Logger
}
}
func
(
this
*
TeamsNotifier
)
ShouldNotify
(
context
*
alerting
.
EvalContext
)
bool
{
return
defaultShouldNotify
(
context
)
}
func
(
this
*
TeamsNotifier
)
Notify
(
evalContext
*
alerting
.
EvalContext
)
error
{
func
(
this
*
TeamsNotifier
)
Notify
(
evalContext
*
alerting
.
EvalContext
)
error
{
this
.
log
.
Info
(
"Executing teams notification"
,
"ruleId"
,
evalContext
.
Rule
.
Id
,
"notification"
,
this
.
Name
)
this
.
log
.
Info
(
"Executing teams notification"
,
"ruleId"
,
evalContext
.
Rule
.
Id
,
"notification"
,
this
.
Name
)
...
...
pkg/services/alerting/notifiers/telegram.go
View file @
d4d2b6d7
...
@@ -208,6 +208,7 @@ func generateImageCaption(evalContext *alerting.EvalContext, ruleUrl string, met
...
@@ -208,6 +208,7 @@ func generateImageCaption(evalContext *alerting.EvalContext, ruleUrl string, met
return
message
return
message
}
}
func
appendIfPossible
(
message
string
,
extra
string
,
sizeLimit
int
)
string
{
func
appendIfPossible
(
message
string
,
extra
string
,
sizeLimit
int
)
string
{
if
len
(
extra
)
+
len
(
message
)
<=
sizeLimit
{
if
len
(
extra
)
+
len
(
message
)
<=
sizeLimit
{
return
message
+
extra
return
message
+
extra
...
@@ -216,10 +217,6 @@ func appendIfPossible(message string, extra string, sizeLimit int) string {
...
@@ -216,10 +217,6 @@ func appendIfPossible(message string, extra string, sizeLimit int) string {
return
message
return
message
}
}
func
(
this
*
TelegramNotifier
)
ShouldNotify
(
context
*
alerting
.
EvalContext
)
bool
{
return
defaultShouldNotify
(
context
)
}
func
(
this
*
TelegramNotifier
)
Notify
(
evalContext
*
alerting
.
EvalContext
)
error
{
func
(
this
*
TelegramNotifier
)
Notify
(
evalContext
*
alerting
.
EvalContext
)
error
{
var
cmd
*
m
.
SendWebhookSync
var
cmd
*
m
.
SendWebhookSync
if
evalContext
.
ImagePublicUrl
==
""
&&
this
.
UploadImage
==
true
{
if
evalContext
.
ImagePublicUrl
==
""
&&
this
.
UploadImage
==
true
{
...
...
pkg/services/alerting/notifiers/threema.go
View file @
d4d2b6d7
...
@@ -114,10 +114,6 @@ func NewThreemaNotifier(model *m.AlertNotification) (alerting.Notifier, error) {
...
@@ -114,10 +114,6 @@ func NewThreemaNotifier(model *m.AlertNotification) (alerting.Notifier, error) {
},
nil
},
nil
}
}
func
(
this
*
ThreemaNotifier
)
ShouldNotify
(
context
*
alerting
.
EvalContext
)
bool
{
return
defaultShouldNotify
(
context
)
}
func
(
notifier
*
ThreemaNotifier
)
Notify
(
evalContext
*
alerting
.
EvalContext
)
error
{
func
(
notifier
*
ThreemaNotifier
)
Notify
(
evalContext
*
alerting
.
EvalContext
)
error
{
notifier
.
log
.
Info
(
"Sending alert notification from"
,
"threema_id"
,
notifier
.
GatewayID
)
notifier
.
log
.
Info
(
"Sending alert notification from"
,
"threema_id"
,
notifier
.
GatewayID
)
notifier
.
log
.
Info
(
"Sending alert notification to"
,
"threema_id"
,
notifier
.
RecipientID
)
notifier
.
log
.
Info
(
"Sending alert notification to"
,
"threema_id"
,
notifier
.
RecipientID
)
...
...
pkg/services/alerting/notifiers/victorops.go
View file @
d4d2b6d7
...
@@ -68,10 +68,6 @@ type VictoropsNotifier struct {
...
@@ -68,10 +68,6 @@ type VictoropsNotifier struct {
log
log
.
Logger
log
log
.
Logger
}
}
func
(
this
*
VictoropsNotifier
)
ShouldNotify
(
context
*
alerting
.
EvalContext
)
bool
{
return
defaultShouldNotify
(
context
)
}
// Notify sends notification to Victorops via POST to URL endpoint
// Notify sends notification to Victorops via POST to URL endpoint
func
(
this
*
VictoropsNotifier
)
Notify
(
evalContext
*
alerting
.
EvalContext
)
error
{
func
(
this
*
VictoropsNotifier
)
Notify
(
evalContext
*
alerting
.
EvalContext
)
error
{
this
.
log
.
Info
(
"Executing victorops notification"
,
"ruleId"
,
evalContext
.
Rule
.
Id
,
"notification"
,
this
.
Name
)
this
.
log
.
Info
(
"Executing victorops notification"
,
"ruleId"
,
evalContext
.
Rule
.
Id
,
"notification"
,
this
.
Name
)
...
...
pkg/services/alerting/notifiers/webhook.go
View file @
d4d2b6d7
...
@@ -65,10 +65,6 @@ type WebhookNotifier struct {
...
@@ -65,10 +65,6 @@ type WebhookNotifier struct {
log
log
.
Logger
log
log
.
Logger
}
}
func
(
this
*
WebhookNotifier
)
ShouldNotify
(
context
*
alerting
.
EvalContext
)
bool
{
return
defaultShouldNotify
(
context
)
}
func
(
this
*
WebhookNotifier
)
Notify
(
evalContext
*
alerting
.
EvalContext
)
error
{
func
(
this
*
WebhookNotifier
)
Notify
(
evalContext
*
alerting
.
EvalContext
)
error
{
this
.
log
.
Info
(
"Sending webhook"
)
this
.
log
.
Info
(
"Sending webhook"
)
...
...
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