forked from grafana/grafana
-
Notifications
You must be signed in to change notification settings - Fork 0
/
alert_notification.go
154 lines (130 loc) · 5.52 KB
/
alert_notification.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
package models
import (
"errors"
"time"
"github.com/grafana/grafana/pkg/components/simplejson"
)
var (
ErrAlertNotificationNotFound = errors.New("alert notification not found")
ErrNotificationFrequencyNotFound = errors.New("notification frequency not specified")
ErrAlertNotificationStateVersionConflict = errors.New("alert notification state update version conflict")
ErrAlertNotificationFailedGenerateUniqueUid = errors.New("failed to generate unique alert notification uid")
ErrAlertNotificationFailedTranslateUniqueID = errors.New("failed to translate Notification Id to Uid")
ErrAlertNotificationWithSameNameExists = errors.New("alert notification with same name already exists")
ErrAlertNotificationWithSameUIDExists = errors.New("alert notification with same uid already exists")
)
type AlertNotificationStateType string
var (
AlertNotificationStatePending = AlertNotificationStateType("pending")
AlertNotificationStateCompleted = AlertNotificationStateType("completed")
AlertNotificationStateUnknown = AlertNotificationStateType("unknown")
)
type AlertNotification struct {
ID int64 `json:"id" xorm:"pk autoincr 'id'"`
UID string `json:"-" xorm:"uid"`
OrgID int64 `json:"-" xorm:"org_id"`
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"`
}
type CreateAlertNotificationCommand struct {
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"`
OrgID int64 `json:"-"`
EncryptedSecureSettings map[string][]byte `json:"-"`
}
type UpdateAlertNotificationCommand struct {
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"`
OrgID int64 `json:"-"`
EncryptedSecureSettings map[string][]byte `json:"-"`
}
type UpdateAlertNotificationWithUidCommand struct {
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"`
OrgID int64 `json:"-"`
}
type DeleteAlertNotificationCommand struct {
ID int64
OrgID int64
}
type DeleteAlertNotificationWithUidCommand struct {
UID string
OrgID int64
DeletedAlertNotificationID int64
}
type GetAlertNotificationUidQuery struct {
ID int64
OrgID int64
}
type GetAlertNotificationsQuery struct {
Name string
ID int64
OrgID int64
}
type GetAlertNotificationsWithUidQuery struct {
UID string
OrgID int64
}
type GetAlertNotificationsWithUidToSendQuery struct {
UIDs []string
OrgID int64
}
type GetAllAlertNotificationsQuery struct {
OrgID int64
}
type AlertNotificationState struct {
ID int64 `xorm:"pk autoincr 'id'"`
OrgID int64 `xorm:"org_id"`
AlertID int64 `xorm:"alert_id"`
NotifierID int64 `xorm:"notifier_id"`
State AlertNotificationStateType
Version int64
UpdatedAt int64
AlertRuleStateUpdatedVersion int64
}
type SetAlertNotificationStateToPendingCommand struct {
ID int64
AlertRuleStateUpdatedVersion int64
Version int64
ResultVersion int64
}
type SetAlertNotificationStateToCompleteCommand struct {
ID int64
Version int64
}
type GetOrCreateNotificationStateQuery struct {
OrgID int64
AlertID int64
NotifierID int64
}