Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
aliveNotifier
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
kpetersn
aliveNotifier
Commits
37cf91fc
Commit
37cf91fc
authored
7 years ago
by
kpetersn
Browse files
Options
Downloads
Patches
Plain Diff
Added notifications for gnome3
parent
952c1cb1
No related branches found
Branches containing commit
Tags
v1.0
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
an.py
+20
-2
20 additions, 2 deletions
an.py
gnome3-notify.py
+73
-0
73 additions, 0 deletions
gnome3-notify.py
with
93 additions
and
2 deletions
an.py
+
20
−
2
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
...
...
This diff is collapsed.
Click to expand it.
gnome3-notify.py
0 → 100755
+
73
−
0
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
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment