2016-04-27 06:02:28 -05:00
|
|
|
package dtos
|
|
|
|
|
2016-07-20 09:13:36 -05:00
|
|
|
import (
|
2018-06-04 15:19:27 -05:00
|
|
|
"strings"
|
2016-07-20 09:13:36 -05:00
|
|
|
"time"
|
|
|
|
|
2017-01-13 05:32:30 -06:00
|
|
|
"github.com/grafana/grafana/pkg/components/null"
|
2016-07-20 09:13:36 -05:00
|
|
|
"github.com/grafana/grafana/pkg/components/simplejson"
|
2018-06-04 15:19:27 -05:00
|
|
|
"github.com/grafana/grafana/pkg/models"
|
2016-07-20 09:13:36 -05:00
|
|
|
)
|
2016-06-20 04:31:20 -05:00
|
|
|
|
2016-07-22 09:45:17 -05:00
|
|
|
type AlertRule struct {
|
2018-06-04 15:19:27 -05:00
|
|
|
Id int64 `json:"id"`
|
|
|
|
DashboardId int64 `json:"dashboardId"`
|
|
|
|
PanelId int64 `json:"panelId"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
Message string `json:"message"`
|
|
|
|
State models.AlertStateType `json:"state"`
|
|
|
|
NewStateDate time.Time `json:"newStateDate"`
|
|
|
|
EvalDate time.Time `json:"evalDate"`
|
|
|
|
EvalData *simplejson.Json `json:"evalData"`
|
|
|
|
ExecutionError string `json:"executionError"`
|
|
|
|
Url string `json:"url"`
|
|
|
|
CanEdit bool `json:"canEdit"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func removeZeroesFromDuration(interval time.Duration) string {
|
|
|
|
frequency := interval.String()
|
|
|
|
|
|
|
|
frequency = strings.Replace(frequency, "0h", "", 1)
|
|
|
|
frequency = strings.Replace(frequency, "0m", "", 1)
|
|
|
|
frequency = strings.Replace(frequency, "0s", "", 1)
|
|
|
|
|
|
|
|
return frequency
|
|
|
|
}
|
|
|
|
|
|
|
|
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: removeZeroesFromDuration(notification.Frequency),
|
|
|
|
NotifyOnce: notification.NotifyOnce,
|
|
|
|
Settings: notification.Settings,
|
|
|
|
}
|
2016-04-27 06:02:28 -05:00
|
|
|
}
|
2016-06-20 04:31:20 -05:00
|
|
|
|
2016-07-22 09:45:17 -05:00
|
|
|
type AlertNotification struct {
|
2018-05-20 11:12:10 -05:00
|
|
|
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"`
|
2016-06-20 04:31:20 -05:00
|
|
|
}
|
2016-07-20 09:13:36 -05:00
|
|
|
|
2016-07-21 03:29:11 -05:00
|
|
|
type AlertTestCommand struct {
|
|
|
|
Dashboard *simplejson.Json `json:"dashboard" binding:"Required"`
|
|
|
|
PanelId int64 `json:"panelId" binding:"Required"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type AlertTestResult struct {
|
2016-11-17 08:48:15 -06:00
|
|
|
Firing bool `json:"firing"`
|
2018-06-04 15:19:27 -05:00
|
|
|
State models.AlertStateType `json:"state"`
|
2016-11-17 08:48:15 -06:00
|
|
|
ConditionEvals string `json:"conditionEvals"`
|
|
|
|
TimeMs string `json:"timeMs"`
|
|
|
|
Error string `json:"error,omitempty"`
|
|
|
|
EvalMatches []*EvalMatch `json:"matches,omitempty"`
|
|
|
|
Logs []*AlertTestResultLog `json:"logs,omitempty"`
|
2016-07-21 06:09:12 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
type AlertTestResultLog struct {
|
|
|
|
Message string `json:"message"`
|
|
|
|
Data interface{} `json:"data"`
|
2016-07-20 09:13:36 -05:00
|
|
|
}
|
2016-07-21 14:54:12 -05:00
|
|
|
|
2016-08-18 04:22:24 -05:00
|
|
|
type EvalMatch struct {
|
|
|
|
Tags map[string]string `json:"tags,omitempty"`
|
|
|
|
Metric string `json:"metric"`
|
2017-01-13 05:32:30 -06:00
|
|
|
Value null.Float `json:"value"`
|
2016-07-21 14:54:12 -05:00
|
|
|
}
|
2016-08-30 02:32:56 -05:00
|
|
|
|
2016-09-05 07:43:53 -05:00
|
|
|
type NotificationTestCommand struct {
|
2018-05-19 15:21:00 -05:00
|
|
|
Name string `json:"name"`
|
|
|
|
Type string `json:"type"`
|
|
|
|
NotifyOnce bool `json:"notifyOnce"`
|
2018-05-20 11:12:10 -05:00
|
|
|
Frequency string `json:"frequency"`
|
2018-05-19 15:21:00 -05:00
|
|
|
Settings *simplejson.Json `json:"settings"`
|
2016-09-05 07:43:53 -05:00
|
|
|
}
|
2016-10-10 07:26:09 -05:00
|
|
|
|
|
|
|
type PauseAlertCommand struct {
|
2016-10-11 03:53:24 -05:00
|
|
|
AlertId int64 `json:"alertId"`
|
|
|
|
Paused bool `json:"paused"`
|
2016-10-10 07:26:09 -05:00
|
|
|
}
|
2016-12-15 10:01:45 -06:00
|
|
|
|
2016-12-19 06:24:45 -06:00
|
|
|
type PauseAllAlertsCommand struct {
|
|
|
|
Paused bool `json:"paused"`
|
2016-12-15 10:01:45 -06:00
|
|
|
}
|