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
b0c7e61e
Commit
b0c7e61e
authored
Sep 13, 2016
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(alerting): removed severity
parent
6375418d
Hide whitespace changes
Inline
Side-by-side
Showing
23 changed files
with
143 additions
and
238 deletions
+143
-238
pkg/api/alerting.go
+0
-2
pkg/api/dtos/alerting.go
+10
-12
pkg/metrics/metrics.go
+39
-41
pkg/models/alert.go
+7
-19
pkg/services/alerting/eval_context.go
+6
-11
pkg/services/alerting/extractor.go
+0
-5
pkg/services/alerting/interfaces.go
+1
-3
pkg/services/alerting/notifier.go
+2
-2
pkg/services/alerting/notifier_test.go
+7
-8
pkg/services/alerting/notifiers/base.go
+5
-17
pkg/services/alerting/notifiers/base_test.go
+24
-26
pkg/services/alerting/notifiers/email.go
+9
-10
pkg/services/alerting/notifiers/webhook.go
+0
-1
pkg/services/alerting/result_handler.go
+8
-10
pkg/services/alerting/rule.go
+1
-3
pkg/services/alerting/test_notification.go
+9
-21
pkg/services/sqlstore/alert.go
+1
-1
pkg/services/sqlstore/alert_test.go
+2
-2
public/app/features/alerting/alert_def.ts
+6
-19
public/app/features/alerting/alert_list_ctrl.ts
+2
-3
public/app/features/alerting/alert_tab_ctrl.ts
+1
-9
public/app/features/alerting/partials/alert_tab.html
+2
-12
public/app/features/alerting/threshold_mapper.ts
+1
-1
No files found.
pkg/api/alerting.go
View file @
b0c7e61e
...
...
@@ -49,7 +49,6 @@ func GetAlerts(c *middleware.Context) Response {
Name
:
alert
.
Name
,
Message
:
alert
.
Message
,
State
:
alert
.
State
,
Severity
:
alert
.
Severity
,
EvalDate
:
alert
.
EvalDate
,
NewStateDate
:
alert
.
NewStateDate
,
ExecutionError
:
alert
.
ExecutionError
,
...
...
@@ -219,7 +218,6 @@ func NotificationTest(c *middleware.Context, dto dtos.NotificationTestCommand) R
cmd
:=
&
alerting
.
NotificationTestCommand
{
Name
:
dto
.
Name
,
Type
:
dto
.
Type
,
Severity
:
dto
.
Severity
,
Settings
:
dto
.
Settings
,
}
...
...
pkg/api/dtos/alerting.go
View file @
b0c7e61e
...
...
@@ -8,17 +8,16 @@ import (
)
type
AlertRule
struct
{
Id
int64
`json:"id"`
DashboardId
int64
`json:"dashboardId"`
PanelId
int64
`json:"panelId"`
Name
string
`json:"name"`
Message
string
`json:"message"`
State
m
.
AlertStateType
`json:"state"`
Severity
m
.
AlertSeverityType
`json:"severity"`
NewStateDate
time
.
Time
`json:"newStateDate"`
EvalDate
time
.
Time
`json:"evalDate"`
ExecutionError
string
`json:"executionError"`
DashbboardUri
string
`json:"dashboardUri"`
Id
int64
`json:"id"`
DashboardId
int64
`json:"dashboardId"`
PanelId
int64
`json:"panelId"`
Name
string
`json:"name"`
Message
string
`json:"message"`
State
m
.
AlertStateType
`json:"state"`
NewStateDate
time
.
Time
`json:"newStateDate"`
EvalDate
time
.
Time
`json:"evalDate"`
ExecutionError
string
`json:"executionError"`
DashbboardUri
string
`json:"dashboardUri"`
}
type
AlertNotification
struct
{
...
...
@@ -58,5 +57,4 @@ type NotificationTestCommand struct {
Name
string
`json:"name"`
Type
string
`json:"type"`
Settings
*
simplejson
.
Json
`json:"settings"`
Severity
string
`json:"severity"`
}
pkg/metrics/metrics.go
View file @
b0c7e61e
...
...
@@ -9,43 +9,42 @@ func init() {
}
var
(
M_Instance_Start
Counter
M_Page_Status_200
Counter
M_Page_Status_500
Counter
M_Page_Status_404
Counter
M_Page_Status_Unknown
Counter
M_Api_Status_200
Counter
M_Api_Status_404
Counter
M_Api_Status_500
Counter
M_Api_Status_Unknown
Counter
M_Proxy_Status_200
Counter
M_Proxy_Status_404
Counter
M_Proxy_Status_500
Counter
M_Proxy_Status_Unknown
Counter
M_Api_User_SignUpStarted
Counter
M_Api_User_SignUpCompleted
Counter
M_Api_User_SignUpInvite
Counter
M_Api_Dashboard_Save
Timer
M_Api_Dashboard_Get
Timer
M_Api_Dashboard_Search
Timer
M_Api_Admin_User_Create
Counter
M_Api_Login_Post
Counter
M_Api_Login_OAuth
Counter
M_Api_Org_Create
Counter
M_Api_Dashboard_Snapshot_Create
Counter
M_Api_Dashboard_Snapshot_External
Counter
M_Api_Dashboard_Snapshot_Get
Counter
M_Models_Dashboard_Insert
Counter
M_Alerting_Result_State_Critical
Counter
M_Alerting_Result_State_Warning
Counter
M_Alerting_Result_State_Ok
Counter
M_Alerting_Result_State_Paused
Counter
M_Alerting_Result_State_Unknown
Counter
M_Alerting_Result_State_ExecutionError
Counter
M_Alerting_Active_Alerts
Counter
M_Alerting_Notification_Sent_Slack
Counter
M_Alerting_Notification_Sent_Email
Counter
M_Alerting_Notification_Sent_Webhook
Counter
M_Instance_Start
Counter
M_Page_Status_200
Counter
M_Page_Status_500
Counter
M_Page_Status_404
Counter
M_Page_Status_Unknown
Counter
M_Api_Status_200
Counter
M_Api_Status_404
Counter
M_Api_Status_500
Counter
M_Api_Status_Unknown
Counter
M_Proxy_Status_200
Counter
M_Proxy_Status_404
Counter
M_Proxy_Status_500
Counter
M_Proxy_Status_Unknown
Counter
M_Api_User_SignUpStarted
Counter
M_Api_User_SignUpCompleted
Counter
M_Api_User_SignUpInvite
Counter
M_Api_Dashboard_Save
Timer
M_Api_Dashboard_Get
Timer
M_Api_Dashboard_Search
Timer
M_Api_Admin_User_Create
Counter
M_Api_Login_Post
Counter
M_Api_Login_OAuth
Counter
M_Api_Org_Create
Counter
M_Api_Dashboard_Snapshot_Create
Counter
M_Api_Dashboard_Snapshot_External
Counter
M_Api_Dashboard_Snapshot_Get
Counter
M_Models_Dashboard_Insert
Counter
M_Alerting_Result_State_Alerting
Counter
M_Alerting_Result_State_Ok
Counter
M_Alerting_Result_State_Paused
Counter
M_Alerting_Result_State_NoData
Counter
M_Alerting_Result_State_ExecError
Counter
M_Alerting_Active_Alerts
Counter
M_Alerting_Notification_Sent_Slack
Counter
M_Alerting_Notification_Sent_Email
Counter
M_Alerting_Notification_Sent_Webhook
Counter
// Timers
M_DataSource_ProxyReq_Timer
Timer
...
...
@@ -92,12 +91,11 @@ func initMetricVars(settings *MetricSettings) {
M_Models_Dashboard_Insert
=
RegCounter
(
"models.dashboard.insert"
)
M_Alerting_Result_State_Critical
=
RegCounter
(
"alerting.result"
,
"state"
,
"critical"
)
M_Alerting_Result_State_Warning
=
RegCounter
(
"alerting.result"
,
"state"
,
"warning"
)
M_Alerting_Result_State_Alerting
=
RegCounter
(
"alerting.result"
,
"state"
,
"alerting"
)
M_Alerting_Result_State_Ok
=
RegCounter
(
"alerting.result"
,
"state"
,
"ok"
)
M_Alerting_Result_State_Paused
=
RegCounter
(
"alerting.result"
,
"state"
,
"paused"
)
M_Alerting_Result_State_
Unknown
=
RegCounter
(
"alerting.result"
,
"state"
,
"unknown
"
)
M_Alerting_Result_State_Exec
utionError
=
RegCounter
(
"alerting.result"
,
"state"
,
"execution
_error"
)
M_Alerting_Result_State_
NoData
=
RegCounter
(
"alerting.result"
,
"state"
,
"no_data
"
)
M_Alerting_Result_State_Exec
Error
=
RegCounter
(
"alerting.result"
,
"state"
,
"exec
_error"
)
M_Alerting_Active_Alerts
=
RegCounter
(
"alerting.active_alerts"
)
M_Alerting_Notification_Sent_Slack
=
RegCounter
(
"alerting.notifications_sent"
,
"type"
,
"slack"
)
...
...
pkg/models/alert.go
View file @
b0c7e61e
...
...
@@ -10,27 +10,15 @@ type AlertStateType string
type
AlertSeverityType
string
const
(
AlertStateUnknown
AlertStateType
=
"unknown"
AlertStateExeuctionError
AlertStateType
=
"execution_error"
AlertStatePaused
AlertStateType
=
"paused"
AlertStateCritical
AlertStateType
=
"critical"
AlertStateWarning
AlertStateType
=
"warning"
AlertStateOK
AlertStateType
=
"ok"
AlertStateNoData
AlertStateType
=
"no_data"
AlertStateExecError
AlertStateType
=
"execution_error"
AlertStatePaused
AlertStateType
=
"paused"
AlertStateAlerting
AlertStateType
=
"alerting"
AlertStateOK
AlertStateType
=
"ok"
)
func
(
s
AlertStateType
)
IsValid
()
bool
{
return
s
==
AlertStateOK
||
s
==
AlertStateUnknown
||
s
==
AlertStateExeuctionError
||
s
==
AlertStatePaused
||
s
==
AlertStateCritical
||
s
==
AlertStateWarning
}
const
(
AlertSeverityCritical
AlertSeverityType
=
"critical"
AlertSeverityWarning
AlertSeverityType
=
"warning"
AlertSeverityInfo
AlertSeverityType
=
"info"
AlertSeverityOK
AlertSeverityType
=
"ok"
)
func
(
s
AlertSeverityType
)
IsValid
()
bool
{
return
s
==
AlertSeverityCritical
||
s
==
AlertSeverityInfo
||
s
==
AlertSeverityWarning
return
s
==
AlertStateOK
||
s
==
AlertStateNoData
||
s
==
AlertStateExecError
||
s
==
AlertStatePaused
}
type
Alert
struct
{
...
...
@@ -41,7 +29,7 @@ type Alert struct {
PanelId
int64
Name
string
Message
string
Severity
AlertSeverityType
Severity
string
State
AlertStateType
Handler
int64
Silenced
bool
...
...
pkg/services/alerting/eval_context.go
View file @
b0c7e61e
...
...
@@ -43,25 +43,20 @@ func (c *EvalContext) GetStateModel() *StateDescription {
Color
:
"#36a64f"
,
Text
:
"OK"
,
}
case
m
.
AlertState
Unknown
:
case
m
.
AlertState
NoData
:
return
&
StateDescription
{
Color
:
"#888888"
,
Text
:
"
UNKNOWN
"
,
Text
:
"
No Data
"
,
}
case
m
.
AlertStateExe
uction
Error
:
case
m
.
AlertStateExe
c
Error
:
return
&
StateDescription
{
Color
:
"#000"
,
Text
:
"E
XECUTION_ERROR
"
,
Text
:
"E
xecution Error
"
,
}
case
m
.
AlertStateWarning
:
return
&
StateDescription
{
Color
:
"#fd821b"
,
Text
:
"WARNING"
,
}
case
m
.
AlertStateCritical
:
case
m
.
AlertStateAlerting
:
return
&
StateDescription
{
Color
:
"#D63232"
,
Text
:
"
CRITICAL
"
,
Text
:
"
Alerting
"
,
}
default
:
panic
(
"Unknown rule state "
+
c
.
Rule
.
State
)
...
...
pkg/services/alerting/extractor.go
View file @
b0c7e61e
...
...
@@ -88,14 +88,9 @@ func (e *DashAlertExtractor) GetAlerts() ([]*m.Alert, error) {
Name
:
jsonAlert
.
Get
(
"name"
)
.
MustString
(),
Handler
:
jsonAlert
.
Get
(
"handler"
)
.
MustInt64
(),
Message
:
jsonAlert
.
Get
(
"message"
)
.
MustString
(),
Severity
:
m
.
AlertSeverityType
(
jsonAlert
.
Get
(
"severity"
)
.
MustString
()),
Frequency
:
getTimeDurationStringToSeconds
(
jsonAlert
.
Get
(
"frequency"
)
.
MustString
()),
}
if
!
alert
.
Severity
.
IsValid
()
{
return
nil
,
ValidationError
{
Reason
:
"Invalid alert Severity"
}
}
for
_
,
condition
:=
range
jsonAlert
.
Get
(
"conditions"
)
.
MustArray
()
{
jsonCondition
:=
simplejson
.
NewFromAny
(
condition
)
...
...
pkg/services/alerting/interfaces.go
View file @
b0c7e61e
...
...
@@ -2,8 +2,6 @@ package alerting
import
(
"time"
"github.com/grafana/grafana/pkg/models"
)
type
EvalHandler
interface
{
...
...
@@ -19,7 +17,7 @@ type Notifier interface {
Notify
(
alertResult
*
EvalContext
)
GetType
()
string
NeedsImage
()
bool
MatchSeverity
(
result
models
.
AlertSeverityTyp
e
)
bool
PassesFilter
(
rule
*
Rul
e
)
bool
}
type
Condition
interface
{
...
...
pkg/services/alerting/notifier.go
View file @
b0c7e61e
...
...
@@ -28,7 +28,7 @@ func (n *RootNotifier) NeedsImage() bool {
return
false
}
func
(
n
*
RootNotifier
)
MatchSeverity
(
result
m
.
AlertSeverityTyp
e
)
bool
{
func
(
n
*
RootNotifier
)
PassesFilter
(
rule
*
Rul
e
)
bool
{
return
false
}
...
...
@@ -130,7 +130,7 @@ func shouldUseNotification(notifier Notifier, context *EvalContext) bool {
return
true
}
return
notifier
.
MatchSeverity
(
context
.
Rule
.
Severity
)
return
notifier
.
PassesFilter
(
context
.
Rule
)
}
type
NotifierFactory
func
(
notification
*
m
.
AlertNotification
)
(
Notifier
,
error
)
...
...
pkg/services/alerting/notifier_test.go
View file @
b0c7e61e
...
...
@@ -6,6 +6,7 @@ import (
"fmt"
"github.com/grafana/grafana/pkg/models"
m
"github.com/grafana/grafana/pkg/models"
.
"github.com/smartystreets/goconvey/convey"
)
...
...
@@ -23,7 +24,7 @@ func (fn *FakeNotifier) NeedsImage() bool {
func
(
fn
*
FakeNotifier
)
Notify
(
alertResult
*
EvalContext
)
{}
func
(
fn
*
FakeNotifier
)
MatchSeverity
(
result
models
.
AlertSeverityTyp
e
)
bool
{
func
(
fn
*
FakeNotifier
)
PassesFilter
(
rule
*
Rul
e
)
bool
{
return
fn
.
FakeMatchResult
}
...
...
@@ -34,7 +35,7 @@ func TestAlertNotificationExtraction(t *testing.T) {
ctx
:=
&
EvalContext
{
Firing
:
false
,
Rule
:
&
Rule
{
S
everity
:
models
.
AlertSeverityCritical
,
S
tate
:
m
.
AlertStateAlerting
,
},
}
notifier
:=
&
FakeNotifier
{
FakeMatchResult
:
false
}
...
...
@@ -42,12 +43,12 @@ func TestAlertNotificationExtraction(t *testing.T) {
So
(
shouldUseNotification
(
notifier
,
ctx
),
ShouldBeTrue
)
})
Convey
(
"exe
uc
tion error cannot be ignored"
,
func
()
{
Convey
(
"exe
cu
tion error cannot be ignored"
,
func
()
{
ctx
:=
&
EvalContext
{
Firing
:
true
,
Error
:
fmt
.
Errorf
(
"I used to be a programmer just like you"
),
Rule
:
&
Rule
{
S
everity
:
models
.
AlertSeverityCritical
,
S
tate
:
m
.
AlertStateOK
,
},
}
notifier
:=
&
FakeNotifier
{
FakeMatchResult
:
false
}
...
...
@@ -59,7 +60,7 @@ func TestAlertNotificationExtraction(t *testing.T) {
ctx
:=
&
EvalContext
{
Firing
:
true
,
Rule
:
&
Rule
{
S
everity
:
models
.
AlertSeverityCritical
,
S
tate
:
models
.
AlertStateAlerting
,
},
}
notifier
:=
&
FakeNotifier
{
FakeMatchResult
:
true
}
...
...
@@ -70,9 +71,7 @@ func TestAlertNotificationExtraction(t *testing.T) {
Convey
(
"firing alert that dont match"
,
func
()
{
ctx
:=
&
EvalContext
{
Firing
:
true
,
Rule
:
&
Rule
{
Severity
:
models
.
AlertSeverityCritical
,
},
Rule
:
&
Rule
{
State
:
m
.
AlertStateOK
},
}
notifier
:=
&
FakeNotifier
{
FakeMatchResult
:
false
}
...
...
pkg/services/alerting/notifiers/base.go
View file @
b0c7e61e
...
...
@@ -2,33 +2,21 @@ package notifiers
import
(
"github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/
models
"
"github.com/grafana/grafana/pkg/
services/alerting
"
)
type
NotifierBase
struct
{
Name
string
Type
string
SeverityFilter
models
.
AlertSeverityType
Name
string
Type
string
}
func
NewNotifierBase
(
name
,
notifierType
string
,
model
*
simplejson
.
Json
)
NotifierBase
{
base
:=
NotifierBase
{
Name
:
name
,
Type
:
notifierType
}
severityFilter
:=
models
.
AlertSeverityType
(
model
.
Get
(
"severityFilter"
)
.
MustString
(
""
))
if
severityFilter
==
models
.
AlertSeverityCritical
||
severityFilter
==
models
.
AlertSeverityWarning
{
base
.
SeverityFilter
=
severityFilter
}
return
base
}
func
(
n
*
NotifierBase
)
MatchSeverity
(
result
models
.
AlertSeverityType
)
bool
{
if
!
n
.
SeverityFilter
.
IsValid
()
{
return
true
}
return
n
.
SeverityFilter
==
result
func
(
n
*
NotifierBase
)
PassesFilter
(
rule
*
alerting
.
Rule
)
bool
{
return
true
}
func
(
n
*
NotifierBase
)
GetType
()
string
{
...
...
pkg/services/alerting/notifiers/base_test.go
View file @
b0c7e61e
...
...
@@ -3,34 +3,32 @@ package notifiers
import
(
"testing"
"github.com/grafana/grafana/pkg/components/simplejson"
m
"github.com/grafana/grafana/pkg/models"
.
"github.com/smartystreets/goconvey/convey"
)
func
TestBaseNotifier
(
t
*
testing
.
T
)
{
Convey
(
"Parsing base notification severity
"
,
t
,
func
()
{
Convey
(
"matches"
,
func
()
{
json
:=
`
{
"severityFilter
": "critical"
}`
settingsJSON
,
_
:=
simplejson
.
NewJson
([]
byte
(
json
))
not
:=
NewNotifierBase
(
"ops"
,
"email"
,
settingsJSON
)
So
(
not
.
MatchSeverity
(
m
.
AlertSeverityCritical
),
ShouldBeTrue
)
})
Convey
(
"does not match"
,
func
()
{
json
:=
`
{
"severityFilter": "critical"
}`
settingsJSON
,
_
:=
simplejson
.
NewJson
([]
byte
(
json
))
not
:=
NewNotifierBase
(
"ops"
,
"email"
,
settingsJSON
)
So
(
not
.
MatchSeverity
(
m
.
AlertSeverityWarning
),
ShouldBeFalse
)
})
})
// Convey("Parsing base notification state
", t, func() {
//
//
Convey("matches", func() {
//
json := `
//
{
// "states
": "critical"
//
}`
//
//
settingsJSON, _ := simplejson.NewJson([]byte(json))
//
not := NewNotifierBase("ops", "email", settingsJSON)
//
So(not.MatchSeverity(m.AlertSeverityCritical), ShouldBeTrue)
//
})
//
//
Convey("does not match", func() {
//
json := `
//
{
//
"severityFilter": "critical"
//
}`
//
//
settingsJSON, _ := simplejson.NewJson([]byte(json))
//
not := NewNotifierBase("ops", "email", settingsJSON)
//
So(not.MatchSeverity(m.AlertSeverityWarning), ShouldBeFalse)
//
})
//
})
}
pkg/services/alerting/notifiers/email.go
View file @
b0c7e61e
...
...
@@ -47,16 +47,15 @@ func (this *EmailNotifier) Notify(context *alerting.EvalContext) {
cmd
:=
&
m
.
SendEmailCommand
{
Data
:
map
[
string
]
interface
{}{
"Title"
:
context
.
GetNotificationTitle
(),
"State"
:
context
.
Rule
.
State
,
"Name"
:
context
.
Rule
.
Name
,
"Severity"
:
context
.
Rule
.
Severity
,
"SeverityColor"
:
context
.
GetStateModel
()
.
Color
,
"Message"
:
context
.
Rule
.
Message
,
"RuleUrl"
:
ruleUrl
,
"ImageLink"
:
context
.
ImagePublicUrl
,
"AlertPageUrl"
:
setting
.
AppUrl
+
"alerting"
,
"EvalMatches"
:
context
.
EvalMatches
,
"Title"
:
context
.
GetNotificationTitle
(),
"State"
:
context
.
Rule
.
State
,
"Name"
:
context
.
Rule
.
Name
,
"StateModel"
:
context
.
GetStateModel
(),
"Message"
:
context
.
Rule
.
Message
,
"RuleUrl"
:
ruleUrl
,
"ImageLink"
:
context
.
ImagePublicUrl
,
"AlertPageUrl"
:
setting
.
AppUrl
+
"alerting"
,
"EvalMatches"
:
context
.
EvalMatches
,
},
To
:
this
.
Addresses
,
Template
:
"alert_notification.html"
,
...
...
pkg/services/alerting/notifiers/webhook.go
View file @
b0c7e61e
...
...
@@ -45,7 +45,6 @@ func (this *WebhookNotifier) Notify(context *alerting.EvalContext) {
bodyJSON
.
Set
(
"ruleId"
,
context
.
Rule
.
Id
)
bodyJSON
.
Set
(
"ruleName"
,
context
.
Rule
.
Name
)
bodyJSON
.
Set
(
"state"
,
context
.
Rule
.
State
)
bodyJSON
.
Set
(
"severity"
,
context
.
Rule
.
Severity
)
bodyJSON
.
Set
(
"evalMatches"
,
context
.
EvalMatches
)
ruleUrl
,
err
:=
context
.
GetRuleUrl
()
...
...
pkg/services/alerting/result_handler.go
View file @
b0c7e61e
...
...
@@ -34,11 +34,11 @@ func (handler *DefaultResultHandler) Handle(ctx *EvalContext) {
annotationData
:=
simplejson
.
New
()
if
ctx
.
Error
!=
nil
{
handler
.
log
.
Error
(
"Alert Rule Result Error"
,
"ruleId"
,
ctx
.
Rule
.
Id
,
"error"
,
ctx
.
Error
)
ctx
.
Rule
.
State
=
m
.
AlertStateExe
uction
Error
ctx
.
Rule
.
State
=
m
.
AlertStateExe
c
Error
exeuctionError
=
ctx
.
Error
.
Error
()
annotationData
.
Set
(
"errorMessage"
,
exeuctionError
)
}
else
if
ctx
.
Firing
{
ctx
.
Rule
.
State
=
m
.
AlertState
Type
(
ctx
.
Rule
.
Severity
)
ctx
.
Rule
.
State
=
m
.
AlertState
Alerting
annotationData
=
simplejson
.
NewFromAny
(
ctx
.
EvalMatches
)
}
else
{
// handle no data case
...
...
@@ -90,17 +90,15 @@ func (handler *DefaultResultHandler) Handle(ctx *EvalContext) {
func
countStateResult
(
state
m
.
AlertStateType
)
{
switch
state
{
case
m
.
AlertStateCritical
:
metrics
.
M_Alerting_Result_State_Critical
.
Inc
(
1
)
case
m
.
AlertStateWarning
:
metrics
.
M_Alerting_Result_State_Warning
.
Inc
(
1
)
case
m
.
AlertStateAlerting
:
metrics
.
M_Alerting_Result_State_Alerting
.
Inc
(
1
)
case
m
.
AlertStateOK
:
metrics
.
M_Alerting_Result_State_Ok
.
Inc
(
1
)
case
m
.
AlertStatePaused
:
metrics
.
M_Alerting_Result_State_Paused
.
Inc
(
1
)
case
m
.
AlertState
Unknown
:
metrics
.
M_Alerting_Result_State_
Unknown
.
Inc
(
1
)
case
m
.
AlertStateExe
uction
Error
:
metrics
.
M_Alerting_Result_State_Exec
ution
Error
.
Inc
(
1
)
case
m
.
AlertState
NoData
:
metrics
.
M_Alerting_Result_State_
NoData
.
Inc
(
1
)
case
m
.
AlertStateExe
c
Error
:
metrics
.
M_Alerting_Result_State_ExecError
.
Inc
(
1
)
}
}
pkg/services/alerting/rule.go
View file @
b0c7e61e
...
...
@@ -20,7 +20,6 @@ type Rule struct {
Message
string
NoDataState
m
.
AlertStateType
State
m
.
AlertStateType
Severity
m
.
AlertSeverityType
Conditions
[]
Condition
Notifications
[]
int64
}
...
...
@@ -66,9 +65,8 @@ func NewRuleFromDBAlert(ruleDef *m.Alert) (*Rule, error) {
model
.
Name
=
ruleDef
.
Name
model
.
Message
=
ruleDef
.
Message
model
.
Frequency
=
ruleDef
.
Frequency
model
.
Severity
=
ruleDef
.
Severity
model
.
State
=
ruleDef
.
State
model
.
NoDataState
=
m
.
AlertStateType
(
ruleDef
.
Settings
.
Get
(
"noDataState"
)
.
MustString
(
"
unknown
"
))
model
.
NoDataState
=
m
.
AlertStateType
(
ruleDef
.
Settings
.
Get
(
"noDataState"
)
.
MustString
(
"
no_data
"
))
for
_
,
v
:=
range
ruleDef
.
Settings
.
Get
(
"notifications"
)
.
MustArray
()
{
jsonModel
:=
simplejson
.
NewFromAny
(
v
)
...
...
pkg/services/alerting/test_notification.go
View file @
b0c7e61e
...
...
@@ -4,11 +4,11 @@ import (
"github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/log"
"github.com/grafana/grafana/pkg/models"
m
"github.com/grafana/grafana/pkg/models"
)
type
NotificationTestCommand
struct
{
S
everity
string
S
tate
m
.
AlertStateType
Name
string
Type
string
Settings
*
simplejson
.
Json
...
...
@@ -22,7 +22,7 @@ func init() {
func
handleNotificationTestCommand
(
cmd
*
NotificationTestCommand
)
error
{
notifier
:=
NewRootNotifier
()
model
:=
&
m
odels
.
AlertNotification
{
model
:=
&
m
.
AlertNotification
{
Name
:
cmd
.
Name
,
Type
:
cmd
.
Type
,
Settings
:
cmd
.
Settings
,
...
...
@@ -35,23 +35,12 @@ func handleNotificationTestCommand(cmd *NotificationTestCommand) error {
return
err
}
severity
:=
models
.
AlertSeverityType
(
cmd
.
Severity
)
notifier
.
sendNotifications
([]
Notifier
{
notifiers
},
createTestEvalContext
(
severity
))
notifier
.
sendNotifications
([]
Notifier
{
notifiers
},
createTestEvalContext
(
cmd
.
State
))
return
nil
}
func
createTestEvalContext
(
severity
models
.
AlertSeverityType
)
*
EvalContext
{
state
:=
models
.
AlertStateOK
firing
:=
false
if
severity
==
models
.
AlertSeverityCritical
{
state
=
models
.
AlertStateCritical
firing
=
true
}
if
severity
==
models
.
AlertSeverityWarning
{
state
=
models
.
AlertStateWarning
firing
=
true
}
func
createTestEvalContext
(
state
m
.
AlertStateType
)
*
EvalContext
{
testRule
:=
&
Rule
{
DashboardId
:
1
,
...
...
@@ -59,23 +48,22 @@ func createTestEvalContext(severity models.AlertSeverityType) *EvalContext {
Name
:
"Test notification"
,
Message
:
"Someone is testing the alert notification within grafana."
,
State
:
state
,
Severity
:
severity
,
}
ctx
:=
NewEvalContext
(
testRule
)
ctx
.
ImagePublicUrl
=
"http://grafana.org/assets/img/blog/mixed_styles.png"
ctx
.
IsTestRun
=
true
ctx
.
Firing
=
fir
ing
ctx
.
Firing
=
state
==
m
.
AlertStateAlert
ing
ctx
.
Error
=
nil
ctx
.
EvalMatches
=
evalMatchesBasedOnS
everity
(
severity
)
ctx
.
EvalMatches
=
evalMatchesBasedOnS
tate
(
state
)
return
ctx
}
func
evalMatchesBasedOnS
everity
(
severity
models
.
AlertSeverity
Type
)
[]
*
EvalMatch
{
func
evalMatchesBasedOnS
tate
(
state
m
.
AlertState
Type
)
[]
*
EvalMatch
{
matches
:=
make
([]
*
EvalMatch
,
0
)
if
s
everity
==
models
.
AlertSeverity
OK
{
if
s
tate
==
m
.
AlertState
OK
{
return
matches
}
...
...
pkg/services/sqlstore/alert.go
View file @
b0c7e61e
...
...
@@ -159,7 +159,7 @@ func upsertAlerts(existingAlerts []*m.Alert, cmd *m.SaveAlertsCommand, sess *xor
}
else
{
alert
.
Updated
=
time
.
Now
()
alert
.
Created
=
time
.
Now
()
alert
.
State
=
m
.
AlertState
Unknown
alert
.
State
=
m
.
AlertState
NoData
alert
.
NewStateDate
=
time
.
Now
()
_
,
err
:=
sess
.
Insert
(
alert
)
...
...
pkg/services/sqlstore/alert_test.go
View file @
b0c7e61e
...
...
@@ -47,7 +47,7 @@ func TestAlertingDataAccess(t *testing.T) {
So
(
err2
,
ShouldBeNil
)
So
(
alert
.
Name
,
ShouldEqual
,
"Alerting title"
)
So
(
alert
.
Message
,
ShouldEqual
,
"Alerting message"
)
So
(
alert
.
State
,
ShouldEqual
,
"
unknown
"
)
So
(
alert
.
State
,
ShouldEqual
,
"
no_data
"
)
So
(
alert
.
Frequency
,
ShouldEqual
,
1
)
})
...
...
@@ -77,7 +77,7 @@ func TestAlertingDataAccess(t *testing.T) {
So
(
query
.
Result
[
0
]
.
Name
,
ShouldEqual
,
"Name"
)
Convey
(
"Alert state should not be updated"
,
func
()
{
So
(
query
.
Result
[
0
]
.
State
,
ShouldEqual
,
"
unknown
"
)
So
(
query
.
Result
[
0
]
.
State
,
ShouldEqual
,
"
no_data
"
)
})
})
...
...
public/app/features/alerting/alert_def.ts
View file @
b0c7e61e
...
...
@@ -38,9 +38,8 @@ var reducerTypes = [
var
noDataModes
=
[
{
text
:
'OK'
,
value
:
'ok'
},
{
text
:
'Critical'
,
value
:
'critical'
},
{
text
:
'Warning'
,
value
:
'warning'
},
{
text
:
'Unknown'
,
value
:
'unknown'
},
{
text
:
'Alerting'
,
value
:
'alerting'
},
{
text
:
'No Data'
,
value
:
'no_data'
},
];
function
createReducerPart
(
model
)
{
...
...
@@ -48,10 +47,6 @@ function createReducerPart(model) {
return
new
QueryPart
(
model
,
def
);
}
var
severityLevels
=
{
'critical'
:
{
text
:
'Critical'
,
iconClass
:
'icon-gf icon-gf-critical'
,
stateClass
:
'alert-state-critical'
},
'warning'
:
{
text
:
'Warning'
,
iconClass
:
'icon-gf icon-gf-warning'
,
stateClass
:
'alert-state-warning'
},
};
function
getStateDisplayModel
(
state
)
{
switch
(
state
)
{
...
...
@@ -62,23 +57,16 @@ function getStateDisplayModel(state) {
stateClass
:
'alert-state-ok'
};
}
case
'
critical
'
:
{
case
'
alerting
'
:
{
return
{
text
:
'
CRITICAL
'
,
text
:
'
ALERTING
'
,
iconClass
:
'icon-gf icon-gf-critical'
,
stateClass
:
'alert-state-critical'
};
}
case
'warning'
:
{
return
{
text
:
'WARNING'
,
iconClass
:
'icon-gf icon-gf-warning'
,
stateClass
:
'alert-state-warning'
};
}
case
'unknown'
:
{
case
'no_data'
:
{
return
{
text
:
'
UNKNOWN
'
,
text
:
'
NO DATA
'
,
iconClass
:
"fa fa-question"
,
stateClass
:
'alert-state-warning'
};
...
...
@@ -106,7 +94,6 @@ export default {
getStateDisplayModel
:
getStateDisplayModel
,
conditionTypes
:
conditionTypes
,
evalFunctions
:
evalFunctions
,
severityLevels
:
severityLevels
,
noDataModes
:
noDataModes
,
reducerTypes
:
reducerTypes
,
createReducerPart
:
createReducerPart
,
...
...
public/app/features/alerting/alert_list_ctrl.ts
View file @
b0c7e61e
...
...
@@ -13,9 +13,8 @@ export class AlertListCtrl {
stateFilters
=
[
{
text
:
'All'
,
value
:
null
},
{
text
:
'OK'
,
value
:
'ok'
},
{
text
:
'Unknown'
,
value
:
'unknown'
},
{
text
:
'Warning'
,
value
:
'warning'
},
{
text
:
'Critical'
,
value
:
'critical'
},
{
text
:
'Alerting'
,
value
:
'alerting'
},
{
text
:
'No Data'
,
value
:
'no_data'
},
{
text
:
'Execution Error'
,
value
:
'execution_error'
},
];
...
...
public/app/features/alerting/alert_tab_ctrl.ts
View file @
b0c7e61e
...
...
@@ -17,7 +17,6 @@ export class AlertTabCtrl {
alert
:
any
;
conditionModels
:
any
;
evalFunctions
:
any
;
severityLevels
:
any
;
noDataModes
:
any
;
addNotificationSegment
;
notifications
;
...
...
@@ -41,7 +40,6 @@ export class AlertTabCtrl {
this
.
subTabIndex
=
0
;
this
.
evalFunctions
=
alertDef
.
evalFunctions
;
this
.
conditionTypes
=
alertDef
.
conditionTypes
;
this
.
severityLevels
=
alertDef
.
severityLevels
;
this
.
noDataModes
=
alertDef
.
noDataModes
;
this
.
appSubUrl
=
config
.
appSubUrl
;
}
...
...
@@ -155,8 +153,7 @@ export class AlertTabCtrl {
alert
.
conditions
.
push
(
this
.
buildDefaultCondition
());
}
alert
.
noDataState
=
alert
.
noDataState
||
'unknown'
;
alert
.
severity
=
alert
.
severity
||
'critical'
;
alert
.
noDataState
=
alert
.
noDataState
||
'no_data'
;
alert
.
frequency
=
alert
.
frequency
||
'60s'
;
alert
.
handler
=
alert
.
handler
||
1
;
alert
.
notifications
=
alert
.
notifications
||
[];
...
...
@@ -321,11 +318,6 @@ export class AlertTabCtrl {
this
.
panelCtrl
.
render
();
}
severityChanged
()
{
ThresholdMapper
.
alertToGraphThresholds
(
this
.
panel
);
this
.
panelCtrl
.
render
();
}
evaluatorTypeChanged
(
evaluator
)
{
// ensure params array is correct length
switch
(
evaluator
.
type
)
{
...
...
public/app/features/alerting/partials/alert_tab.html
View file @
b0c7e61e
...
...
@@ -29,18 +29,8 @@
<div
class=
"gf-form"
>
<span
class=
"gf-form-label width-8"
>
Name
</span>
<input
type=
"text"
class=
"gf-form-input width-25"
ng-model=
"ctrl.alert.name"
>
</div>
<div
class=
"gf-form-inline"
>
<div
class=
"gf-form"
>
<span
class=
"gf-form-label width-8"
>
Evaluate every
</span>
<input
class=
"gf-form-input max-width-7"
type=
"text"
ng-model=
"ctrl.alert.frequency"
></input>
</div>
<div
class=
"gf-form"
>
<span
class=
"gf-form-label"
>
Severity
</span>
<div
class=
"gf-form-select-wrapper width-13"
>
<select
class=
"gf-form-input"
ng-model=
"ctrl.alert.severity"
ng-options=
"key as value.text for (key, value) in ctrl.severityLevels"
ng-change=
"ctrl.severityChanged()"
>
</select>
</div>
<span
class=
"gf-form-label width-8"
>
Evaluate every
</span>
<input
class=
"gf-form-input max-width-5"
type=
"text"
ng-model=
"ctrl.alert.frequency"
></input>
</div>
</div>
</div>
...
...
public/app/features/alerting/threshold_mapper.ts
View file @
b0c7e61e
...
...
@@ -62,7 +62,7 @@ export class ThresholdMapper {
for
(
var
t
of
panel
.
thresholds
)
{
t
.
fill
=
true
;
t
.
line
=
true
;
t
.
colorMode
=
panel
.
alert
.
severity
;
t
.
colorMode
=
'critical'
;
}
var
updated
=
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