mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
46 lines
998 B
Go
46 lines
998 B
Go
package pagerduty
|
|
|
|
import (
|
|
"os"
|
|
"time"
|
|
|
|
"github.com/PagerDuty/go-pagerduty"
|
|
"github.com/wtfutil/wtf/wtf"
|
|
)
|
|
|
|
// GetOnCalls returns a list of people currently on call
|
|
func GetOnCalls() ([]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")
|
|
|
|
oncalls, err := client.ListOnCalls(queryOpts)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
results = append(results, oncalls.OnCalls...)
|
|
|
|
for oncalls.APIListObject.More == true {
|
|
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
|
|
}
|
|
|
|
func apiKey() string {
|
|
return wtf.Config.UString(
|
|
"wtf.mods.pagerduty.apiKey",
|
|
os.Getenv("WTF_PAGERDUTY_API_KEY"),
|
|
)
|
|
}
|