2016-04-13 16:33:45 +08:00
|
|
|
package models
|
|
|
|
|
|
|
|
import (
|
2016-04-25 22:18:28 +08:00
|
|
|
"time"
|
2016-06-10 04:21:28 +08:00
|
|
|
|
|
|
|
"github.com/grafana/grafana/pkg/components/simplejson"
|
2016-04-13 16:33:45 +08:00
|
|
|
)
|
|
|
|
|
2016-06-11 16:26:48 +08:00
|
|
|
type Alert struct {
|
2016-06-10 04:21:28 +08:00
|
|
|
Id int64
|
|
|
|
OrgId int64
|
|
|
|
DashboardId int64
|
|
|
|
PanelId int64
|
|
|
|
Name string
|
|
|
|
Description string
|
|
|
|
State string
|
2016-06-13 21:58:22 +08:00
|
|
|
Handler int64
|
2016-06-11 16:13:33 +08:00
|
|
|
Enabled bool
|
2016-06-10 04:21:28 +08:00
|
|
|
|
|
|
|
Created time.Time
|
|
|
|
Updated time.Time
|
|
|
|
|
2016-06-13 21:18:19 +08:00
|
|
|
Settings *simplejson.Json
|
2016-04-13 16:33:45 +08:00
|
|
|
}
|
|
|
|
|
2016-06-11 16:26:48 +08:00
|
|
|
func (alert *Alert) ValidToSave() bool {
|
2016-06-13 21:01:07 +08:00
|
|
|
return alert.DashboardId != 0 && alert.OrgId != 0 && alert.PanelId != 0
|
2016-06-10 16:00:00 +08:00
|
|
|
}
|
|
|
|
|
2016-06-11 16:26:48 +08:00
|
|
|
func (this *Alert) ContainsUpdates(other *Alert) bool {
|
2016-05-30 23:50:35 +08:00
|
|
|
result := false
|
2016-06-06 23:11:46 +08:00
|
|
|
result = result || this.Name != other.Name
|
2016-05-30 23:50:35 +08:00
|
|
|
result = result || this.Description != other.Description
|
2016-06-10 04:21:28 +08:00
|
|
|
|
2016-06-13 21:18:19 +08:00
|
|
|
if this.Settings != nil && other.Settings != nil {
|
|
|
|
json1, err1 := this.Settings.Encode()
|
|
|
|
json2, err2 := other.Settings.Encode()
|
2016-06-10 04:21:28 +08:00
|
|
|
|
2016-06-10 17:37:03 +08:00
|
|
|
if err1 != nil || err2 != nil {
|
|
|
|
return false
|
|
|
|
}
|
2016-06-10 04:21:28 +08:00
|
|
|
|
2016-06-10 17:37:03 +08:00
|
|
|
result = result || string(json1) != string(json2)
|
|
|
|
}
|
2016-06-10 04:21:28 +08:00
|
|
|
|
2016-05-30 23:50:35 +08:00
|
|
|
//don't compare .State! That would be insane.
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
2016-05-23 20:51:41 +08:00
|
|
|
type AlertingClusterInfo struct {
|
|
|
|
ServerId string
|
|
|
|
ClusterSize int
|
|
|
|
UptimePosition int
|
|
|
|
}
|
|
|
|
|
2016-06-09 16:00:34 +08:00
|
|
|
type HeartBeat struct {
|
|
|
|
Id int64
|
|
|
|
ServerId string
|
|
|
|
Updated time.Time
|
|
|
|
Created time.Time
|
|
|
|
}
|
|
|
|
|
2016-05-23 20:51:41 +08:00
|
|
|
type HeartBeatCommand struct {
|
2016-05-23 16:02:17 +08:00
|
|
|
ServerId string
|
2016-06-11 16:26:48 +08:00
|
|
|
Result AlertingClusterInfo
|
2016-05-23 16:02:17 +08:00
|
|
|
}
|
|
|
|
|
2016-06-11 16:26:48 +08:00
|
|
|
type AlertChange struct {
|
2016-05-04 15:57:53 +08:00
|
|
|
Id int64 `json:"id"`
|
2016-04-27 17:44:04 +08:00
|
|
|
OrgId int64 `json:"-"`
|
|
|
|
AlertId int64 `json:"alertId"`
|
|
|
|
Type string `json:"type"`
|
|
|
|
Created time.Time `json:"created"`
|
2016-04-25 22:18:28 +08:00
|
|
|
}
|
|
|
|
|
2016-04-13 16:33:45 +08:00
|
|
|
// Commands
|
|
|
|
type SaveAlertsCommand struct {
|
|
|
|
DashboardId int64
|
|
|
|
UserId int64
|
|
|
|
OrgId int64
|
|
|
|
|
2016-06-11 16:26:48 +08:00
|
|
|
Alerts []*Alert
|
2016-04-13 16:33:45 +08:00
|
|
|
}
|
2016-04-26 23:36:50 +08:00
|
|
|
|
2016-05-02 22:07:19 +08:00
|
|
|
type DeleteAlertCommand struct {
|
|
|
|
AlertId int64
|
|
|
|
}
|
|
|
|
|
2016-04-26 23:36:50 +08:00
|
|
|
//Queries
|
|
|
|
type GetAlertsQuery struct {
|
2016-05-10 15:45:56 +08:00
|
|
|
OrgId int64
|
|
|
|
State []string
|
|
|
|
DashboardId int64
|
|
|
|
PanelId int64
|
2016-04-26 23:36:50 +08:00
|
|
|
|
2016-06-11 16:26:48 +08:00
|
|
|
Result []*Alert
|
2016-04-26 23:36:50 +08:00
|
|
|
}
|
|
|
|
|
2016-06-03 21:24:53 +08:00
|
|
|
type GetAllAlertsQuery struct {
|
2016-06-11 16:26:48 +08:00
|
|
|
Result []*Alert
|
2016-05-16 21:39:09 +08:00
|
|
|
}
|
|
|
|
|
2016-04-28 14:23:50 +08:00
|
|
|
type GetAlertByIdQuery struct {
|
2016-04-26 23:36:50 +08:00
|
|
|
Id int64
|
|
|
|
|
2016-06-11 16:26:48 +08:00
|
|
|
Result *Alert
|
2016-04-26 23:36:50 +08:00
|
|
|
}
|
2016-04-27 14:59:33 +08:00
|
|
|
|
|
|
|
type GetAlertChangesQuery struct {
|
2016-05-04 15:57:53 +08:00
|
|
|
OrgId int64
|
|
|
|
Limit int64
|
|
|
|
SinceId int64
|
2016-04-27 14:59:33 +08:00
|
|
|
|
2016-06-11 16:26:48 +08:00
|
|
|
Result []*AlertChange
|
2016-04-27 14:59:33 +08:00
|
|
|
}
|