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:
parent
3ebb299350
commit
ff994cb793
@ -7,15 +7,16 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Data struct {
|
type OnCallResponse struct {
|
||||||
OnCallRecipients []string `json:"onCallRecipients"`
|
OnCallData []OnCallData `json:"data"`
|
||||||
Parent Parent `json:"_parent"`
|
Message string `json:"message"`
|
||||||
|
RequestID string `json:"requestId"`
|
||||||
|
Took float32 `json:"took"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type OnCallData struct {
|
type OnCallData struct {
|
||||||
Data Data `json:"data"`
|
Recipients []string `json:"onCallRecipients"`
|
||||||
Message string `json:"message"`
|
Parent Parent `json:"_parent"`
|
||||||
RequestID string `json:"requestId"`
|
|
||||||
Took float32 `json:"took"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type Parent struct {
|
type Parent struct {
|
||||||
@ -24,11 +25,10 @@ type Parent struct {
|
|||||||
Enabled bool `json:"enabled"`
|
Enabled bool `json:"enabled"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func Fetch() *OnCallData {
|
func Fetch() *OnCallResponse {
|
||||||
apiKey := os.Getenv("WTF_OPS_GENIE_API_KEY")
|
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)
|
req, err := http.NewRequest("GET", url, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -45,11 +45,10 @@ func Fetch() *OnCallData {
|
|||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
var onCallData OnCallData
|
var onCallResponse OnCallResponse
|
||||||
|
if err := json.NewDecoder(resp.Body).Decode(&onCallResponse); err != nil {
|
||||||
if err := json.NewDecoder(resp.Body).Decode(&onCallData); err != nil {
|
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return &onCallData
|
return &onCallResponse
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ func NewWidget() *Widget {
|
|||||||
BaseWidget: wtf.BaseWidget{
|
BaseWidget: wtf.BaseWidget{
|
||||||
Name: "OpsGenie",
|
Name: "OpsGenie",
|
||||||
RefreshedAt: time.Now(),
|
RefreshedAt: time.Now(),
|
||||||
RefreshInt: 28800,
|
RefreshInt: 21600,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -35,7 +35,7 @@ func NewWidget() *Widget {
|
|||||||
func (widget *Widget) Refresh() {
|
func (widget *Widget) Refresh() {
|
||||||
data := Fetch()
|
data := Fetch()
|
||||||
|
|
||||||
widget.View.SetTitle(" OpsGenie ")
|
widget.View.SetTitle(" ⏰ On Call ")
|
||||||
widget.RefreshedAt = time.Now()
|
widget.RefreshedAt = time.Now()
|
||||||
|
|
||||||
widget.View.Clear()
|
widget.View.Clear()
|
||||||
@ -51,14 +51,19 @@ func (widget *Widget) addView() {
|
|||||||
view.SetBorderColor(tcell.ColorGray)
|
view.SetBorderColor(tcell.ColorGray)
|
||||||
view.SetDynamicColors(true)
|
view.SetDynamicColors(true)
|
||||||
view.SetTitle(widget.Name)
|
view.SetTitle(widget.Name)
|
||||||
|
view.SetWrap(false)
|
||||||
|
|
||||||
widget.View = view
|
widget.View = view
|
||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) contentFrom(onCallData *OnCallData) string {
|
func (widget *Widget) contentFrom(onCallResponse *OnCallResponse) string {
|
||||||
str := "\n"
|
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
|
return str
|
||||||
}
|
}
|
||||||
|
12
wtf.go
12
wtf.go
@ -55,18 +55,18 @@ func main() {
|
|||||||
weather.Refresh()
|
weather.Refresh()
|
||||||
|
|
||||||
grid := tview.NewGrid()
|
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.SetColumns(40, 40) // How _wide_ the column is, in terminal columns
|
||||||
grid.SetBorder(false)
|
grid.SetBorder(false)
|
||||||
|
|
||||||
grid.AddItem(bamboo.View, 0, 0, 2, 1, 0, 0, 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(git.View, 0, 2, 3, 1, 0, 0, false)
|
||||||
grid.AddItem(weather.View, 0, 1, 1, 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(sec.View, 1, 1, 1, 1, 0, 0, false)
|
||||||
grid.AddItem(opsgenie.View, 2, 1, 1, 1, 0, 0, false)
|
grid.AddItem(opsgenie.View, 2, 0, 3, 1, 0, 0, false)
|
||||||
grid.AddItem(jira.View, 3, 1, 1, 1, 0, 0, false)
|
grid.AddItem(jira.View, 5, 0, 1, 1, 0, 0, false)
|
||||||
grid.AddItem(stat.View, 5, 0, 3, 3, 0, 0, false)
|
grid.AddItem(stat.View, 6, 0, 3, 3, 0, 0, false)
|
||||||
|
|
||||||
app := tview.NewApplication()
|
app := tview.NewApplication()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user