2016-06-13 09:39:00 -05:00
|
|
|
package models
|
|
|
|
|
|
|
|
import (
|
2018-05-25 13:14:33 -05:00
|
|
|
"errors"
|
2016-06-13 09:39:00 -05:00
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/grafana/grafana/pkg/components/simplejson"
|
|
|
|
)
|
|
|
|
|
2018-05-25 13:14:33 -05:00
|
|
|
var (
|
2020-11-05 06:07:06 -06:00
|
|
|
ErrAlertNotificationNotFound = errors.New("alert notification not found")
|
|
|
|
ErrNotificationFrequencyNotFound = errors.New("notification frequency not specified")
|
2018-12-14 03:53:50 -06:00
|
|
|
ErrAlertNotificationStateVersionConflict = errors.New("alert notification state update version conflict")
|
2020-11-05 06:07:06 -06:00
|
|
|
ErrAlertNotificationFailedGenerateUniqueUid = errors.New("failed to generate unique alert notification uid")
|
|
|
|
ErrAlertNotificationFailedTranslateUniqueID = errors.New("failed to translate Notification Id to Uid")
|
2020-10-20 06:53:48 -05:00
|
|
|
ErrAlertNotificationWithSameNameExists = errors.New("alert notification with same name already exists")
|
|
|
|
ErrAlertNotificationWithSameUIDExists = errors.New("alert notification with same uid already exists")
|
2018-09-27 04:14:44 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
type AlertNotificationStateType string
|
|
|
|
|
|
|
|
var (
|
|
|
|
AlertNotificationStatePending = AlertNotificationStateType("pending")
|
|
|
|
AlertNotificationStateCompleted = AlertNotificationStateType("completed")
|
2018-10-02 04:19:09 -05:00
|
|
|
AlertNotificationStateUnknown = AlertNotificationStateType("unknown")
|
2018-05-25 13:14:33 -05:00
|
|
|
)
|
|
|
|
|
2016-06-13 09:39:00 -05:00
|
|
|
type AlertNotification struct {
|
2021-10-07 09:33:50 -05:00
|
|
|
Id int64 `json:"id"`
|
|
|
|
Uid string `json:"-"`
|
|
|
|
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"`
|
|
|
|
SecureSettings map[string][]byte `json:"secureSettings"`
|
|
|
|
Created time.Time `json:"created"`
|
|
|
|
Updated time.Time `json:"updated"`
|
2016-06-13 09:39:00 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
type CreateAlertNotificationCommand struct {
|
2020-07-08 03:17:05 -05:00
|
|
|
Uid string `json:"uid"`
|
|
|
|
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"`
|
|
|
|
SecureSettings map[string]string `json:"secureSettings"`
|
2016-06-13 09:39:00 -05:00
|
|
|
|
2021-10-07 09:33:50 -05:00
|
|
|
OrgId int64 `json:"-"`
|
|
|
|
EncryptedSecureSettings map[string][]byte `json:"-"`
|
|
|
|
|
2022-02-08 06:38:43 -06:00
|
|
|
Result *AlertNotification `json:"-"`
|
2016-06-13 09:39:00 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
type UpdateAlertNotificationCommand struct {
|
2020-07-08 03:17:05 -05:00
|
|
|
Id int64 `json:"id" binding:"Required"`
|
|
|
|
Uid string `json:"uid"`
|
|
|
|
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"`
|
|
|
|
SecureSettings map[string]string `json:"secureSettings"`
|
2016-06-13 09:39:00 -05:00
|
|
|
|
2021-10-07 09:33:50 -05:00
|
|
|
OrgId int64 `json:"-"`
|
|
|
|
EncryptedSecureSettings map[string][]byte `json:"-"`
|
|
|
|
|
2022-02-08 06:38:43 -06:00
|
|
|
Result *AlertNotification `json:"-"`
|
2016-06-13 09:39:00 -05:00
|
|
|
}
|
|
|
|
|
2018-12-14 03:53:50 -06:00
|
|
|
type UpdateAlertNotificationWithUidCommand struct {
|
2020-07-08 03:17:05 -05:00
|
|
|
Uid string `json:"-"`
|
|
|
|
NewUid string `json:"uid"`
|
|
|
|
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"`
|
|
|
|
SecureSettings map[string]string `json:"secureSettings"`
|
2018-12-14 03:53:50 -06:00
|
|
|
|
2022-02-08 06:38:43 -06:00
|
|
|
OrgId int64 `json:"-"`
|
|
|
|
Result *AlertNotification `json:"-"`
|
2018-12-14 03:53:50 -06:00
|
|
|
}
|
|
|
|
|
2016-06-16 08:21:44 -05:00
|
|
|
type DeleteAlertNotificationCommand struct {
|
|
|
|
Id int64
|
|
|
|
OrgId int64
|
|
|
|
}
|
2018-12-14 03:53:50 -06:00
|
|
|
type DeleteAlertNotificationWithUidCommand struct {
|
|
|
|
Uid string
|
|
|
|
OrgId int64
|
2020-09-11 11:04:43 -05:00
|
|
|
|
|
|
|
DeletedAlertNotificationId int64
|
2018-12-14 03:53:50 -06:00
|
|
|
}
|
2016-06-16 08:21:44 -05:00
|
|
|
|
2020-03-18 08:00:56 -05:00
|
|
|
type GetAlertNotificationUidQuery struct {
|
|
|
|
Id int64
|
|
|
|
OrgId int64
|
|
|
|
|
|
|
|
Result string
|
|
|
|
}
|
|
|
|
|
2016-07-22 09:45:17 -05:00
|
|
|
type GetAlertNotificationsQuery struct {
|
|
|
|
Name string
|
|
|
|
Id int64
|
2016-09-06 01:42:35 -05:00
|
|
|
OrgId int64
|
|
|
|
|
|
|
|
Result *AlertNotification
|
|
|
|
}
|
|
|
|
|
2018-12-14 03:53:50 -06:00
|
|
|
type GetAlertNotificationsWithUidQuery struct {
|
|
|
|
Uid string
|
|
|
|
OrgId int64
|
|
|
|
|
|
|
|
Result *AlertNotification
|
|
|
|
}
|
|
|
|
|
|
|
|
type GetAlertNotificationsWithUidToSendQuery struct {
|
|
|
|
Uids []string
|
2016-07-22 09:45:17 -05:00
|
|
|
OrgId int64
|
2016-06-13 09:39:00 -05:00
|
|
|
|
|
|
|
Result []*AlertNotification
|
|
|
|
}
|
2016-09-06 01:42:35 -05:00
|
|
|
|
|
|
|
type GetAllAlertNotificationsQuery struct {
|
|
|
|
OrgId int64
|
|
|
|
|
|
|
|
Result []*AlertNotification
|
|
|
|
}
|
2018-05-19 15:21:00 -05:00
|
|
|
|
2018-09-26 10:26:02 -05:00
|
|
|
type AlertNotificationState struct {
|
2018-10-02 04:19:09 -05:00
|
|
|
Id int64
|
|
|
|
OrgId int64
|
|
|
|
AlertId int64
|
|
|
|
NotifierId int64
|
|
|
|
State AlertNotificationStateType
|
|
|
|
Version int64
|
|
|
|
UpdatedAt int64
|
|
|
|
AlertRuleStateUpdatedVersion int64
|
2018-05-19 15:21:00 -05:00
|
|
|
}
|
|
|
|
|
2018-09-27 04:33:13 -05:00
|
|
|
type SetAlertNotificationStateToPendingCommand struct {
|
2018-10-02 06:57:41 -05:00
|
|
|
Id int64
|
2018-10-01 07:13:03 -05:00
|
|
|
AlertRuleStateUpdatedVersion int64
|
2018-10-02 06:57:41 -05:00
|
|
|
Version int64
|
|
|
|
|
|
|
|
ResultVersion int64
|
2018-05-19 15:21:00 -05:00
|
|
|
}
|
|
|
|
|
2018-09-27 04:33:13 -05:00
|
|
|
type SetAlertNotificationStateToCompleteCommand struct {
|
2018-10-02 06:57:41 -05:00
|
|
|
Id int64
|
|
|
|
Version int64
|
2018-09-27 04:33:13 -05:00
|
|
|
}
|
|
|
|
|
2018-10-02 04:23:40 -05:00
|
|
|
type GetOrCreateNotificationStateQuery struct {
|
2018-05-19 15:21:00 -05:00
|
|
|
OrgId int64
|
|
|
|
AlertId int64
|
|
|
|
NotifierId int64
|
|
|
|
|
2018-09-26 10:26:02 -05:00
|
|
|
Result *AlertNotificationState
|
2018-05-19 15:21:00 -05:00
|
|
|
}
|