Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
kpetersn
aliveNotifier
Commits
37cf91fc
Commit
37cf91fc
authored
Feb 16, 2018
by
kpetersn
Browse files
Added notifications for gnome3
parent
952c1cb1
Changes
2
Hide whitespace changes
Inline
Side-by-side
an.py
View file @
37cf91fc
...
...
@@ -16,7 +16,7 @@ import sys
engineer
=
"Peterson"
# period should match cron job period
period
=
60
0
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
):
notify
OSX
(
ioc
,
state
,
time_str
)
notify
Gnome3
(
ioc
,
state
,
time_str
)
notifyEmail
(
ioc
,
state
,
time_str
)
# set notification function
#!notify = notifyConsole
notify
=
notifyEmail
#!notify = notifyGnome3
#!notify = notifyOSX
#!notify = notifyCombo
...
...
gnome3-notify.py
0 → 100755
View file @
37cf91fc
#!/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
()
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment