mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Add incident showing to pagerduty
Building off previous functionality, also show incidents This is optional, and can be configured (as can, now showing schedules)
This commit is contained in:
parent
3122f2fee9
commit
659797c3fa
@ -37,6 +37,34 @@ func GetOnCalls() ([]pagerduty.OnCall, error) {
|
|||||||
return results, nil
|
return results, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetIncidents returns a list of people currently on call
|
||||||
|
func GetIncidents() ([]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 == true {
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
func apiKey() string {
|
func apiKey() string {
|
||||||
return wtf.Config.UString(
|
return wtf.Config.UString(
|
||||||
"wtf.mods.pagerduty.apiKey",
|
"wtf.mods.pagerduty.apiKey",
|
||||||
|
@ -24,18 +24,35 @@ func NewWidget(app *tview.Application) *Widget {
|
|||||||
/* -------------------- Exported Functions -------------------- */
|
/* -------------------- Exported Functions -------------------- */
|
||||||
|
|
||||||
func (widget *Widget) Refresh() {
|
func (widget *Widget) Refresh() {
|
||||||
onCalls, err := GetOnCalls()
|
var onCalls []pagerduty.OnCall
|
||||||
|
var incidents []pagerduty.Incident
|
||||||
|
|
||||||
|
var err1 error
|
||||||
|
var err2 error
|
||||||
|
|
||||||
|
if wtf.Config.UBool("wtf.mods.pagerduty.showSchedules", true) {
|
||||||
|
onCalls, err1 = GetOnCalls()
|
||||||
|
}
|
||||||
|
|
||||||
|
if wtf.Config.UBool("wtf.mods.pagerduty.showIncidents") {
|
||||||
|
incidents, err2 = GetIncidents()
|
||||||
|
}
|
||||||
|
|
||||||
widget.View.SetTitle(widget.ContextualTitle(fmt.Sprintf("%s", widget.Name)))
|
widget.View.SetTitle(widget.ContextualTitle(fmt.Sprintf("%s", widget.Name)))
|
||||||
widget.View.Clear()
|
widget.View.Clear()
|
||||||
|
|
||||||
var content string
|
var content string
|
||||||
if err != nil {
|
if err1 != nil || err2 != nil {
|
||||||
widget.View.SetWrap(true)
|
widget.View.SetWrap(true)
|
||||||
content = err.Error()
|
if err1 != nil {
|
||||||
|
content = content + err1.Error()
|
||||||
|
}
|
||||||
|
if err2 != nil {
|
||||||
|
content = content + err2.Error()
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
widget.View.SetWrap(false)
|
widget.View.SetWrap(false)
|
||||||
content = widget.contentFrom(onCalls)
|
content = widget.contentFrom(onCalls, incidents)
|
||||||
}
|
}
|
||||||
|
|
||||||
widget.View.SetText(content)
|
widget.View.SetText(content)
|
||||||
@ -43,9 +60,19 @@ func (widget *Widget) Refresh() {
|
|||||||
|
|
||||||
/* -------------------- Unexported Functions -------------------- */
|
/* -------------------- Unexported Functions -------------------- */
|
||||||
|
|
||||||
func (widget *Widget) contentFrom(onCalls []pagerduty.OnCall) string {
|
func (widget *Widget) contentFrom(onCalls []pagerduty.OnCall, incidents []pagerduty.Incident) string {
|
||||||
var str string
|
var str string
|
||||||
|
|
||||||
|
if len(incidents) > 0 {
|
||||||
|
str = str + "[yellow]Incidents[white]\n"
|
||||||
|
for _, incident := range incidents {
|
||||||
|
str = str + fmt.Sprintf("[red]%s[white]\n", incident.Summary)
|
||||||
|
str = str + fmt.Sprintf("Status: %s\n", incident.Status)
|
||||||
|
str = str + fmt.Sprintf("Service: %s\n", incident.Service.Summary)
|
||||||
|
str = str + fmt.Sprintf("Escalation: %s\n", incident.EscalationPolicy.Summary)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
tree := make(map[string][]pagerduty.OnCall)
|
tree := make(map[string][]pagerduty.OnCall)
|
||||||
|
|
||||||
filtering := wtf.Config.UList("wtf.mods.pagerduty.escalationFilter")
|
filtering := wtf.Config.UList("wtf.mods.pagerduty.escalationFilter")
|
||||||
@ -69,13 +96,16 @@ func (widget *Widget) contentFrom(onCalls []pagerduty.OnCall) string {
|
|||||||
|
|
||||||
sort.Strings(keys)
|
sort.Strings(keys)
|
||||||
|
|
||||||
// Print out policies, and escalation order of users
|
if len(keys) > 0 {
|
||||||
for _, key := range keys {
|
str = str + "[yellow]Schedules[white]\n"
|
||||||
str = str + fmt.Sprintf("[red]%s\n", key)
|
// Print out policies, and escalation order of users
|
||||||
values := tree[key]
|
for _, key := range keys {
|
||||||
sort.Sort(ByEscalationLevel(values))
|
str = str + fmt.Sprintf("[red]%s\n", key)
|
||||||
for _, item := range values {
|
values := tree[key]
|
||||||
str = str + fmt.Sprintf("[white]%d - %s\n", item.EscalationLevel, item.User.Summary)
|
sort.Sort(ByEscalationLevel(values))
|
||||||
|
for _, item := range values {
|
||||||
|
str = str + fmt.Sprintf("[white]%d - %s\n", item.EscalationLevel, item.User.Summary)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user