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

Handle offline scenarios for OpsGenie

This commit is contained in:
Chris Cummer 2018-04-09 09:48:45 -07:00 committed by Chris Cummer
parent 204e3b4032
commit aa658db210
6 changed files with 46 additions and 32 deletions

View File

@ -1,7 +1,7 @@
wtf:
refreshInterval: 1
bamboohr:
enabled: false
enabled: true
position:
top: 0
left: 0
@ -11,7 +11,7 @@ wtf:
url: "https://api.bamboohr.com/api/gateway.php"
gcal:
currentIcon: "💥"
enabled: false
enabled: true
eventCount: 10
position:
top: 2
@ -22,7 +22,7 @@ wtf:
secretFile: "~/.wtf/gcal/client_secret.json"
git:
commitCount: 5
enabled: false
enabled: true
position:
top: 0
left: 2
@ -31,7 +31,7 @@ wtf:
refreshInterval: 8
repository: "/Users/chris/go/src/github.com/senorprogrammer/wtf"
github:
enabled: false
enabled: true
organization: "BetterOfficeApps"
position:
top: 2
@ -42,7 +42,7 @@ wtf:
repo: "core-api"
username: "senorprogrammer"
jira:
enabled: false
enabled: true
position:
top: 1
left: 1
@ -51,16 +51,16 @@ wtf:
refreshInterval: 900
newrelic:
applicationId: 10549735
enabled: false
deployCount: 7
enabled: true
deployCount: 10
position:
top: 4
left: 2
height: 1
height: 2
width: 3
refreshInterval: 900
opsgenie:
enabled: false
enabled: true
position:
top: 2
left: 0
@ -68,20 +68,20 @@ wtf:
width: 1
refreshInterval: 21600
security:
enabled: false
enabled: true
position:
top: 5
top: 4
left: 0
height: 1
width: 1
refreshInterval: 3600
status:
enabled: false
enabled: true
position:
top: 5
left: 2
height: 3
width: 3
left: 0
height: 1
width: 1
refreshInterval: 1
weather:
cityId: 6173331

View File

@ -69,10 +69,9 @@ func (widget *Widget) contentFrom(deploys []nr.ApplicationDeployment) string {
for _, deploy := range deploys {
if (deploy.Revision != "") && wtf.Exclude(revisions, deploy.Revision) {
str = str + fmt.Sprintf(
" %03d [green]%s[white] %-6s %s\n",
deploy.ID%1000,
" [green]%s[white] %s %-16s\n",
deploy.Revision[0:8],
deploy.Timestamp.Format("Jan 2"),
deploy.Timestamp.Format("Jan 02, 15:04"),
wtf.NameFromEmail(deploy.User),
)

View File

@ -27,22 +27,21 @@ type Parent struct {
/* -------------------- Exported Functions -------------------- */
func Fetch() *OnCallResponse {
func Fetch() (*OnCallResponse, error) {
apiKey := os.Getenv("WTF_OPS_GENIE_API_KEY")
scheduleUrl := "https://api.opsgenie.com/v2/schedules/on-calls?flat=true"
var onCallResponse OnCallResponse
opsGenieRequest(scheduleUrl, apiKey, &onCallResponse)
response, err := opsGenieRequest(scheduleUrl, apiKey)
return &onCallResponse
return response, err
}
/* -------------------- Unexported Functions -------------------- */
func opsGenieRequest(url string, apiKey string, payload interface{}) {
func opsGenieRequest(url string, apiKey string) (*OnCallResponse, error) {
req, err := http.NewRequest("GET", url, nil)
if err != nil {
panic(err)
return nil, err
}
req.Header.Set("Authorization", fmt.Sprintf("GenieKey %s", apiKey))
@ -51,11 +50,14 @@ func opsGenieRequest(url string, apiKey string, payload interface{}) {
resp, err := client.Do(req)
if err != nil {
panic(err)
return nil, err
}
defer resp.Body.Close()
if err := json.NewDecoder(resp.Body).Decode(payload); err != nil {
panic(err)
response := &OnCallResponse{}
if err := json.NewDecoder(resp.Body).Decode(response); err != nil {
return nil, err
}
return response, nil
}

View File

@ -34,13 +34,20 @@ func (widget *Widget) Refresh() {
return
}
data := Fetch()
data, err := Fetch()
widget.View.SetTitle(" ⏰ On Call ")
widget.RefreshedAt = time.Now()
widget.View.Clear()
if err != nil {
widget.View.SetWrap(true)
fmt.Fprintf(widget.View, "%s", err)
} else {
widget.View.SetWrap(false)
fmt.Fprintf(widget.View, "%s", widget.contentFrom(data))
}
}
/* -------------------- Unexported Functions -------------------- */

View File

@ -58,8 +58,14 @@ func (widget *Widget) addView() {
}
func (widget *Widget) contentFrom(data map[string]string) string {
str := fmt.Sprintf(" Firewall: %s Network: %s\n", data["Enabled"], data["Network"])
str = str + fmt.Sprintf(" Stealth: %s Crypto: %s\n", data["Stealth"], data["Encryption"])
str := " [red]WiFi[white]\n"
str = str + fmt.Sprintf(" %8s: %s\n", "Network", data["Network"])
str = str + fmt.Sprintf(" %8s: %s\n", "Crypto", data["Encryption"])
str = str + "\n"
str = str + " [red]Firewall[white]\n"
str = str + fmt.Sprintf(" %8s: %s\n", "Enabled", data["Enabled"])
str = str + fmt.Sprintf(" %8s: %s\n", "Stealth", data["Stealth"])
str = str + "\n"
return str
}

View File

@ -37,7 +37,7 @@ func (widget *Widget) Refresh() {
data := Fetch(Config.UInt("wtf.weather.cityId", 6176823))
widget.View.SetTitle(fmt.Sprintf(" %s Weather - %s ", icon(data), data.Name))
widget.View.SetTitle(fmt.Sprintf(" %s Weather: [green]%s[white] ", icon(data), data.Name))
widget.RefreshedAt = time.Now()
widget.View.Clear()