Skip to content
Snippets Groups Projects
Commit 37cf91fc authored by kpetersn's avatar kpetersn
Browse files

Added notifications for gnome3

parent 952c1cb1
No related branches found
Tags v1.0
No related merge requests found
......@@ -16,7 +16,7 @@ import sys
engineer = "Peterson"
# period should match cron job period
period = 600
period = 60
# needed for notifyOSX()
osx_command = "/Users/kpetersn/Applications/terminal-notifier.app/Contents/MacOS/terminal-notifier"
......@@ -39,13 +39,31 @@ def notifyOSX(ioc, state, time_str):
notify_command = "%s -title \"%s is %s\" -message \"%s\" -open \"%s\"" % (osx_command, ioc, state, time_str, eng_url)
os.system(notify_command)
def notifyGnome3(ioc, state, time_str):
subject = "%s is %s" % (ioc, state)
message = "Snapshot time: %s" % time_str
url = "%s%s" % (ioc_url, ioc)
# Priority 0 and 1 disappear on their own and end up in the history until it is clicked
# Priority 2 never disappears on its own and never ends up in the history because it requires interaction to dismiss
priority = 1
# Not sure if this is a good idea
#!if state == "DOWN":
#! priority = 2
notify_command = "./gnome3-notify.py \'%s\' \'%s\' %i \'%s\'" % (subject, message, priority, url)
#!print notify_command
os.system(notify_command)
def notifyCombo(ioc, state, time_str):
notifyOSX(ioc, state, time_str)
notifyGnome3(ioc, state, time_str)
notifyEmail(ioc, state, time_str)
# set notification function
#!notify = notifyConsole
notify = notifyEmail
#!notify = notifyGnome3
#!notify = notifyOSX
#!notify = notifyCombo
......
#!/usr/bin/env python
import sys
import os
import gi
gi.require_version('Notify', '0.7')
from gi.repository import Notify
#!from gi.repository import GLib
# This function is unused because I can't get the callbacks to work
def xdg_open(arg):
global loop
# open file or url
if arg != None:
command = "xdg-open \'%s\'" % arg
#!command = "touch %s" % arg
os.system(command)
loop.quit()
def main(args):
global xdg_open
numArgs = len(args)
summary = args[0]
body = args[1]
if numArgs >= 3:
priority = int(args[2])
else:
priority = 0
if numArgs >= 4:
url = args[3]
# If hyperlinks were supported we could append the URL To the body
#!body = body + "\n<a href=" + url + ">" + url + "</a>"
else:
url = None
#!print "url =", url
# The app name doesn't appear in the notifications
Notify.init("gnome3-notify.py")
# Create the notification (icon depends on priority - 0 & 1 = info, 2 = error)
notification = Notify.Notification.new(summary, body)
# An icon can be chosen indepenently of the priority, which is probably a bad idea
#!notification = Notify.Notification.new(summary, body, "dialog-information")
#!notification = Notify.Notification.new(summary, body, "dialog-warning")
#!notification = Notify.Notification.new(summary, body, "dialog-error")
# This should work but it doesn't
#!num = notification.add_action("action_click", "More Info", xdg_open, url)
# urgency 0 or 1 = popup disappers quickly; urgency = 2 makes the popup persist
# Note: the number 1, 2, or 3 can be passed to set_urgency() directly, but an int can't
notification.set_urgency(Notify.Urgency(priority))
# Make the notification appear
notification.show()
if __name__ == '__main__':
#!print sys.argv
if len(sys.argv) < 3:
print "Usage: gnome3-notify.py <summary> <body> [priority] [url]"
#!print sys.argv
else:
#!global loop
main(sys.argv[1:])
#!loop = GLib.MainLoop()
#!loop.run()
Notify.uninit()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment