From aa5e5e70a9c2a1b5490a8d4c307800b06f3e429b Mon Sep 17 00:00:00 2001 From: Matt Murphy Date: Sun, 7 Jun 2020 16:58:44 -0400 Subject: [PATCH] Add TeamIDs and UserIDs filters for incidents --- modules/pagerduty/client.go | 6 ++++-- modules/pagerduty/settings.go | 8 ++++++-- modules/pagerduty/widget.go | 4 +++- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/modules/pagerduty/client.go b/modules/pagerduty/client.go index 2f03f22f..d509de21 100644 --- a/modules/pagerduty/client.go +++ b/modules/pagerduty/client.go @@ -38,8 +38,8 @@ func GetOnCalls(apiKey string, scheduleIDs []string) ([]pagerduty.OnCall, error) return results, nil } -// GetIncidents returns a list of people currently on call -func GetIncidents(apiKey string) ([]pagerduty.Incident, error) { +// GetIncidents returns a list of unresolved incidents +func GetIncidents(apiKey string, teamIDs []string, userIDs []string) ([]pagerduty.Incident, error) { client := pagerduty.NewClient(apiKey) var results []pagerduty.Incident @@ -47,6 +47,8 @@ func GetIncidents(apiKey string) ([]pagerduty.Incident, error) { var queryOpts pagerduty.ListIncidentsOptions queryOpts.DateRange = "all" queryOpts.Statuses = []string{"triggered", "acknowledged"} + queryOpts.TeamIDs = teamIDs + queryOpts.UserIDs = userIDs items, err := client.ListIncidents(queryOpts) if err != nil { diff --git a/modules/pagerduty/settings.go b/modules/pagerduty/settings.go index 1319bde7..962299cd 100644 --- a/modules/pagerduty/settings.go +++ b/modules/pagerduty/settings.go @@ -17,11 +17,13 @@ type Settings struct { common *cfg.Common apiKey string `help:"Your PagerDuty API key."` - escalationFilter []interface{} `help:"An array of schedule names you want to filter on."` + escalationFilter []interface{} `help:"An array of schedule names you want to filter the OnCalls on."` myName string `help:"The name to highlight when on-call in PagerDuty."` - scheduleIDs []interface{} `help:"An array of schedule IDs you want to restrict the query to."` + scheduleIDs []interface{} `help:"An array of schedule IDs you want to restrict the OnCalls query to."` showIncidents bool `help:"Whether or not to list incidents." optional:"true"` showSchedules bool `help:"Whether or not to show schedules." optional:"true"` + teamIDs []interface{} `help:"An array of team IDs to restrict the incidents query to" optional:"true"` + userIDs []interface{} `help:"An array of user IDs to restrict the incidents query to" optional:"true"` } // NewSettingsFromYAML creates a new settings instance from a YAML config block @@ -35,6 +37,8 @@ func NewSettingsFromYAML(name string, ymlConfig *config.Config, globalConfig *co scheduleIDs: ymlConfig.UList("scheduleIDs", []interface{}{}), showIncidents: ymlConfig.UBool("showIncidents", true), showSchedules: ymlConfig.UBool("showSchedules", true), + teamIDs: ymlConfig.UList("teamIDs", []interface{}{}), + userIDs: ymlConfig.UList("userIDs", []interface{}{}), } cfg.ModuleSecret(name, globalConfig, &settings.apiKey).Load() diff --git a/modules/pagerduty/widget.go b/modules/pagerduty/widget.go index 1528a6a9..1275e0bb 100644 --- a/modules/pagerduty/widget.go +++ b/modules/pagerduty/widget.go @@ -36,7 +36,9 @@ func (widget *Widget) Refresh() { var err2 error if widget.settings.showIncidents { - incidents, err2 = GetIncidents(widget.settings.apiKey) + teamIDs := utils.ToStrs(widget.settings.teamIDs) + userIDs := utils.ToStrs(widget.settings.userIDs) + incidents, err2 = GetIncidents(widget.settings.apiKey, teamIDs, userIDs) } if widget.settings.showSchedules {