mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Merge pull request #447 from wtfutil/pagerduty-schedule-specifications
Allow PagerDuty to restrict on scheduleID
This commit is contained in:
commit
b4b39d87c0
@ -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 {
|
||||
|
@ -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),
|
||||
}
|
||||
|
@ -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,10 +99,10 @@ 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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user