2021-08-06 07:06:56 -05:00
|
|
|
package models
|
|
|
|
|
|
|
|
import (
|
Alerting: send alerts to external, internal, or both alertmanagers (#40341)
* (WIP) send alerts to external, internal, or both alertmanagers
* Modify admin configuration endpoint, update swagger docs
* Integration test for admin config updated
* Code review changes
* Fix alertmanagers choice not changing bug, add unit test
* Add AlertmanagersChoice as enum in swagger, code review changes
* Fix API and tests errors
* Change enum from int to string, use 'SendAlertsTo' instead of 'AlertmanagerChoice' where necessary
* Fix tests to reflect last changes
* Keep senders running when alerts are handled just internally
* Check if any external AM has been discovered before sending alerts, update tests
* remove duplicate data from logs
* update comment
* represent alertmanagers choice as an int instead of a string
* default alertmanagers choice to all alertmanagers, test cases
* update definitions and generate spec
2022-02-01 17:36:55 -06:00
|
|
|
"errors"
|
2021-08-06 07:06:56 -05:00
|
|
|
)
|
|
|
|
|
Alerting: send alerts to external, internal, or both alertmanagers (#40341)
* (WIP) send alerts to external, internal, or both alertmanagers
* Modify admin configuration endpoint, update swagger docs
* Integration test for admin config updated
* Code review changes
* Fix alertmanagers choice not changing bug, add unit test
* Add AlertmanagersChoice as enum in swagger, code review changes
* Fix API and tests errors
* Change enum from int to string, use 'SendAlertsTo' instead of 'AlertmanagerChoice' where necessary
* Fix tests to reflect last changes
* Keep senders running when alerts are handled just internally
* Check if any external AM has been discovered before sending alerts, update tests
* remove duplicate data from logs
* update comment
* represent alertmanagers choice as an int instead of a string
* default alertmanagers choice to all alertmanagers, test cases
* update definitions and generate spec
2022-02-01 17:36:55 -06:00
|
|
|
type AlertmanagersChoice int
|
|
|
|
|
|
|
|
const (
|
|
|
|
AllAlertmanagers AlertmanagersChoice = iota
|
|
|
|
InternalAlertmanager
|
|
|
|
ExternalAlertmanagers
|
|
|
|
)
|
|
|
|
|
|
|
|
var alertmanagersChoiceMap = map[AlertmanagersChoice]string{
|
|
|
|
AllAlertmanagers: "all",
|
|
|
|
InternalAlertmanager: "internal",
|
|
|
|
ExternalAlertmanagers: "external",
|
|
|
|
}
|
|
|
|
|
2021-08-06 07:06:56 -05:00
|
|
|
// AdminConfiguration represents the ngalert administration configuration settings.
|
|
|
|
type AdminConfiguration struct {
|
|
|
|
ID int64 `xorm:"pk autoincr 'id'"`
|
|
|
|
OrgID int64 `xorm:"org_id"`
|
|
|
|
|
Alerting: send alerts to external, internal, or both alertmanagers (#40341)
* (WIP) send alerts to external, internal, or both alertmanagers
* Modify admin configuration endpoint, update swagger docs
* Integration test for admin config updated
* Code review changes
* Fix alertmanagers choice not changing bug, add unit test
* Add AlertmanagersChoice as enum in swagger, code review changes
* Fix API and tests errors
* Change enum from int to string, use 'SendAlertsTo' instead of 'AlertmanagerChoice' where necessary
* Fix tests to reflect last changes
* Keep senders running when alerts are handled just internally
* Check if any external AM has been discovered before sending alerts, update tests
* remove duplicate data from logs
* update comment
* represent alertmanagers choice as an int instead of a string
* default alertmanagers choice to all alertmanagers, test cases
* update definitions and generate spec
2022-02-01 17:36:55 -06:00
|
|
|
// SendAlertsTo indicates which set of alertmanagers will handle the alert.
|
|
|
|
SendAlertsTo AlertmanagersChoice `xorm:"send_alerts_to"`
|
|
|
|
|
2021-08-06 07:06:56 -05:00
|
|
|
CreatedAt int64 `xorm:"created"`
|
|
|
|
UpdatedAt int64 `xorm:"updated"`
|
|
|
|
}
|
|
|
|
|
Alerting: send alerts to external, internal, or both alertmanagers (#40341)
* (WIP) send alerts to external, internal, or both alertmanagers
* Modify admin configuration endpoint, update swagger docs
* Integration test for admin config updated
* Code review changes
* Fix alertmanagers choice not changing bug, add unit test
* Add AlertmanagersChoice as enum in swagger, code review changes
* Fix API and tests errors
* Change enum from int to string, use 'SendAlertsTo' instead of 'AlertmanagerChoice' where necessary
* Fix tests to reflect last changes
* Keep senders running when alerts are handled just internally
* Check if any external AM has been discovered before sending alerts, update tests
* remove duplicate data from logs
* update comment
* represent alertmanagers choice as an int instead of a string
* default alertmanagers choice to all alertmanagers, test cases
* update definitions and generate spec
2022-02-01 17:36:55 -06:00
|
|
|
// 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")
|
|
|
|
}
|