mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Add TeamIDs and UserIDs filters for incidents
This commit is contained in:
parent
068f0e46fd
commit
aa5e5e70a9
@ -38,8 +38,8 @@ func GetOnCalls(apiKey string, scheduleIDs []string) ([]pagerduty.OnCall, error)
|
|||||||
return results, nil
|
return results, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetIncidents returns a list of people currently on call
|
// GetIncidents returns a list of unresolved incidents
|
||||||
func GetIncidents(apiKey string) ([]pagerduty.Incident, error) {
|
func GetIncidents(apiKey string, teamIDs []string, userIDs []string) ([]pagerduty.Incident, error) {
|
||||||
client := pagerduty.NewClient(apiKey)
|
client := pagerduty.NewClient(apiKey)
|
||||||
|
|
||||||
var results []pagerduty.Incident
|
var results []pagerduty.Incident
|
||||||
@ -47,6 +47,8 @@ func GetIncidents(apiKey string) ([]pagerduty.Incident, error) {
|
|||||||
var queryOpts pagerduty.ListIncidentsOptions
|
var queryOpts pagerduty.ListIncidentsOptions
|
||||||
queryOpts.DateRange = "all"
|
queryOpts.DateRange = "all"
|
||||||
queryOpts.Statuses = []string{"triggered", "acknowledged"}
|
queryOpts.Statuses = []string{"triggered", "acknowledged"}
|
||||||
|
queryOpts.TeamIDs = teamIDs
|
||||||
|
queryOpts.UserIDs = userIDs
|
||||||
|
|
||||||
items, err := client.ListIncidents(queryOpts)
|
items, err := client.ListIncidents(queryOpts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -17,11 +17,13 @@ type Settings struct {
|
|||||||
common *cfg.Common
|
common *cfg.Common
|
||||||
|
|
||||||
apiKey string `help:"Your PagerDuty API key."`
|
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."`
|
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"`
|
showIncidents bool `help:"Whether or not to list incidents." optional:"true"`
|
||||||
showSchedules bool `help:"Whether or not to show schedules." 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
|
// 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{}{}),
|
scheduleIDs: ymlConfig.UList("scheduleIDs", []interface{}{}),
|
||||||
showIncidents: ymlConfig.UBool("showIncidents", true),
|
showIncidents: ymlConfig.UBool("showIncidents", true),
|
||||||
showSchedules: ymlConfig.UBool("showSchedules", true),
|
showSchedules: ymlConfig.UBool("showSchedules", true),
|
||||||
|
teamIDs: ymlConfig.UList("teamIDs", []interface{}{}),
|
||||||
|
userIDs: ymlConfig.UList("userIDs", []interface{}{}),
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg.ModuleSecret(name, globalConfig, &settings.apiKey).Load()
|
cfg.ModuleSecret(name, globalConfig, &settings.apiKey).Load()
|
||||||
|
@ -36,7 +36,9 @@ func (widget *Widget) Refresh() {
|
|||||||
var err2 error
|
var err2 error
|
||||||
|
|
||||||
if widget.settings.showIncidents {
|
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 {
|
if widget.settings.showSchedules {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user