2016-06-13 16:39:00 +02:00
|
|
|
package models
|
|
|
|
|
|
|
|
import (
|
2018-05-25 14:14:33 -04:00
|
|
|
"errors"
|
2016-06-13 16:39:00 +02:00
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/grafana/grafana/pkg/components/simplejson"
|
|
|
|
)
|
|
|
|
|
2018-05-25 14:14:33 -04:00
|
|
|
var (
|
2018-12-14 11:53:50 +02:00
|
|
|
ErrNotificationFrequencyNotFound = errors.New("Notification frequency not specified")
|
|
|
|
ErrAlertNotificationStateNotFound = errors.New("alert notification state not found")
|
|
|
|
ErrAlertNotificationStateVersionConflict = errors.New("alert notification state update version conflict")
|
2019-04-23 11:24:47 +03:00
|
|
|
ErrAlertNotificationStateAlreadyExist = errors.New("alert notification state already exists")
|
2018-12-14 11:53:50 +02:00
|
|
|
ErrAlertNotificationFailedGenerateUniqueUid = errors.New("Failed to generate unique alert notification uid")
|
2018-09-27 11:14:44 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
type AlertNotificationStateType string
|
|
|
|
|
|
|
|
var (
|
|
|
|
AlertNotificationStatePending = AlertNotificationStateType("pending")
|
|
|
|
AlertNotificationStateCompleted = AlertNotificationStateType("completed")
|
2018-10-02 11:19:09 +02:00
|
|
|
AlertNotificationStateUnknown = AlertNotificationStateType("unknown")
|
2018-05-25 14:14:33 -04:00
|
|
|
)
|
|
|
|
|
2016-06-13 16:39:00 +02:00
|
|
|
type AlertNotification struct {
|
2018-10-17 10:41:18 +02:00
|
|
|
Id int64 `json:"id"`
|
2018-12-14 11:53:50 +02:00
|
|
|
Uid string `json:"-"`
|
2018-10-17 10:41:18 +02:00
|
|
|
OrgId int64 `json:"-"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
Type string `json:"type"`
|
|
|
|
SendReminder bool `json:"sendReminder"`
|
|
|
|
DisableResolveMessage bool `json:"disableResolveMessage"`
|
|
|
|
Frequency time.Duration `json:"frequency"`
|
|
|
|
IsDefault bool `json:"isDefault"`
|
|
|
|
Settings *simplejson.Json `json:"settings"`
|
|
|
|
Created time.Time `json:"created"`
|
|
|
|
Updated time.Time `json:"updated"`
|
2016-06-13 16:39:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type CreateAlertNotificationCommand struct {
|
2019-04-04 17:52:40 +02:00
|
|
|
Uid string `json:"uid"`
|
2018-10-17 10:41:18 +02:00
|
|
|
Name string `json:"name" binding:"Required"`
|
|
|
|
Type string `json:"type" binding:"Required"`
|
|
|
|
SendReminder bool `json:"sendReminder"`
|
|
|
|
DisableResolveMessage bool `json:"disableResolveMessage"`
|
|
|
|
Frequency string `json:"frequency"`
|
|
|
|
IsDefault bool `json:"isDefault"`
|
|
|
|
Settings *simplejson.Json `json:"settings"`
|
2016-06-13 16:39:00 +02:00
|
|
|
|
2016-07-22 16:45:17 +02:00
|
|
|
OrgId int64 `json:"-"`
|
2016-06-13 16:39:00 +02:00
|
|
|
Result *AlertNotification
|
|
|
|
}
|
|
|
|
|
|
|
|
type UpdateAlertNotificationCommand struct {
|
2018-10-17 10:41:18 +02:00
|
|
|
Id int64 `json:"id" binding:"Required"`
|
2019-03-29 15:42:38 +07:00
|
|
|
Uid string `json:"uid"`
|
2018-10-17 10:41:18 +02:00
|
|
|
Name string `json:"name" binding:"Required"`
|
|
|
|
Type string `json:"type" binding:"Required"`
|
|
|
|
SendReminder bool `json:"sendReminder"`
|
|
|
|
DisableResolveMessage bool `json:"disableResolveMessage"`
|
|
|
|
Frequency string `json:"frequency"`
|
|
|
|
IsDefault bool `json:"isDefault"`
|
|
|
|
Settings *simplejson.Json `json:"settings" binding:"Required"`
|
2016-06-13 16:39:00 +02:00
|
|
|
|
2016-07-22 16:45:17 +02:00
|
|
|
OrgId int64 `json:"-"`
|
2016-06-13 16:39:00 +02:00
|
|
|
Result *AlertNotification
|
|
|
|
}
|
|
|
|
|
2018-12-14 11:53:50 +02:00
|
|
|
type UpdateAlertNotificationWithUidCommand struct {
|
2019-03-26 18:37:02 +07:00
|
|
|
Uid string `json:"-"`
|
2019-03-29 15:42:38 +07:00
|
|
|
NewUid string `json:"uid"`
|
2019-03-26 18:37:02 +07:00
|
|
|
Name string `json:"name" binding:"Required"`
|
|
|
|
Type string `json:"type" binding:"Required"`
|
|
|
|
SendReminder bool `json:"sendReminder"`
|
|
|
|
DisableResolveMessage bool `json:"disableResolveMessage"`
|
|
|
|
Frequency string `json:"frequency"`
|
|
|
|
IsDefault bool `json:"isDefault"`
|
|
|
|
Settings *simplejson.Json `json:"settings" binding:"Required"`
|
2018-12-14 11:53:50 +02:00
|
|
|
|
|
|
|
OrgId int64
|
|
|
|
Result *AlertNotification
|
|
|
|
}
|
|
|
|
|
2016-06-16 15:21:44 +02:00
|
|
|
type DeleteAlertNotificationCommand struct {
|
|
|
|
Id int64
|
|
|
|
OrgId int64
|
|
|
|
}
|
2018-12-14 11:53:50 +02:00
|
|
|
type DeleteAlertNotificationWithUidCommand struct {
|
|
|
|
Uid string
|
|
|
|
OrgId int64
|
|
|
|
}
|
2016-06-16 15:21:44 +02:00
|
|
|
|
2016-07-22 16:45:17 +02:00
|
|
|
type GetAlertNotificationsQuery struct {
|
|
|
|
Name string
|
|
|
|
Id int64
|
2016-09-06 08:42:35 +02:00
|
|
|
OrgId int64
|
|
|
|
|
|
|
|
Result *AlertNotification
|
|
|
|
}
|
|
|
|
|
2018-12-14 11:53:50 +02:00
|
|
|
type GetAlertNotificationsWithUidQuery struct {
|
|
|
|
Uid string
|
|
|
|
OrgId int64
|
|
|
|
|
|
|
|
Result *AlertNotification
|
|
|
|
}
|
|
|
|
|
|
|
|
type GetAlertNotificationsWithUidToSendQuery struct {
|
|
|
|
Uids []string
|
2016-07-22 16:45:17 +02:00
|
|
|
OrgId int64
|
2016-06-13 16:39:00 +02:00
|
|
|
|
|
|
|
Result []*AlertNotification
|
|
|
|
}
|
2016-09-06 08:42:35 +02:00
|
|
|
|
|
|
|
type GetAllAlertNotificationsQuery struct {
|
|
|
|
OrgId int64
|
|
|
|
|
|
|
|
Result []*AlertNotification
|
|
|
|
}
|
2018-05-19 16:21:00 -04:00
|
|
|
|
2018-09-26 17:26:02 +02:00
|
|
|
type AlertNotificationState struct {
|
2018-10-02 11:19:09 +02:00
|
|
|
Id int64
|
|
|
|
OrgId int64
|
|
|
|
AlertId int64
|
|
|
|
NotifierId int64
|
|
|
|
State AlertNotificationStateType
|
|
|
|
Version int64
|
|
|
|
UpdatedAt int64
|
|
|
|
AlertRuleStateUpdatedVersion int64
|
2018-05-19 16:21:00 -04:00
|
|
|
}
|
|
|
|
|
2018-09-27 11:33:13 +02:00
|
|
|
type SetAlertNotificationStateToPendingCommand struct {
|
2018-10-02 13:57:41 +02:00
|
|
|
Id int64
|
2018-10-01 14:13:03 +02:00
|
|
|
AlertRuleStateUpdatedVersion int64
|
2018-10-02 13:57:41 +02:00
|
|
|
Version int64
|
|
|
|
|
|
|
|
ResultVersion int64
|
2018-05-19 16:21:00 -04:00
|
|
|
}
|
|
|
|
|
2018-09-27 11:33:13 +02:00
|
|
|
type SetAlertNotificationStateToCompleteCommand struct {
|
2018-10-02 13:57:41 +02:00
|
|
|
Id int64
|
|
|
|
Version int64
|
2018-09-27 11:33:13 +02:00
|
|
|
}
|
|
|
|
|
2018-10-02 11:23:40 +02:00
|
|
|
type GetOrCreateNotificationStateQuery struct {
|
2018-05-19 16:21:00 -04:00
|
|
|
OrgId int64
|
|
|
|
AlertId int64
|
|
|
|
NotifierId int64
|
|
|
|
|
2018-09-26 17:26:02 +02:00
|
|
|
Result *AlertNotificationState
|
2018-05-19 16:21:00 -04:00
|
|
|
}
|