mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Merge pull request #516 from l13t/master
Added to opsgenie module region selection
This commit is contained in:
commit
b75beba06b
@ -24,13 +24,19 @@ type Parent struct {
|
|||||||
Enabled bool `json:"enabled"`
|
Enabled bool `json:"enabled"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var opsGenieAPIUrl = map[string]string{
|
||||||
|
"us": "https://api.opsgenie.com",
|
||||||
|
"eu": "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{}
|
||||||
|
|
||||||
|
if regionUrl, regionErr := opsGenieAPIUrl[widget.settings.region]; regionErr {
|
||||||
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)
|
scheduleUrl := fmt.Sprintf("%s/v2/schedules/%s/on-calls?scheduleIdentifierType=%s&flat=true", regionUrl, 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 {
|
||||||
@ -38,6 +44,9 @@ func (widget *Widget) Fetch(scheduleIdentifierType string, schedules []string) (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return agregatedResponses, nil
|
return agregatedResponses, nil
|
||||||
|
} else {
|
||||||
|
return nil, fmt.Errorf("You specified wrong region. Possible options are only 'us' and 'eu'.")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------- Unexported Functions -------------------- */
|
/* -------------------- Unexported Functions -------------------- */
|
||||||
|
@ -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."`
|
||||||
|
region string `help:"Defines region to use. Possible options: us (by default), eu." 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")),
|
||||||
|
region: ymlConfig.UString("region", "us"),
|
||||||
displayEmpty: ymlConfig.UBool("displayEmpty", true),
|
displayEmpty: ymlConfig.UBool("displayEmpty", true),
|
||||||
scheduleIdentifierType: ymlConfig.UString("scheduleIdentifierType", "id"),
|
scheduleIdentifierType: ymlConfig.UString("scheduleIdentifierType", "id"),
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user