mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
* Upgrade godo to latest * Fix a bunch of issues found by * Running staticcheck on a codebase for the first time is a sobering experience * go mod tidy * More static improvements Signed-off-by: Chris Cummer <chriscummer@me.com>
68 lines
1.6 KiB
Go
68 lines
1.6 KiB
Go
package pagerduty
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/PagerDuty/go-pagerduty"
|
|
)
|
|
|
|
// GetOnCalls returns a list of people currently on call
|
|
func GetOnCalls(apiKey string, scheduleIDs []string) ([]pagerduty.OnCall, error) {
|
|
client := pagerduty.NewClient(apiKey)
|
|
|
|
var results []pagerduty.OnCall
|
|
var queryOpts pagerduty.ListOnCallOptions
|
|
|
|
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 {
|
|
return nil, err
|
|
}
|
|
|
|
results = append(results, oncalls.OnCalls...)
|
|
|
|
for oncalls.APIListObject.More {
|
|
queryOpts.APIListObject.Offset = oncalls.APIListObject.Offset
|
|
oncalls, err = client.ListOnCalls(queryOpts)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
results = append(results, oncalls.OnCalls...)
|
|
}
|
|
|
|
return results, nil
|
|
}
|
|
|
|
// GetIncidents returns a list of people currently on call
|
|
func GetIncidents(apiKey string) ([]pagerduty.Incident, error) {
|
|
client := pagerduty.NewClient(apiKey)
|
|
|
|
var results []pagerduty.Incident
|
|
|
|
var queryOpts pagerduty.ListIncidentsOptions
|
|
queryOpts.DateRange = "all"
|
|
queryOpts.Statuses = []string{"triggered", "acknowledged"}
|
|
|
|
items, err := client.ListIncidents(queryOpts)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
results = append(results, items.Incidents...)
|
|
|
|
for items.APIListObject.More {
|
|
queryOpts.APIListObject.Offset = items.APIListObject.Offset
|
|
items, err = client.ListIncidents(queryOpts)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
results = append(results, items.Incidents...)
|
|
}
|
|
|
|
return results, nil
|
|
}
|