1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00

OpsGenie on-call schedules into dashboard

This commit is contained in:
Chris Cummer 2018-04-03 03:44:57 -07:00 committed by Chris Cummer
parent 3ebb299350
commit ff994cb793
3 changed files with 29 additions and 25 deletions

View File

@ -7,28 +7,28 @@ import (
"os"
)
type Data struct {
OnCallRecipients []string `json:"onCallRecipients"`
Parent Parent `json:"_parent"`
}
type OnCallData struct {
Data Data `json:"data"`
type OnCallResponse struct {
OnCallData []OnCallData `json:"data"`
Message string `json:"message"`
RequestID string `json:"requestId"`
Took float32 `json:"took"`
}
type OnCallData struct {
Recipients []string `json:"onCallRecipients"`
Parent Parent `json:"_parent"`
}
type Parent struct {
ID string `json:"id"`
Name string `json:"name"`
Enabled bool `json:"enabled"`
}
func Fetch() *OnCallData {
func Fetch() *OnCallResponse {
apiKey := os.Getenv("WTF_OPS_GENIE_API_KEY")
scheduleName := "Oversight"
url := fmt.Sprintf("https://api.opsgenie.com/v2/schedules/%s/on-calls?scheduleIdentifierType=name&flat=true", scheduleName)
url := "https://api.opsgenie.com/v2/schedules/on-calls?flat=true"
req, err := http.NewRequest("GET", url, nil)
if err != nil {
@ -45,11 +45,10 @@ func Fetch() *OnCallData {
}
defer resp.Body.Close()
var onCallData OnCallData
if err := json.NewDecoder(resp.Body).Decode(&onCallData); err != nil {
var onCallResponse OnCallResponse
if err := json.NewDecoder(resp.Body).Decode(&onCallResponse); err != nil {
panic(err)
}
return &onCallData
return &onCallResponse
}

View File

@ -20,7 +20,7 @@ func NewWidget() *Widget {
BaseWidget: wtf.BaseWidget{
Name: "OpsGenie",
RefreshedAt: time.Now(),
RefreshInt: 28800,
RefreshInt: 21600,
},
}
@ -35,7 +35,7 @@ func NewWidget() *Widget {
func (widget *Widget) Refresh() {
data := Fetch()
widget.View.SetTitle(" OpsGenie ")
widget.View.SetTitle(" ⏰ On Call ")
widget.RefreshedAt = time.Now()
widget.View.Clear()
@ -51,14 +51,19 @@ func (widget *Widget) addView() {
view.SetBorderColor(tcell.ColorGray)
view.SetDynamicColors(true)
view.SetTitle(widget.Name)
view.SetWrap(false)
widget.View = view
}
func (widget *Widget) contentFrom(onCallData *OnCallData) string {
func (widget *Widget) contentFrom(onCallResponse *OnCallResponse) string {
str := "\n"
str = str + fmt.Sprintf(" [red]%s[white]\n", onCallData.Data.Parent.Name)
str = str + fmt.Sprintf(" %s\n", strings.Join(onCallData.Data.OnCallRecipients, ", "))
for _, data := range onCallResponse.OnCallData {
str = str + fmt.Sprintf(" [green]%s[white]\n", data.Parent.Name)
str = str + fmt.Sprintf(" %s\n", strings.Join(data.Recipients, ", "))
str = str + "\n"
}
return str
}

10
wtf.go
View File

@ -55,18 +55,18 @@ func main() {
weather.Refresh()
grid := tview.NewGrid()
grid.SetRows(9, 9, 9, 9, 15, 3) // How _high_ the row is, in terminal rows
grid.SetRows(9, 9, 9, 9, 9, 6, 3) // How _high_ the row is, in terminal rows
grid.SetColumns(40, 40) // How _wide_ the column is, in terminal columns
grid.SetBorder(false)
grid.AddItem(bamboo.View, 0, 0, 2, 1, 0, 0, false)
grid.AddItem(cal.View, 2, 0, 3, 1, 0, 0, false)
grid.AddItem(cal.View, 2, 1, 4, 1, 0, 0, false)
grid.AddItem(git.View, 0, 2, 3, 1, 0, 0, false)
grid.AddItem(weather.View, 0, 1, 1, 1, 0, 0, false)
grid.AddItem(sec.View, 1, 1, 1, 1, 0, 0, false)
grid.AddItem(opsgenie.View, 2, 1, 1, 1, 0, 0, false)
grid.AddItem(jira.View, 3, 1, 1, 1, 0, 0, false)
grid.AddItem(stat.View, 5, 0, 3, 3, 0, 0, false)
grid.AddItem(opsgenie.View, 2, 0, 3, 1, 0, 0, false)
grid.AddItem(jira.View, 5, 0, 1, 1, 0, 0, false)
grid.AddItem(stat.View, 6, 0, 3, 3, 0, 0, false)
app := tview.NewApplication()