1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00

Added to opsgenie module region selection

According to OpsGenie API documentation:
``If using the EU instance of Opsgenie, the URL needs to be https://api.eu.opsgenie.com for requests to be
successful.```
This commit is contained in:
Dmytro Prokhorenkov 2019-07-23 17:23:53 +02:00
parent 7a70ed75be
commit 7422cc3822
2 changed files with 12 additions and 1 deletions

View File

@ -24,13 +24,22 @@ type Parent struct {
Enabled bool `json:"enabled"` Enabled bool `json:"enabled"`
} }
var opsGenieAPIUrl = map[string]string{
"default": "https://api.opsgenie.com",
"europe": "https://api.eu.opsgenie.com",
}
/* -------------------- Exported Functions -------------------- */ /* -------------------- Exported Functions -------------------- */
func (widget *Widget) Fetch(scheduleIdentifierType string, schedules []string) ([]*OnCallResponse, error) { func (widget *Widget) Fetch(scheduleIdentifierType string, schedules []string) ([]*OnCallResponse, error) {
agregatedResponses := []*OnCallResponse{} agregatedResponses := []*OnCallResponse{}
region := "default"
for _, sched := range schedules { for _, sched := range schedules {
scheduleUrl := fmt.Sprintf("https://api.opsgenie.com/v2/schedules/%s/on-calls?scheduleIdentifierType=%s&flat=true", sched, scheduleIdentifierType) if widget.settings.isEurope {
region = "europe"
}
scheduleUrl := fmt.Sprintf("%s/v2/schedules/%s/on-calls?scheduleIdentifierType=%s&flat=true", opsGenieAPIUrl[region], sched, scheduleIdentifierType)
response, err := opsGenieRequest(scheduleUrl, widget.settings.apiKey) response, err := opsGenieRequest(scheduleUrl, widget.settings.apiKey)
agregatedResponses = append(agregatedResponses, response) agregatedResponses = append(agregatedResponses, response)
if err != nil { if err != nil {

View File

@ -13,6 +13,7 @@ type Settings struct {
common *cfg.Common common *cfg.Common
apiKey string `help:"Your OpsGenie API token."` apiKey string `help:"Your OpsGenie API token."`
isEurope bool `help:"Defines if European servers should be used." optional:"true"`
displayEmpty bool `help:"Whether schedules with no assigned person on-call should be displayed." optional:"true"` displayEmpty bool `help:"Whether schedules with no assigned person on-call should be displayed." optional:"true"`
schedule []string `help:"A list of names of the schedule(s) to retrieve."` schedule []string `help:"A list of names of the schedule(s) to retrieve."`
scheduleIdentifierType string `help:"Type of the schedule identifier." values:"id or name" optional:"true"` scheduleIdentifierType string `help:"Type of the schedule identifier." values:"id or name" optional:"true"`
@ -24,6 +25,7 @@ func NewSettingsFromYAML(name string, ymlConfig *config.Config, globalConfig *co
common: cfg.NewCommonSettingsFromModule(name, defaultTitle, ymlConfig, globalConfig), common: cfg.NewCommonSettingsFromModule(name, defaultTitle, ymlConfig, globalConfig),
apiKey: ymlConfig.UString("apiKey", os.Getenv("WTF_OPS_GENIE_API_KEY")), apiKey: ymlConfig.UString("apiKey", os.Getenv("WTF_OPS_GENIE_API_KEY")),
isEurope: ymlConfig.UBool("isEurope", false),
displayEmpty: ymlConfig.UBool("displayEmpty", true), displayEmpty: ymlConfig.UBool("displayEmpty", true),
scheduleIdentifierType: ymlConfig.UString("scheduleIdentifierType", "id"), scheduleIdentifierType: ymlConfig.UString("scheduleIdentifierType", "id"),
} }