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

Allow PagerDuty to restrict on scheduleID

This commit is contained in:
Chris Cummer 2019-05-12 09:42:20 -07:00
parent f6ed8b6b45
commit 5f054c8ffd
3 changed files with 17 additions and 11 deletions

View File

@ -7,14 +7,17 @@ import (
) )
// GetOnCalls returns a list of people currently on call // GetOnCalls returns a list of people currently on call
func GetOnCalls(apiKey string) ([]pagerduty.OnCall, error) { func GetOnCalls(apiKey string, scheduleIDs []string) ([]pagerduty.OnCall, error) {
client := pagerduty.NewClient(apiKey) client := pagerduty.NewClient(apiKey)
var results []pagerduty.OnCall var results []pagerduty.OnCall
var queryOpts pagerduty.ListOnCallOptions var queryOpts pagerduty.ListOnCallOptions
queryOpts.Since = time.Now().Format("2006-01-02T15:04:05Z07:00")
queryOpts.Until = time.Now().Format("2006-01-02T15:04:05Z07:00") queryOpts.ScheduleIDs = scheduleIDs
timeFmt := "2006-01-02T15:04:05Z07:00"
queryOpts.Since = time.Now().Format(timeFmt)
queryOpts.Until = time.Now().Format(timeFmt)
oncalls, err := client.ListOnCalls(queryOpts) oncalls, err := client.ListOnCalls(queryOpts)
if err != nil { if err != nil {

View File

@ -14,6 +14,7 @@ type Settings struct {
apiKey string apiKey string
escalationFilter []interface{} escalationFilter []interface{}
scheduleIDs []interface{}
showIncidents bool showIncidents bool
showSchedules bool showSchedules bool
} }
@ -25,6 +26,7 @@ func NewSettingsFromYAML(name string, ymlConfig *config.Config, globalConfig *co
apiKey: ymlConfig.UString("apiKey", os.Getenv("WTF_PAGERDUTY_API_KEY")), apiKey: ymlConfig.UString("apiKey", os.Getenv("WTF_PAGERDUTY_API_KEY")),
escalationFilter: ymlConfig.UList("escalationFilter"), escalationFilter: ymlConfig.UList("escalationFilter"),
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),
} }

View File

@ -34,14 +34,15 @@ func (widget *Widget) Refresh() {
var err1 error var err1 error
var err2 error var err2 error
if widget.settings.showSchedules {
onCalls, err1 = GetOnCalls(widget.settings.apiKey)
}
if widget.settings.showIncidents { if widget.settings.showIncidents {
incidents, err2 = GetIncidents(widget.settings.apiKey) incidents, err2 = GetIncidents(widget.settings.apiKey)
} }
if widget.settings.showSchedules {
scheduleIDs := wtf.ToStrs(widget.settings.scheduleIDs)
onCalls, err1 = GetOnCalls(widget.settings.apiKey, scheduleIDs)
}
var content string var content string
wrap := false wrap := false
if err1 != nil || err2 != nil { if err1 != nil || err2 != nil {
@ -98,10 +99,10 @@ func (widget *Widget) contentFrom(onCalls []pagerduty.OnCall, incidents []pagerd
sort.Strings(keys) sort.Strings(keys)
if len(keys) > 0 { if len(keys) > 0 {
str = str + "[yellow]Schedules[white]\n" str = str + "\n[red] Schedules[white]\n"
// Print out policies, and escalation order of users // Print out policies, and escalation order of users
for _, key := range keys { for _, key := range keys {
str = str + fmt.Sprintf("[red]%s\n", key) str = str + fmt.Sprintf("\n [green::b]%s\n", key)
values := tree[key] values := tree[key]
sort.Sort(ByEscalationLevel(values)) sort.Sort(ByEscalationLevel(values))
for _, item := range values { for _, item := range values {