1package models
2
3import (
4	"errors"
5	"time"
6
7	"github.com/grafana/grafana/pkg/components/simplejson"
8)
9
10var (
11	ErrAlertNotificationNotFound                = errors.New("alert notification not found")
12	ErrNotificationFrequencyNotFound            = errors.New("notification frequency not specified")
13	ErrAlertNotificationStateVersionConflict    = errors.New("alert notification state update version conflict")
14	ErrAlertNotificationFailedGenerateUniqueUid = errors.New("failed to generate unique alert notification uid")
15	ErrAlertNotificationFailedTranslateUniqueID = errors.New("failed to translate Notification Id to Uid")
16	ErrAlertNotificationWithSameNameExists      = errors.New("alert notification with same name already exists")
17	ErrAlertNotificationWithSameUIDExists       = errors.New("alert notification with same uid already exists")
18)
19
20type AlertNotificationStateType string
21
22var (
23	AlertNotificationStatePending   = AlertNotificationStateType("pending")
24	AlertNotificationStateCompleted = AlertNotificationStateType("completed")
25	AlertNotificationStateUnknown   = AlertNotificationStateType("unknown")
26)
27
28type AlertNotification struct {
29	Id                    int64             `json:"id"`
30	Uid                   string            `json:"-"`
31	OrgId                 int64             `json:"-"`
32	Name                  string            `json:"name"`
33	Type                  string            `json:"type"`
34	SendReminder          bool              `json:"sendReminder"`
35	DisableResolveMessage bool              `json:"disableResolveMessage"`
36	Frequency             time.Duration     `json:"frequency"`
37	IsDefault             bool              `json:"isDefault"`
38	Settings              *simplejson.Json  `json:"settings"`
39	SecureSettings        map[string][]byte `json:"secureSettings"`
40	Created               time.Time         `json:"created"`
41	Updated               time.Time         `json:"updated"`
42}
43
44type CreateAlertNotificationCommand struct {
45	Uid                   string            `json:"uid"`
46	Name                  string            `json:"name"  binding:"Required"`
47	Type                  string            `json:"type"  binding:"Required"`
48	SendReminder          bool              `json:"sendReminder"`
49	DisableResolveMessage bool              `json:"disableResolveMessage"`
50	Frequency             string            `json:"frequency"`
51	IsDefault             bool              `json:"isDefault"`
52	Settings              *simplejson.Json  `json:"settings"`
53	SecureSettings        map[string]string `json:"secureSettings"`
54
55	OrgId                   int64             `json:"-"`
56	EncryptedSecureSettings map[string][]byte `json:"-"`
57
58	Result *AlertNotification
59}
60
61type UpdateAlertNotificationCommand struct {
62	Id                    int64             `json:"id"  binding:"Required"`
63	Uid                   string            `json:"uid"`
64	Name                  string            `json:"name"  binding:"Required"`
65	Type                  string            `json:"type"  binding:"Required"`
66	SendReminder          bool              `json:"sendReminder"`
67	DisableResolveMessage bool              `json:"disableResolveMessage"`
68	Frequency             string            `json:"frequency"`
69	IsDefault             bool              `json:"isDefault"`
70	Settings              *simplejson.Json  `json:"settings"  binding:"Required"`
71	SecureSettings        map[string]string `json:"secureSettings"`
72
73	OrgId                   int64             `json:"-"`
74	EncryptedSecureSettings map[string][]byte `json:"-"`
75
76	Result *AlertNotification
77}
78
79type UpdateAlertNotificationWithUidCommand struct {
80	Uid                   string            `json:"-"`
81	NewUid                string            `json:"uid"`
82	Name                  string            `json:"name"  binding:"Required"`
83	Type                  string            `json:"type"  binding:"Required"`
84	SendReminder          bool              `json:"sendReminder"`
85	DisableResolveMessage bool              `json:"disableResolveMessage"`
86	Frequency             string            `json:"frequency"`
87	IsDefault             bool              `json:"isDefault"`
88	Settings              *simplejson.Json  `json:"settings"  binding:"Required"`
89	SecureSettings        map[string]string `json:"secureSettings"`
90
91	OrgId  int64
92	Result *AlertNotification
93}
94
95type DeleteAlertNotificationCommand struct {
96	Id    int64
97	OrgId int64
98}
99type DeleteAlertNotificationWithUidCommand struct {
100	Uid   string
101	OrgId int64
102
103	DeletedAlertNotificationId int64
104}
105
106type GetAlertNotificationUidQuery struct {
107	Id    int64
108	OrgId int64
109
110	Result string
111}
112
113type GetAlertNotificationsQuery struct {
114	Name  string
115	Id    int64
116	OrgId int64
117
118	Result *AlertNotification
119}
120
121type GetAlertNotificationsWithUidQuery struct {
122	Uid   string
123	OrgId int64
124
125	Result *AlertNotification
126}
127
128type GetAlertNotificationsWithUidToSendQuery struct {
129	Uids  []string
130	OrgId int64
131
132	Result []*AlertNotification
133}
134
135type GetAllAlertNotificationsQuery struct {
136	OrgId int64
137
138	Result []*AlertNotification
139}
140
141type AlertNotificationState struct {
142	Id                           int64
143	OrgId                        int64
144	AlertId                      int64
145	NotifierId                   int64
146	State                        AlertNotificationStateType
147	Version                      int64
148	UpdatedAt                    int64
149	AlertRuleStateUpdatedVersion int64
150}
151
152type SetAlertNotificationStateToPendingCommand struct {
153	Id                           int64
154	AlertRuleStateUpdatedVersion int64
155	Version                      int64
156
157	ResultVersion int64
158}
159
160type SetAlertNotificationStateToCompleteCommand struct {
161	Id      int64
162	Version int64
163}
164
165type GetOrCreateNotificationStateQuery struct {
166	OrgId      int64
167	AlertId    int64
168	NotifierId int64
169
170	Result *AlertNotificationState
171}
172