Skip to content

Commit

Permalink
add warning icon for high urgency incidents
Browse files Browse the repository at this point in the history
  • Loading branch information
frese committed May 5, 2020
1 parent 514a822 commit 9b97bff
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 8 additions & 4 deletions src/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var menuItems = []trayhost.MenuItem{
{
Title: "Pause",
Handler: func() {
appNotify("Pagerduty Notifier", "This is not implemeted yet.", "", 30*time.Second)
appNotify("Pagerduty Notifier", "This is not implemeted yet.", "", nil, 30*time.Second)
},
},
{
Expand Down Expand Up @@ -67,10 +67,10 @@ func appInit() {
func toggleStartup() {
if existsLaunchConf() {
deleteLaunchConf()
appNotify("Pagerduty Notifier", "Removed from Launch configuration", "", 10*time.Second)
appNotify("Pagerduty Notifier", "Removed from Launch configuration", "", nil, 10*time.Second)
} else {
writeLaunchConf()
appNotify("Pagerduty Notifier", "Added to launch configuration", "", 10*time.Second)
appNotify("Pagerduty Notifier", "Added to launch configuration", "", nil, 10*time.Second)
}
}

Expand All @@ -79,7 +79,7 @@ func appEnterLoop() {
trayhost.EnterLoop()
}

func appNotify(title string, message string, url string, timeout time.Duration) {
func appNotify(title string, message string, url string, image *trayhost.Image, timeout time.Duration) {

notification := trayhost.Notification{
Title: title,
Expand All @@ -91,6 +91,10 @@ func appNotify(title string, message string, url string, timeout time.Duration)
notification.Handler = func() { openBrowser(url) }
}

if image != nil {
notification.Image = *image
}

notification.Display()
}

Expand Down
6 changes: 3 additions & 3 deletions src/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ func cfgInit() *ini.File {

switch runtime.GOOS {
case "linux":
appNotify("HOME/.pagerduty.ini", "No ini file found, click here to see how.", "https://github.com/trustpilot/pagerduty-notifier", 0)
appNotify("HOME/.pagerduty.ini", "No ini file found, click here to see how.", "https://github.com/trustpilot/pagerduty-notifier", nil, 0)
os.Exit(1)

case "windows":
appNotify("HOME/.pagerduty.ini", "No ini file found, click here to see how.", "https://github.com/trustpilot/pagerduty-notifier", 0)
appNotify("HOME/.pagerduty.ini", "No ini file found, click here to see how.", "https://github.com/trustpilot/pagerduty-notifier", nil, 0)
os.Exit(1)

case "darwin":
Expand All @@ -99,7 +99,7 @@ func cfgInit() *ini.File {
os.Exit(1)
}

appNotify("HOME/.pagerduty.ini", "Created default config file, please edit and add token !", "https://github.com/trustpilot/pagerduty-notifier", 0)
appNotify("HOME/.pagerduty.ini", "Created default config file, please edit and add token !", "https://github.com/trustpilot/pagerduty-notifier", nil, 0)
os.Exit(0)

default:
Expand Down
9 changes: 8 additions & 1 deletion src/pd.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/PagerDuty/go-pagerduty"
"github.com/go-ini/ini"
"github.com/shurcooL/trayhost"
)

var pd *pagerduty.Client
Expand Down Expand Up @@ -208,6 +209,12 @@ func pdNotify(i pagerduty.Incident) {
title = fmt.Sprintf("Incident %s", i.Status)
message = removeCharacters(i.APIObject.Summary, "[]")
}
image := trayhost.Image{}

appNotify(title, message, i.APIObject.HTMLURL, 0)
if i.Urgency == "high" {
image.Kind = "png"
image.Bytes = getIcon("warning.png")
}

appNotify(title, message, i.APIObject.HTMLURL, &image, 0)
}

0 comments on commit 9b97bff

Please sign in to comment.