forked from grafana/grafana
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathadmin_configuration.go
49 lines (39 loc) · 1.1 KB
/
admin_configuration.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
package models
import (
"errors"
)
type AlertmanagersChoice int
const (
AllAlertmanagers AlertmanagersChoice = iota
InternalAlertmanager
ExternalAlertmanagers
)
var alertmanagersChoiceMap = map[AlertmanagersChoice]string{
AllAlertmanagers: "all",
InternalAlertmanager: "internal",
ExternalAlertmanagers: "external",
}
// AdminConfiguration represents the ngalert administration configuration settings.
type AdminConfiguration struct {
ID int64 `xorm:"pk autoincr 'id'"`
OrgID int64 `xorm:"org_id"`
// SendAlertsTo indicates which set of alertmanagers will handle the alert.
SendAlertsTo AlertmanagersChoice `xorm:"send_alerts_to"`
CreatedAt int64 `xorm:"created"`
UpdatedAt int64 `xorm:"updated"`
}
// String implements the Stringer interface
func (amc AlertmanagersChoice) String() string {
return alertmanagersChoiceMap[amc]
}
func StringToAlertmanagersChoice(str string) (AlertmanagersChoice, error) {
if str == "" {
return AllAlertmanagers, nil
}
for k, v := range alertmanagersChoiceMap {
if str == v {
return k, nil
}
}
return 0, errors.New("invalid alertmanager choice")
}