diff --git a/dist/PagerdutyNotifier.app/Contents/Resources/warning.png b/dist/PagerdutyNotifier.app/Contents/Resources/warning.png new file mode 100644 index 0000000..f50de29 Binary files /dev/null and b/dist/PagerdutyNotifier.app/Contents/Resources/warning.png differ diff --git a/src/app.go b/src/app.go index d7626de..a128527 100644 --- a/src/app.go +++ b/src/app.go @@ -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) }, }, { @@ -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) } } @@ -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, @@ -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() } diff --git a/src/conf.go b/src/conf.go index df779db..387f893 100644 --- a/src/conf.go +++ b/src/conf.go @@ -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": @@ -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: diff --git a/src/pd.go b/src/pd.go index 67a390d..a16ae41 100644 --- a/src/pd.go +++ b/src/pd.go @@ -9,6 +9,7 @@ import ( "github.com/PagerDuty/go-pagerduty" "github.com/go-ini/ini" + "github.com/shurcooL/trayhost" ) var pd *pagerduty.Client @@ -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) }