feat(alerting): working on state management
This commit is contained in:
+33
-30
@@ -6,6 +6,29 @@ import (
|
||||
"github.com/grafana/grafana/pkg/components/simplejson"
|
||||
)
|
||||
|
||||
type AlertStateType string
|
||||
type AlertSeverityType string
|
||||
|
||||
const (
|
||||
AlertStatePending AlertStateType = "pending"
|
||||
AlertStateFiring AlertStateType = "firing"
|
||||
AlertStateOK AlertStateType = "ok"
|
||||
)
|
||||
|
||||
func (s AlertStateType) IsValid() bool {
|
||||
return s == AlertStatePending || s == AlertStateFiring || s == AlertStateOK
|
||||
}
|
||||
|
||||
const (
|
||||
AlertSeverityCritical AlertSeverityType = "critical"
|
||||
AlertSeverityWarning AlertSeverityType = "warning"
|
||||
AlertSeverityInfo AlertSeverityType = "info"
|
||||
)
|
||||
|
||||
func (s AlertSeverityType) IsValid() bool {
|
||||
return s == AlertSeverityCritical || s == AlertSeverityInfo || s == AlertSeverityWarning
|
||||
}
|
||||
|
||||
type Alert struct {
|
||||
Id int64
|
||||
OrgId int64
|
||||
@@ -13,8 +36,8 @@ type Alert struct {
|
||||
PanelId int64
|
||||
Name string
|
||||
Description string
|
||||
Severity string
|
||||
State string
|
||||
Severity AlertSeverityType
|
||||
State AlertStateType
|
||||
Handler int64
|
||||
Enabled bool
|
||||
Frequency int64
|
||||
@@ -32,7 +55,7 @@ func (alert *Alert) ValidToSave() bool {
|
||||
return alert.DashboardId != 0 && alert.OrgId != 0 && alert.PanelId != 0
|
||||
}
|
||||
|
||||
func (alert *Alert) ShouldUpdateState(newState string) bool {
|
||||
func (alert *Alert) ShouldUpdateState(newState AlertStateType) bool {
|
||||
return alert.State != newState
|
||||
}
|
||||
|
||||
@@ -74,25 +97,6 @@ type HeartBeatCommand struct {
|
||||
Result AlertingClusterInfo
|
||||
}
|
||||
|
||||
type AlertChange struct {
|
||||
Id int64 `json:"id"`
|
||||
OrgId int64 `json:"-"`
|
||||
AlertId int64 `json:"alertId"`
|
||||
UpdatedBy int64 `json:"updatedBy"`
|
||||
NewAlertSettings *simplejson.Json `json:"newAlertSettings"`
|
||||
Type string `json:"type"`
|
||||
Created time.Time `json:"created"`
|
||||
}
|
||||
|
||||
// Commands
|
||||
type CreateAlertChangeCommand struct {
|
||||
OrgId int64
|
||||
AlertId int64
|
||||
UpdatedBy int64
|
||||
NewAlertSettings *simplejson.Json
|
||||
Type string
|
||||
}
|
||||
|
||||
type SaveAlertsCommand struct {
|
||||
DashboardId int64
|
||||
UserId int64
|
||||
@@ -101,6 +105,13 @@ type SaveAlertsCommand struct {
|
||||
Alerts []*Alert
|
||||
}
|
||||
|
||||
type SetAlertStateCommand struct {
|
||||
AlertId int64
|
||||
OrgId int64
|
||||
State AlertStateType
|
||||
Timestamp time.Time
|
||||
}
|
||||
|
||||
type DeleteAlertCommand struct {
|
||||
AlertId int64
|
||||
}
|
||||
@@ -124,11 +135,3 @@ type GetAlertByIdQuery struct {
|
||||
|
||||
Result *Alert
|
||||
}
|
||||
|
||||
type GetAlertChangesQuery struct {
|
||||
OrgId int64
|
||||
Limit int64
|
||||
SinceId int64
|
||||
|
||||
Result []*AlertChange
|
||||
}
|
||||
|
||||
+45
-52
@@ -1,54 +1,47 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/grafana/grafana/pkg/components/simplejson"
|
||||
"github.com/grafana/grafana/pkg/services/alerting/alertstates"
|
||||
)
|
||||
|
||||
type AlertState struct {
|
||||
Id int64 `json:"-"`
|
||||
OrgId int64 `json:"-"`
|
||||
AlertId int64 `json:"alertId"`
|
||||
State string `json:"state"`
|
||||
Created time.Time `json:"created"`
|
||||
Info string `json:"info"`
|
||||
TriggeredAlerts *simplejson.Json `json:"triggeredAlerts"`
|
||||
}
|
||||
|
||||
func (this *UpdateAlertStateCommand) IsValidState() bool {
|
||||
for _, v := range alertstates.ValidStates {
|
||||
if this.State == v {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Commands
|
||||
|
||||
type UpdateAlertStateCommand struct {
|
||||
AlertId int64 `json:"alertId" binding:"Required"`
|
||||
OrgId int64 `json:"orgId" binding:"Required"`
|
||||
State string `json:"state" binding:"Required"`
|
||||
Info string `json:"info"`
|
||||
|
||||
Result *Alert
|
||||
}
|
||||
|
||||
// Queries
|
||||
|
||||
type GetAlertsStateQuery struct {
|
||||
OrgId int64 `json:"orgId" binding:"Required"`
|
||||
AlertId int64 `json:"alertId" binding:"Required"`
|
||||
|
||||
Result *[]AlertState
|
||||
}
|
||||
|
||||
type GetLastAlertStateQuery struct {
|
||||
AlertId int64
|
||||
OrgId int64
|
||||
|
||||
Result *AlertState
|
||||
}
|
||||
// type AlertState struct {
|
||||
// Id int64 `json:"-"`
|
||||
// OrgId int64 `json:"-"`
|
||||
// AlertId int64 `json:"alertId"`
|
||||
// State string `json:"state"`
|
||||
// Created time.Time `json:"created"`
|
||||
// Info string `json:"info"`
|
||||
// TriggeredAlerts *simplejson.Json `json:"triggeredAlerts"`
|
||||
// }
|
||||
//
|
||||
// func (this *UpdateAlertStateCommand) IsValidState() bool {
|
||||
// for _, v := range alertstates.ValidStates {
|
||||
// if this.State == v {
|
||||
// return true
|
||||
// }
|
||||
// }
|
||||
// return false
|
||||
// }
|
||||
//
|
||||
// // Commands
|
||||
//
|
||||
// type UpdateAlertStateCommand struct {
|
||||
// AlertId int64 `json:"alertId" binding:"Required"`
|
||||
// OrgId int64 `json:"orgId" binding:"Required"`
|
||||
// State string `json:"state" binding:"Required"`
|
||||
// Info string `json:"info"`
|
||||
//
|
||||
// Result *Alert
|
||||
// }
|
||||
//
|
||||
// // Queries
|
||||
//
|
||||
// type GetAlertsStateQuery struct {
|
||||
// OrgId int64 `json:"orgId" binding:"Required"`
|
||||
// AlertId int64 `json:"alertId" binding:"Required"`
|
||||
//
|
||||
// Result *[]AlertState
|
||||
// }
|
||||
//
|
||||
// type GetLastAlertStateQuery struct {
|
||||
// AlertId int64
|
||||
// OrgId int64
|
||||
//
|
||||
// Result *AlertState
|
||||
// }
|
||||
|
||||
Reference in New Issue
Block a user