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

Display OpsGenie oncall data for one specific schedule

This commit is contained in:
Chris Cummer 2018-04-02 21:41:46 -07:00 committed by Chris Cummer
parent 62502c24d0
commit 945dfc8db7
6 changed files with 71 additions and 38 deletions

View File

@ -58,7 +58,7 @@ func (widget *Widget) contentFrom(items []Item) string {
return fmt.Sprintf("\n\n\n\n\n\n\n%s", wtf.CenterText("[grey]no one[white]", 52))
}
str := ""
str := "\n"
for _, item := range items {
str = str + widget.format(item)
}

View File

@ -9,13 +9,11 @@ import (
type Client struct {
CommitCount int
Repository string
}
func NewClient() *Client {
client := Client{
CommitCount: 10,
Repository: "/Users/Chris/Documents/Lendesk/core-api",
}
return &client
@ -23,7 +21,7 @@ func NewClient() *Client {
/* -------------------- Unexported Functions -------------------- */
func (client *Client) CurrentBranch() string {
func (client *Client) Branch() string {
arg := []string{"rev-parse", "--abbrev-ref", "HEAD"}
cmd := exec.Command("git", arg...)
str := wtf.ExecuteCommand(cmd)
@ -50,3 +48,11 @@ func (client *Client) Commits() []string {
return data
}
func (client *Client) Repository() string {
arg := []string{"rev-parse", "--show-toplevel"}
cmd := exec.Command("git", arg...)
str := wtf.ExecuteCommand(cmd)
return str
}

View File

@ -7,8 +7,8 @@ func Fetch() map[string][]string {
result := make(map[string][]string)
result["repo"] = []string{client.Repository}
result["branch"] = []string{client.CurrentBranch()}
result["repo"] = []string{client.Repository()}
result["branch"] = []string{client.Branch()}
result["changes"] = client.ChangedFiles()
result["commits"] = client.Commits()

View File

@ -1,33 +1,55 @@
package opsgenie
import (
"encoding/json"
"fmt"
"net/http"
"os"
ogcli "github.com/opsgenie/opsgenie-go-sdk/client"
sch "github.com/opsgenie/opsgenie-go-sdk/schedule"
)
func Fetch() string {
apiKey := os.Getenv("WTF_OPS_GENIE_API_KEY")
cli := new(ogcli.OpsGenieClient)
cli.SetAPIKey(apiKey)
scheduler, err := cli.Schedule()
if err != nil {
panic(err)
}
request := sch.ListSchedulesRequest{}
response, err := scheduler.List(request)
if err != nil {
panic(err)
}
var str string
for _, schedule := range response.Schedules {
str = str + schedule.Name + "\n"
}
return ""
type Data struct {
OnCallRecipients []string `json:"onCallRecipients"`
Parent Parent `json:"_parent"`
}
type OnCallData struct {
Data Data `json:"data"`
Message string `json:"message"`
RequestID string `json:"requestId"`
Took float32 `json:"took"`
}
type Parent struct {
ID string `json:"id"`
Name string `json:"name"`
Enabled bool `json:"enabled"`
}
func Fetch() *OnCallData {
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)
req, err := http.NewRequest("GET", url, nil)
if err != nil {
panic(err)
}
req.Header.Set("Authorization", fmt.Sprintf("GenieKey %s", apiKey))
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
var onCallData OnCallData
if err := json.NewDecoder(resp.Body).Decode(&onCallData); err != nil {
panic(err)
}
return &onCallData
}

View File

@ -1,7 +1,8 @@
package opsgenie
import (
//"fmt"
"fmt"
"strings"
"time"
"github.com/rivo/tview"
@ -31,13 +32,13 @@ func NewWidget() *Widget {
/* -------------------- Exported Functions -------------------- */
func (widget *Widget) Refresh() {
//data := Fetch()
data := Fetch()
widget.View.SetTitle(" OpsGenie ")
widget.RefreshedAt = time.Now()
widget.View.Clear()
//fmt.Fprintf(widget.View, "%s", widget.contentFrom(data))
fmt.Fprintf(widget.View, "%s", widget.contentFrom(data))
}
/* -------------------- Unexported Functions -------------------- */
@ -52,6 +53,10 @@ func (widget *Widget) addView() {
widget.View = view
}
func (widget *Widget) contentFrom(data string) string {
return data
func (widget *Widget) contentFrom(onCallData *OnCallData) 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, ", "))
return str
}

View File

@ -32,7 +32,7 @@ func NewWidget() *Widget {
/* -------------------- Exported Functions -------------------- */
func (widget *Widget) Refresh() {
widget.View.SetTitle(" 🎁 Status ")
widget.View.SetTitle(" 🎉 Status ")
widget.RefreshedAt = time.Now()
widget.View.Clear()