mirror of
https://github.com/grafana/grafana.git
synced 2024-12-01 21:19:28 -06:00
45facbba11
* Remove URL-based alertmanagers from endpoint config * WIP * Add migration and alertmanagers from admin_configuration * Empty comment removed * set BasicAuth true when user is present in url * Remove Alertmanagers from GET /admin_config payload * Remove URL-based alertmanager configuration from UI * Fix new uid generation in external alertmanagers migration * Fix tests for URL-based external alertmanagers * Fix API tests * Add more tests, move migration code to separate file, and remove possible am duplicate urls * Fix edge cases in migration * Fix imports * Remove useless fields and fix created_at/updated_at retrieval Co-authored-by: George Robinson <george.robinson@grafana.com> Co-authored-by: Konrad Lalik <konrad.lalik@grafana.com>
50 lines
1.1 KiB
Go
50 lines
1.1 KiB
Go
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")
|
|
}
|