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
7333d7b8
Commit
7333d7b8
authored
Jun 05, 2018
by
bergquist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
alerting: invert sendOnce to sendReminder
parent
0c6d8398
Hide whitespace changes
Inline
Side-by-side
Showing
28 changed files
with
173 additions
and
148 deletions
+173
-148
pkg/api/dtos/alerting.go
+23
-23
pkg/api/dtos/alerting_test.go
+1
-0
pkg/models/alert_notifications.go
+23
-23
pkg/services/alerting/interfaces.go
+1
-1
pkg/services/alerting/notifiers/alertmanager.go
+1
-1
pkg/services/alerting/notifiers/base.go
+28
-26
pkg/services/alerting/notifiers/base_test.go
+10
-3
pkg/services/alerting/notifiers/dingding.go
+1
-1
pkg/services/alerting/notifiers/discord.go
+1
-1
pkg/services/alerting/notifiers/email.go
+1
-1
pkg/services/alerting/notifiers/hipchat.go
+1
-1
pkg/services/alerting/notifiers/kafka.go
+1
-1
pkg/services/alerting/notifiers/line.go
+1
-1
pkg/services/alerting/notifiers/opsgenie.go
+1
-1
pkg/services/alerting/notifiers/pagerduty.go
+1
-1
pkg/services/alerting/notifiers/pushover.go
+1
-1
pkg/services/alerting/notifiers/sensu.go
+1
-1
pkg/services/alerting/notifiers/slack.go
+1
-1
pkg/services/alerting/notifiers/teams.go
+1
-1
pkg/services/alerting/notifiers/telegram.go
+1
-1
pkg/services/alerting/notifiers/threema.go
+1
-1
pkg/services/alerting/notifiers/victorops.go
+1
-1
pkg/services/alerting/notifiers/webhook.go
+1
-1
pkg/services/sqlstore/alert_notification.go
+16
-16
pkg/services/sqlstore/alert_notification_test.go
+32
-31
pkg/services/sqlstore/migrations/alert_mig.go
+3
-2
public/app/features/alerting/notification_edit_ctrl.ts
+1
-1
public/app/features/alerting/partials/notification_edit.html
+18
-5
No files found.
pkg/api/dtos/alerting.go
View file @
7333d7b8
...
...
@@ -49,28 +49,28 @@ func formatShort(interval time.Duration) string {
func
NewAlertNotification
(
notification
*
models
.
AlertNotification
)
*
AlertNotification
{
return
&
AlertNotification
{
Id
:
notification
.
Id
,
Name
:
notification
.
Name
,
Type
:
notification
.
Type
,
IsDefault
:
notification
.
IsDefault
,
Created
:
notification
.
Created
,
Updated
:
notification
.
Updated
,
Frequency
:
formatShort
(
notification
.
Frequency
),
NotifyOnce
:
notification
.
NotifyOnce
,
Settings
:
notification
.
Settings
,
Id
:
notification
.
Id
,
Name
:
notification
.
Name
,
Type
:
notification
.
Type
,
IsDefault
:
notification
.
IsDefault
,
Created
:
notification
.
Created
,
Updated
:
notification
.
Updated
,
Frequency
:
formatShort
(
notification
.
Frequency
),
SendReminder
:
notification
.
SendReminder
,
Settings
:
notification
.
Settings
,
}
}
type
AlertNotification
struct
{
Id
int64
`json:"id"`
Name
string
`json:"name"`
Type
string
`json:"type"`
IsDefault
bool
`json:"isDefault"`
NotifyOnce
bool
`json:"notifyOnce
"`
Frequency
string
`json:"frequency"`
Created
time
.
Time
`json:"created"`
Updated
time
.
Time
`json:"updated"`
Settings
*
simplejson
.
Json
`json:"settings"`
Id
int64
`json:"id"`
Name
string
`json:"name"`
Type
string
`json:"type"`
IsDefault
bool
`json:"isDefault"`
SendReminder
bool
`json:"sendReminder
"`
Frequency
string
`json:"frequency"`
Created
time
.
Time
`json:"created"`
Updated
time
.
Time
`json:"updated"`
Settings
*
simplejson
.
Json
`json:"settings"`
}
type
AlertTestCommand
struct
{
...
...
@@ -100,11 +100,11 @@ type EvalMatch struct {
}
type
NotificationTestCommand
struct
{
Name
string
`json:"name"`
Type
string
`json:"type"`
NotifyOnce
bool
`json:"notifyOnce
"`
Frequency
string
`json:"frequency"`
Settings
*
simplejson
.
Json
`json:"settings"`
Name
string
`json:"name"`
Type
string
`json:"type"`
SendReminder
bool
`json:"sendReminder
"`
Frequency
string
`json:"frequency"`
Settings
*
simplejson
.
Json
`json:"settings"`
}
type
PauseAlertCommand
struct
{
...
...
pkg/api/dtos/alerting_test.go
View file @
7333d7b8
...
...
@@ -14,6 +14,7 @@ func TestFormatShort(t *testing.T) {
{
interval
:
time
.
Duration
(
time
.
Hour
+
time
.
Minute
),
expected
:
"1h1m"
},
{
interval
:
time
.
Duration
((
time
.
Hour
*
10
)
+
time
.
Minute
),
expected
:
"10h1m"
},
{
interval
:
time
.
Duration
((
time
.
Hour
*
10
)
+
(
time
.
Minute
*
10
)
+
time
.
Second
),
expected
:
"10h10m1s"
},
{
interval
:
time
.
Duration
(
time
.
Minute
*
10
),
expected
:
"10m"
},
}
for
_
,
tc
:=
range
tcs
{
...
...
pkg/models/alert_notifications.go
View file @
7333d7b8
...
...
@@ -12,38 +12,38 @@ var (
)
type
AlertNotification
struct
{
Id
int64
`json:"id"`
OrgId
int64
`json:"-"`
Name
string
`json:"name"`
Type
string
`json:"type"`
NotifyOnce
bool
`json:"notifyOnce
"`
Frequency
time
.
Duration
`json:"frequency"`
IsDefault
bool
`json:"isDefault"`
Settings
*
simplejson
.
Json
`json:"settings"`
Created
time
.
Time
`json:"created"`
Updated
time
.
Time
`json:"updated"`
Id
int64
`json:"id"`
OrgId
int64
`json:"-"`
Name
string
`json:"name"`
Type
string
`json:"type"`
SendReminder
bool
`json:"sendReminder
"`
Frequency
time
.
Duration
`json:"frequency"`
IsDefault
bool
`json:"isDefault"`
Settings
*
simplejson
.
Json
`json:"settings"`
Created
time
.
Time
`json:"created"`
Updated
time
.
Time
`json:"updated"`
}
type
CreateAlertNotificationCommand
struct
{
Name
string
`json:"name" binding:"Required"`
Type
string
`json:"type" binding:"Required"`
NotifyOnce
bool
`json:"notifyOnce
"`
Frequency
string
`json:"frequency"`
IsDefault
bool
`json:"isDefault"`
Settings
*
simplejson
.
Json
`json:"settings"`
Name
string
`json:"name" binding:"Required"`
Type
string
`json:"type" binding:"Required"`
SendReminder
bool
`json:"sendReminder
"`
Frequency
string
`json:"frequency"`
IsDefault
bool
`json:"isDefault"`
Settings
*
simplejson
.
Json
`json:"settings"`
OrgId
int64
`json:"-"`
Result
*
AlertNotification
}
type
UpdateAlertNotificationCommand
struct
{
Id
int64
`json:"id" binding:"Required"`
Name
string
`json:"name" binding:"Required"`
Type
string
`json:"type" binding:"Required"`
NotifyOnce
bool
`json:"notifyOnce
"`
Frequency
string
`json:"frequency"`
IsDefault
bool
`json:"isDefault"`
Settings
*
simplejson
.
Json
`json:"settings" binding:"Required"`
Id
int64
`json:"id" binding:"Required"`
Name
string
`json:"name" binding:"Required"`
Type
string
`json:"type" binding:"Required"`
SendReminder
bool
`json:"sendReminder
"`
Frequency
string
`json:"frequency"`
IsDefault
bool
`json:"isDefault"`
Settings
*
simplejson
.
Json
`json:"settings" binding:"Required"`
OrgId
int64
`json:"-"`
Result
*
AlertNotification
...
...
pkg/services/alerting/interfaces.go
View file @
7333d7b8
...
...
@@ -19,7 +19,7 @@ type Notifier interface {
GetNotifierId
()
int64
GetIsDefault
()
bool
Get
NotifyOnce
()
bool
Get
SendReminder
()
bool
GetFrequency
()
time
.
Duration
}
...
...
pkg/services/alerting/notifiers/alertmanager.go
View file @
7333d7b8
...
...
@@ -33,7 +33,7 @@ func NewAlertmanagerNotifier(model *m.AlertNotification) (alerting.Notifier, err
}
return
&
AlertmanagerNotifier
{
NotifierBase
:
NewNotifierBase
(
model
.
Id
,
model
.
IsDefault
,
model
.
Name
,
model
.
Type
,
model
.
NotifyOnce
,
model
.
Frequency
,
model
.
Settings
),
NotifierBase
:
NewNotifierBase
(
model
),
Url
:
url
,
log
:
log
.
New
(
"alerting.notifier.prometheus-alertmanager"
),
},
nil
...
...
pkg/services/alerting/notifiers/base.go
View file @
7333d7b8
...
...
@@ -3,54 +3,56 @@ package notifiers
import
(
"time"
"github.com/grafana/grafana/pkg/components/simplejson"
m
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/alerting"
)
type
NotifierBase
struct
{
Name
string
Type
string
Id
int64
IsDeault
bool
UploadImage
bool
NotifyOnce
bool
Frequency
time
.
Duration
Name
string
Type
string
Id
int64
IsDeault
bool
UploadImage
bool
SendReminder
bool
Frequency
time
.
Duration
}
func
NewNotifierBase
(
id
int64
,
isDefault
bool
,
name
,
notifierType
string
,
notifyOnce
bool
,
frequency
time
.
Duration
,
model
*
simplejson
.
Js
on
)
NotifierBase
{
func
NewNotifierBase
(
model
*
models
.
AlertNotificati
on
)
NotifierBase
{
uploadImage
:=
true
value
,
exist
:=
model
.
CheckGet
(
"uploadImage"
)
value
,
exist
:=
model
.
Settings
.
CheckGet
(
"uploadImage"
)
if
exist
{
uploadImage
=
value
.
MustBool
()
}
return
NotifierBase
{
Id
:
i
d
,
Name
:
n
ame
,
IsDeault
:
i
sDefault
,
Type
:
notifier
Type
,
UploadImage
:
uploadImage
,
NotifyOnce
:
notifyOnce
,
Frequency
:
f
requency
,
Id
:
model
.
I
d
,
Name
:
model
.
N
ame
,
IsDeault
:
model
.
I
sDefault
,
Type
:
model
.
Type
,
UploadImage
:
uploadImage
,
SendReminder
:
model
.
SendReminder
,
Frequency
:
model
.
F
requency
,
}
}
func
defaultShouldNotify
(
context
*
alerting
.
EvalContext
,
notifyOnce
bool
,
frequency
time
.
Duration
,
lastNotify
*
time
.
Time
)
bool
{
func
defaultShouldNotify
(
context
*
alerting
.
EvalContext
,
sendReminder
bool
,
frequency
time
.
Duration
,
lastNotify
*
time
.
Time
)
bool
{
// Only notify on state change.
if
context
.
PrevAlertState
==
context
.
Rule
.
State
&&
notifyOnce
{
if
context
.
PrevAlertState
==
context
.
Rule
.
State
&&
!
sendReminder
{
return
false
}
// Do not notify if interval has not elapsed
if
!
notifyOnce
&&
lastNotify
!=
nil
&&
lastNotify
.
Add
(
frequency
)
.
After
(
time
.
Now
())
{
if
sendReminder
&&
lastNotify
!=
nil
&&
lastNotify
.
Add
(
frequency
)
.
After
(
time
.
Now
())
{
return
false
}
// Do not notify if alert state if OK or pending even on repeated notify
if
!
notifyOnce
&&
(
context
.
Rule
.
State
==
m
.
AlertStateOK
||
context
.
Rule
.
State
==
m
.
AlertStatePending
)
{
if
sendReminder
&&
(
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
==
m
.
AlertStatePending
)
&&
(
context
.
Rule
.
State
==
m
.
AlertStateOK
)
{
if
(
context
.
PrevAlertState
==
m
odels
.
AlertStatePending
)
&&
(
context
.
Rule
.
State
==
models
.
AlertStateOK
)
{
return
false
}
return
true
...
...
@@ -58,7 +60,7 @@ func defaultShouldNotify(context *alerting.EvalContext, notifyOnce bool, frequen
func
(
n
*
NotifierBase
)
ShouldNotify
(
context
*
alerting
.
EvalContext
)
bool
{
lastNotify
:=
context
.
LastNotify
(
n
.
Id
)
return
defaultShouldNotify
(
context
,
n
.
NotifyOnce
,
n
.
Frequency
,
lastNotify
)
return
defaultShouldNotify
(
context
,
n
.
SendReminder
,
n
.
Frequency
,
lastNotify
)
}
func
(
n
*
NotifierBase
)
GetType
()
string
{
...
...
@@ -77,8 +79,8 @@ func (n *NotifierBase) GetIsDefault() bool {
return
n
.
IsDeault
}
func
(
n
*
NotifierBase
)
Get
NotifyOnce
()
bool
{
return
n
.
NotifyOnce
func
(
n
*
NotifierBase
)
Get
SendReminder
()
bool
{
return
n
.
SendReminder
}
func
(
n
*
NotifierBase
)
GetFrequency
()
time
.
Duration
{
...
...
pkg/services/alerting/notifiers/base_test.go
View file @
7333d7b8
...
...
@@ -16,22 +16,29 @@ func TestBaseNotifier(t *testing.T) {
Convey
(
"default constructor for notifiers"
,
func
()
{
bJson
:=
simplejson
.
New
()
model
:=
&
m
.
AlertNotification
{
Id
:
1
,
Name
:
"name"
,
Type
:
"email"
,
Settings
:
bJson
,
}
Convey
(
"can parse false value"
,
func
()
{
bJson
.
Set
(
"uploadImage"
,
false
)
base
:=
NewNotifierBase
(
1
,
false
,
"name"
,
"email"
,
true
,
0
,
bJson
)
base
:=
NewNotifierBase
(
model
)
So
(
base
.
UploadImage
,
ShouldBeFalse
)
})
Convey
(
"can parse true value"
,
func
()
{
bJson
.
Set
(
"uploadImage"
,
true
)
base
:=
NewNotifierBase
(
1
,
false
,
"name"
,
"email"
,
true
,
0
,
bJson
)
base
:=
NewNotifierBase
(
model
)
So
(
base
.
UploadImage
,
ShouldBeTrue
)
})
Convey
(
"default value should be true for backwards compatibility"
,
func
()
{
base
:=
NewNotifierBase
(
1
,
false
,
"name"
,
"email"
,
true
,
0
,
bJson
)
base
:=
NewNotifierBase
(
model
)
So
(
base
.
UploadImage
,
ShouldBeTrue
)
})
})
...
...
pkg/services/alerting/notifiers/dingding.go
View file @
7333d7b8
...
...
@@ -32,7 +32,7 @@ func NewDingDingNotifier(model *m.AlertNotification) (alerting.Notifier, error)
}
return
&
DingDingNotifier
{
NotifierBase
:
NewNotifierBase
(
model
.
Id
,
model
.
IsDefault
,
model
.
Name
,
model
.
Type
,
model
.
NotifyOnce
,
model
.
Frequency
,
model
.
Settings
),
NotifierBase
:
NewNotifierBase
(
model
),
Url
:
url
,
log
:
log
.
New
(
"alerting.notifier.dingding"
),
},
nil
...
...
pkg/services/alerting/notifiers/discord.go
View file @
7333d7b8
...
...
@@ -39,7 +39,7 @@ func NewDiscordNotifier(model *m.AlertNotification) (alerting.Notifier, error) {
}
return
&
DiscordNotifier
{
NotifierBase
:
NewNotifierBase
(
model
.
Id
,
model
.
IsDefault
,
model
.
Name
,
model
.
Type
,
model
.
NotifyOnce
,
model
.
Frequency
,
model
.
Settings
),
NotifierBase
:
NewNotifierBase
(
model
),
WebhookURL
:
url
,
log
:
log
.
New
(
"alerting.notifier.discord"
),
},
nil
...
...
pkg/services/alerting/notifiers/email.go
View file @
7333d7b8
...
...
@@ -52,7 +52,7 @@ func NewEmailNotifier(model *m.AlertNotification) (alerting.Notifier, error) {
})
return
&
EmailNotifier
{
NotifierBase
:
NewNotifierBase
(
model
.
Id
,
model
.
IsDefault
,
model
.
Name
,
model
.
Type
,
model
.
NotifyOnce
,
model
.
Frequency
,
model
.
Settings
),
NotifierBase
:
NewNotifierBase
(
model
),
Addresses
:
addresses
,
log
:
log
.
New
(
"alerting.notifier.email"
),
},
nil
...
...
pkg/services/alerting/notifiers/hipchat.go
View file @
7333d7b8
...
...
@@ -59,7 +59,7 @@ func NewHipChatNotifier(model *models.AlertNotification) (alerting.Notifier, err
roomId
:=
model
.
Settings
.
Get
(
"roomid"
)
.
MustString
()
return
&
HipChatNotifier
{
NotifierBase
:
NewNotifierBase
(
model
.
Id
,
model
.
IsDefault
,
model
.
Name
,
model
.
Type
,
model
.
NotifyOnce
,
model
.
Frequency
,
model
.
Settings
),
NotifierBase
:
NewNotifierBase
(
model
),
Url
:
url
,
ApiKey
:
apikey
,
RoomId
:
roomId
,
...
...
pkg/services/alerting/notifiers/kafka.go
View file @
7333d7b8
...
...
@@ -43,7 +43,7 @@ func NewKafkaNotifier(model *m.AlertNotification) (alerting.Notifier, error) {
}
return
&
KafkaNotifier
{
NotifierBase
:
NewNotifierBase
(
model
.
Id
,
model
.
IsDefault
,
model
.
Name
,
model
.
Type
,
model
.
NotifyOnce
,
model
.
Frequency
,
model
.
Settings
),
NotifierBase
:
NewNotifierBase
(
model
),
Endpoint
:
endpoint
,
Topic
:
topic
,
log
:
log
.
New
(
"alerting.notifier.kafka"
),
...
...
pkg/services/alerting/notifiers/line.go
View file @
7333d7b8
...
...
@@ -39,7 +39,7 @@ func NewLINENotifier(model *m.AlertNotification) (alerting.Notifier, error) {
}
return
&
LineNotifier
{
NotifierBase
:
NewNotifierBase
(
model
.
Id
,
model
.
IsDefault
,
model
.
Name
,
model
.
Type
,
model
.
NotifyOnce
,
model
.
Frequency
,
model
.
Settings
),
NotifierBase
:
NewNotifierBase
(
model
),
Token
:
token
,
log
:
log
.
New
(
"alerting.notifier.line"
),
},
nil
...
...
pkg/services/alerting/notifiers/opsgenie.go
View file @
7333d7b8
...
...
@@ -56,7 +56,7 @@ func NewOpsGenieNotifier(model *m.AlertNotification) (alerting.Notifier, error)
}
return
&
OpsGenieNotifier
{
NotifierBase
:
NewNotifierBase
(
model
.
Id
,
model
.
IsDefault
,
model
.
Name
,
model
.
Type
,
model
.
NotifyOnce
,
model
.
Frequency
,
model
.
Settings
),
NotifierBase
:
NewNotifierBase
(
model
),
ApiKey
:
apiKey
,
ApiUrl
:
apiUrl
,
AutoClose
:
autoClose
,
...
...
pkg/services/alerting/notifiers/pagerduty.go
View file @
7333d7b8
...
...
@@ -51,7 +51,7 @@ func NewPagerdutyNotifier(model *m.AlertNotification) (alerting.Notifier, error)
}
return
&
PagerdutyNotifier
{
NotifierBase
:
NewNotifierBase
(
model
.
Id
,
model
.
IsDefault
,
model
.
Name
,
model
.
Type
,
model
.
NotifyOnce
,
model
.
Frequency
,
model
.
Settings
),
NotifierBase
:
NewNotifierBase
(
model
),
Key
:
key
,
AutoResolve
:
autoResolve
,
log
:
log
.
New
(
"alerting.notifier.pagerduty"
),
...
...
pkg/services/alerting/notifiers/pushover.go
View file @
7333d7b8
...
...
@@ -99,7 +99,7 @@ func NewPushoverNotifier(model *m.AlertNotification) (alerting.Notifier, error)
return
nil
,
alerting
.
ValidationError
{
Reason
:
"API token not given"
}
}
return
&
PushoverNotifier
{
NotifierBase
:
NewNotifierBase
(
model
.
Id
,
model
.
IsDefault
,
model
.
Name
,
model
.
Type
,
model
.
NotifyOnce
,
model
.
Frequency
,
model
.
Settings
),
NotifierBase
:
NewNotifierBase
(
model
),
UserKey
:
userKey
,
ApiToken
:
apiToken
,
Priority
:
priority
,
...
...
pkg/services/alerting/notifiers/sensu.go
View file @
7333d7b8
...
...
@@ -51,7 +51,7 @@ func NewSensuNotifier(model *m.AlertNotification) (alerting.Notifier, error) {
}
return
&
SensuNotifier
{
NotifierBase
:
NewNotifierBase
(
model
.
Id
,
model
.
IsDefault
,
model
.
Name
,
model
.
Type
,
model
.
NotifyOnce
,
model
.
Frequency
,
model
.
Settings
),
NotifierBase
:
NewNotifierBase
(
model
),
Url
:
url
,
User
:
model
.
Settings
.
Get
(
"username"
)
.
MustString
(),
Source
:
model
.
Settings
.
Get
(
"source"
)
.
MustString
(),
...
...
pkg/services/alerting/notifiers/slack.go
View file @
7333d7b8
...
...
@@ -78,7 +78,7 @@ func NewSlackNotifier(model *m.AlertNotification) (alerting.Notifier, error) {
uploadImage
:=
model
.
Settings
.
Get
(
"uploadImage"
)
.
MustBool
(
true
)
return
&
SlackNotifier
{
NotifierBase
:
NewNotifierBase
(
model
.
Id
,
model
.
IsDefault
,
model
.
Name
,
model
.
Type
,
model
.
NotifyOnce
,
model
.
Frequency
,
model
.
Settings
),
NotifierBase
:
NewNotifierBase
(
model
),
Url
:
url
,
Recipient
:
recipient
,
Mention
:
mention
,
...
...
pkg/services/alerting/notifiers/teams.go
View file @
7333d7b8
...
...
@@ -33,7 +33,7 @@ func NewTeamsNotifier(model *m.AlertNotification) (alerting.Notifier, error) {
}
return
&
TeamsNotifier
{
NotifierBase
:
NewNotifierBase
(
model
.
Id
,
model
.
IsDefault
,
model
.
Name
,
model
.
Type
,
model
.
NotifyOnce
,
model
.
Frequency
,
model
.
Settings
),
NotifierBase
:
NewNotifierBase
(
model
),
Url
:
url
,
log
:
log
.
New
(
"alerting.notifier.teams"
),
},
nil
...
...
pkg/services/alerting/notifiers/telegram.go
View file @
7333d7b8
...
...
@@ -78,7 +78,7 @@ func NewTelegramNotifier(model *m.AlertNotification) (alerting.Notifier, error)
}
return
&
TelegramNotifier
{
NotifierBase
:
NewNotifierBase
(
model
.
Id
,
model
.
IsDefault
,
model
.
Name
,
model
.
Type
,
model
.
NotifyOnce
,
model
.
Frequency
,
model
.
Settings
),
NotifierBase
:
NewNotifierBase
(
model
),
BotToken
:
botToken
,
ChatID
:
chatId
,
UploadImage
:
uploadImage
,
...
...
pkg/services/alerting/notifiers/threema.go
View file @
7333d7b8
...
...
@@ -106,7 +106,7 @@ func NewThreemaNotifier(model *m.AlertNotification) (alerting.Notifier, error) {
}
return
&
ThreemaNotifier
{
NotifierBase
:
NewNotifierBase
(
model
.
Id
,
model
.
IsDefault
,
model
.
Name
,
model
.
Type
,
model
.
NotifyOnce
,
model
.
Frequency
,
model
.
Settings
),
NotifierBase
:
NewNotifierBase
(
model
),
GatewayID
:
gatewayID
,
RecipientID
:
recipientID
,
APISecret
:
apiSecret
,
...
...
pkg/services/alerting/notifiers/victorops.go
View file @
7333d7b8
...
...
@@ -51,7 +51,7 @@ func NewVictoropsNotifier(model *models.AlertNotification) (alerting.Notifier, e
}
return
&
VictoropsNotifier
{
NotifierBase
:
NewNotifierBase
(
model
.
Id
,
model
.
IsDefault
,
model
.
Name
,
model
.
Type
,
model
.
NotifyOnce
,
model
.
Frequency
,
model
.
Settings
),
NotifierBase
:
NewNotifierBase
(
model
),
URL
:
url
,
AutoResolve
:
autoResolve
,
log
:
log
.
New
(
"alerting.notifier.victorops"
),
...
...
pkg/services/alerting/notifiers/webhook.go
View file @
7333d7b8
...
...
@@ -47,7 +47,7 @@ func NewWebHookNotifier(model *m.AlertNotification) (alerting.Notifier, error) {
}
return
&
WebhookNotifier
{
NotifierBase
:
NewNotifierBase
(
model
.
Id
,
model
.
IsDefault
,
model
.
Name
,
model
.
Type
,
model
.
NotifyOnce
,
model
.
Frequency
,
model
.
Settings
),
NotifierBase
:
NewNotifierBase
(
model
),
Url
:
url
,
User
:
model
.
Settings
.
Get
(
"username"
)
.
MustString
(),
Password
:
model
.
Settings
.
Get
(
"password"
)
.
MustString
(),
...
...
pkg/services/sqlstore/alert_notification.go
View file @
7333d7b8
...
...
@@ -57,7 +57,7 @@ func GetAlertNotificationsToSend(query *m.GetAlertNotificationsToSendQuery) erro
alert_notification.updated,
alert_notification.settings,
alert_notification.is_default,
alert_notification.
notify_once
,
alert_notification.
send_reminder
,
alert_notification.frequency
FROM alert_notification
`
)
...
...
@@ -97,7 +97,7 @@ func getAlertNotificationInternal(query *m.GetAlertNotificationsQuery, sess *DBS
alert_notification.updated,
alert_notification.settings,
alert_notification.is_default,
alert_notification.
notify_once
,
alert_notification.
send_reminder
,
alert_notification.frequency
FROM alert_notification
`
)
...
...
@@ -145,7 +145,7 @@ func CreateAlertNotificationCommand(cmd *m.CreateAlertNotificationCommand) error
}
var
frequency
time
.
Duration
if
!
cmd
.
NotifyOnce
{
if
cmd
.
SendReminder
{
if
cmd
.
Frequency
==
""
{
return
m
.
ErrNotificationFrequencyNotFound
}
...
...
@@ -157,18 +157,18 @@ func CreateAlertNotificationCommand(cmd *m.CreateAlertNotificationCommand) error
}
alertNotification
:=
&
m
.
AlertNotification
{
OrgId
:
cmd
.
OrgId
,
Name
:
cmd
.
Name
,
Type
:
cmd
.
Type
,
Settings
:
cmd
.
Settings
,
NotifyOnce
:
cmd
.
NotifyOnce
,
Frequency
:
frequency
,
Created
:
time
.
Now
(),
Updated
:
time
.
Now
(),
IsDefault
:
cmd
.
IsDefault
,
OrgId
:
cmd
.
OrgId
,
Name
:
cmd
.
Name
,
Type
:
cmd
.
Type
,
Settings
:
cmd
.
Settings
,
SendReminder
:
cmd
.
SendReminder
,
Frequency
:
frequency
,
Created
:
time
.
Now
(),
Updated
:
time
.
Now
(),
IsDefault
:
cmd
.
IsDefault
,
}
if
_
,
err
=
sess
.
MustCols
(
"
notify_once
"
)
.
Insert
(
alertNotification
);
err
!=
nil
{
if
_
,
err
=
sess
.
MustCols
(
"
send_reminder
"
)
.
Insert
(
alertNotification
);
err
!=
nil
{
return
err
}
...
...
@@ -200,9 +200,9 @@ func UpdateAlertNotification(cmd *m.UpdateAlertNotificationCommand) error {
current
.
Name
=
cmd
.
Name
current
.
Type
=
cmd
.
Type
current
.
IsDefault
=
cmd
.
IsDefault
current
.
NotifyOnce
=
cmd
.
NotifyOnce
current
.
SendReminder
=
cmd
.
SendReminder
if
!
current
.
NotifyOnce
{
if
current
.
SendReminder
{
if
cmd
.
Frequency
==
""
{
return
m
.
ErrNotificationFrequencyNotFound
}
...
...
@@ -215,7 +215,7 @@ func UpdateAlertNotification(cmd *m.UpdateAlertNotificationCommand) error {
current
.
Frequency
=
frequency
}
sess
.
UseBool
(
"is_default"
,
"
notify_once
"
)
sess
.
UseBool
(
"is_default"
,
"
send_reminder
"
)
if
affected
,
err
:=
sess
.
ID
(
cmd
.
Id
)
.
Update
(
current
);
err
!=
nil
{
return
err
...
...
pkg/services/sqlstore/alert_notification_test.go
View file @
7333d7b8
...
...
@@ -23,13 +23,13 @@ func TestAlertNotificationSQLAccess(t *testing.T) {
So
(
cmd
.
Result
,
ShouldBeNil
)
})
Convey
(
"Cannot save alert notifier with
notitfyonce = fals
e"
,
func
()
{
Convey
(
"Cannot save alert notifier with
send reminder = tru
e"
,
func
()
{
cmd
:=
&
m
.
CreateAlertNotificationCommand
{
Name
:
"ops"
,
Type
:
"email"
,
OrgId
:
1
,
NotifyOnce
:
fals
e
,
Settings
:
simplejson
.
New
(),
Name
:
"ops"
,
Type
:
"email"
,
OrgId
:
1
,
SendReminder
:
tru
e
,
Settings
:
simplejson
.
New
(),
}
Convey
(
"and missing frequency"
,
func
()
{
...
...
@@ -47,19 +47,19 @@ func TestAlertNotificationSQLAccess(t *testing.T) {
Convey
(
"Cannot update alert notifier with notitfyonce = false"
,
func
()
{
cmd
:=
&
m
.
CreateAlertNotificationCommand
{
Name
:
"ops update"
,
Type
:
"email"
,
OrgId
:
1
,
NotifyOnce
:
tru
e
,
Settings
:
simplejson
.
New
(),
Name
:
"ops update"
,
Type
:
"email"
,
OrgId
:
1
,
SendReminder
:
fals
e
,
Settings
:
simplejson
.
New
(),
}
err
:=
CreateAlertNotificationCommand
(
cmd
)
So
(
err
,
ShouldBeNil
)
updateCmd
:=
&
m
.
UpdateAlertNotificationCommand
{
Id
:
cmd
.
Result
.
Id
,
NotifyOnce
:
fals
e
,
Id
:
cmd
.
Result
.
Id
,
SendReminder
:
tru
e
,
}
Convey
(
"and missing frequency"
,
func
()
{
...
...
@@ -71,18 +71,19 @@ func TestAlertNotificationSQLAccess(t *testing.T) {
updateCmd
.
Frequency
=
"invalid duration"
err
:=
UpdateAlertNotification
(
updateCmd
)
So
(
err
,
ShouldNotBeNil
)
So
(
err
.
Error
(),
ShouldEqual
,
"time: invalid duration invalid duration"
)
})
})
Convey
(
"Can save Alert Notification"
,
func
()
{
cmd
:=
&
m
.
CreateAlertNotificationCommand
{
Name
:
"ops"
,
Type
:
"email"
,
OrgId
:
1
,
NotifyOnce
:
true
,
Frequency
:
"10s"
,
Settings
:
simplejson
.
New
(),
Name
:
"ops"
,
Type
:
"email"
,
OrgId
:
1
,
SendReminder
:
true
,
Frequency
:
"10s"
,
Settings
:
simplejson
.
New
(),
}
err
:=
CreateAlertNotificationCommand
(
cmd
)
...
...
@@ -98,13 +99,13 @@ func TestAlertNotificationSQLAccess(t *testing.T) {
Convey
(
"Can update alert notification"
,
func
()
{
newCmd
:=
&
m
.
UpdateAlertNotificationCommand
{
Name
:
"NewName"
,
Type
:
"webhook"
,
OrgId
:
cmd
.
Result
.
OrgId
,
NotifyOnce
:
true
,
Frequency
:
"10s"
,
Settings
:
simplejson
.
New
(),
Id
:
cmd
.
Result
.
Id
,
Name
:
"NewName"
,
Type
:
"webhook"
,
OrgId
:
cmd
.
Result
.
OrgId
,
SendReminder
:
true
,
Frequency
:
"10s"
,
Settings
:
simplejson
.
New
(),
Id
:
cmd
.
Result
.
Id
,
}
err
:=
UpdateAlertNotification
(
newCmd
)
So
(
err
,
ShouldBeNil
)
...
...
@@ -113,12 +114,12 @@ func TestAlertNotificationSQLAccess(t *testing.T) {
})
Convey
(
"Can search using an array of ids"
,
func
()
{
cmd1
:=
m
.
CreateAlertNotificationCommand
{
Name
:
"nagios"
,
Type
:
"webhook"
,
OrgId
:
1
,
NotifyOnce
:
true
,
Frequency
:
"10s"
,
Settings
:
simplejson
.
New
()}
cmd2
:=
m
.
CreateAlertNotificationCommand
{
Name
:
"slack"
,
Type
:
"webhook"
,
OrgId
:
1
,
NotifyOnce
:
true
,
Frequency
:
"10s"
,
Settings
:
simplejson
.
New
()}
cmd3
:=
m
.
CreateAlertNotificationCommand
{
Name
:
"ops2"
,
Type
:
"email"
,
OrgId
:
1
,
NotifyOnce
:
true
,
Frequency
:
"10s"
,
Settings
:
simplejson
.
New
()}
cmd4
:=
m
.
CreateAlertNotificationCommand
{
IsDefault
:
true
,
Name
:
"default"
,
Type
:
"email"
,
OrgId
:
1
,
NotifyOnce
:
true
,
Frequency
:
"10s"
,
Settings
:
simplejson
.
New
()}
cmd1
:=
m
.
CreateAlertNotificationCommand
{
Name
:
"nagios"
,
Type
:
"webhook"
,
OrgId
:
1
,
SendReminder
:
true
,
Frequency
:
"10s"
,
Settings
:
simplejson
.
New
()}
cmd2
:=
m
.
CreateAlertNotificationCommand
{
Name
:
"slack"
,
Type
:
"webhook"
,
OrgId
:
1
,
SendReminder
:
true
,
Frequency
:
"10s"
,
Settings
:
simplejson
.
New
()}
cmd3
:=
m
.
CreateAlertNotificationCommand
{
Name
:
"ops2"
,
Type
:
"email"
,
OrgId
:
1
,
SendReminder
:
true
,
Frequency
:
"10s"
,
Settings
:
simplejson
.
New
()}
cmd4
:=
m
.
CreateAlertNotificationCommand
{
IsDefault
:
true
,
Name
:
"default"
,
Type
:
"email"
,
OrgId
:
1
,
SendReminder
:
true
,
Frequency
:
"10s"
,
Settings
:
simplejson
.
New
()}
otherOrg
:=
m
.
CreateAlertNotificationCommand
{
Name
:
"default"
,
Type
:
"email"
,
OrgId
:
2
,
NotifyOnce
:
true
,
Frequency
:
"10s"
,
Settings
:
simplejson
.
New
()}
otherOrg
:=
m
.
CreateAlertNotificationCommand
{
Name
:
"default"
,
Type
:
"email"
,
OrgId
:
2
,
SendReminder
:
true
,
Frequency
:
"10s"
,
Settings
:
simplejson
.
New
()}
So
(
CreateAlertNotificationCommand
(
&
cmd1
),
ShouldBeNil
)
So
(
CreateAlertNotificationCommand
(
&
cmd2
),
ShouldBeNil
)
...
...
pkg/services/sqlstore/migrations/alert_mig.go
View file @
7333d7b8
...
...
@@ -68,9 +68,10 @@ func addAlertMigrations(mg *Migrator) {
mg
.
AddMigration
(
"Add column frequency"
,
NewAddColumnMigration
(
alert_notification
,
&
Column
{
Name
:
"frequency"
,
Type
:
DB_BigInt
,
Nullable
:
true
,
}))
mg
.
AddMigration
(
"Add column
notify_once
"
,
NewAddColumnMigration
(
alert_notification
,
&
Column
{
Name
:
"
notify_once"
,
Type
:
DB_Bool
,
Nullable
:
false
,
Default
:
"1
"
,
mg
.
AddMigration
(
"Add column
send_reminder
"
,
NewAddColumnMigration
(
alert_notification
,
&
Column
{
Name
:
"
send_reminder"
,
Type
:
DB_Bool
,
Nullable
:
true
,
Default
:
"0
"
,
}))
mg
.
AddMigration
(
"add index alert_notification org_id & name"
,
NewAddIndexMigration
(
alert_notification
,
alert_notification
.
Indices
[
0
]))
notification_journal
:=
Table
{
...
...
public/app/features/alerting/notification_edit_ctrl.ts
View file @
7333d7b8
...
...
@@ -11,7 +11,7 @@ export class AlertNotificationEditCtrl {
model
:
any
;
defaults
:
any
=
{
type
:
'email'
,
notifyOnce
:
tru
e
,
sendReminder
:
fals
e
,
frequency
:
'15m'
,
settings
:
{
httpMethod
:
'POST'
,
...
...
public/app/features/alerting/partials/notification_edit.html
View file @
7333d7b8
...
...
@@ -34,14 +34,27 @@
</gf-form-switch>
<gf-form-switch
class=
"gf-form"
label=
"
Notify once
"
label=
"
Send reminder
"
label-class=
"width-12"
checked=
"ctrl.model.
notifyOnce
"
checked=
"ctrl.model.
sendReminder
"
tooltip=
"Choose to either notify on state change or at every interval"
>
</gf-form-switch>
<div
class=
"gf-form"
>
<span
class=
"gf-form-label width-12"
ng-if=
"!ctrl.model.notifyOnce"
>
Notify every
</span>
<input
class=
"gf-form-input max-width-15"
type=
"text"
required
ng-model=
"ctrl.model.frequency"
required
ng-if=
"!ctrl.model.notifyOnce"
></input>
<div
class=
"gf-form-inline"
>
<div
class=
"gf-form"
>
<span
class=
"gf-form-label width-12"
ng-if=
"ctrl.model.sendReminder"
>
Send reminder every
</span>
<input
class=
"gf-form-input max-width-15"
type=
"text"
ng-model=
"ctrl.model.frequency"
ng-required=
"ctrl.model.sendReminder"
ng-if=
"ctrl.model.sendReminder"
spellcheck=
'false'
placeholder=
'15m'
></input>
<info-popover
mode=
"right-absolute"
>
Specify at what interval you want reminder's about this alerting beeing triggered.
Ex. 60s, 10m, 30m, 1h
</info-popover>
</div>
</div>
</div>
...
...
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