diff --git a/modules/pagerduty/client.go b/modules/pagerduty/client.go index aa8766b9..bd137f52 100644 --- a/modules/pagerduty/client.go +++ b/modules/pagerduty/client.go @@ -7,14 +7,17 @@ import ( ) // 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) var results []pagerduty.OnCall - 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) if err != nil { diff --git a/modules/pagerduty/settings.go b/modules/pagerduty/settings.go index b98bb923..3e6fa6ba 100644 --- a/modules/pagerduty/settings.go +++ b/modules/pagerduty/settings.go @@ -14,6 +14,7 @@ type Settings struct { apiKey string escalationFilter []interface{} + scheduleIDs []interface{} showIncidents 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")), escalationFilter: ymlConfig.UList("escalationFilter"), + scheduleIDs: ymlConfig.UList("scheduleIDs", []interface{}{}), showIncidents: ymlConfig.UBool("showIncidents", true), showSchedules: ymlConfig.UBool("showSchedules", true), } diff --git a/modules/pagerduty/widget.go b/modules/pagerduty/widget.go index a032e43f..4741666f 100644 --- a/modules/pagerduty/widget.go +++ b/modules/pagerduty/widget.go @@ -34,14 +34,15 @@ func (widget *Widget) Refresh() { var err1 error var err2 error - if widget.settings.showSchedules { - onCalls, err1 = GetOnCalls(widget.settings.apiKey) - } - if widget.settings.showIncidents { 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 wrap := false if err1 != nil || err2 != nil { @@ -98,14 +99,14 @@ func (widget *Widget) contentFrom(onCalls []pagerduty.OnCall, incidents []pagerd sort.Strings(keys) 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 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] sort.Sort(ByEscalationLevel(values)) for _, item := range values { - str = str + fmt.Sprintf("[white]%d - %s\n", item.EscalationLevel, item.User.Summary) + str = str + fmt.Sprintf(" [white]%d - %s\n", item.EscalationLevel, item.User.Summary) } } }