simple scriptable popups in GNOME
As you may or may not already know, we’re into Phing here at Magma Digital. You can fire off all sorts of complex tasks and at the end, you get a report (if you’re using a CI platform). I personally don’t like relying on email for such notifications though. If my build succeeded, then I don’t want to break from what I’m doing to see that. I’d much prefer a simple pop-up notification. I recently discovered “notify-send” which creates a very unobtrusive pop-up in the corner of your screen.
I think the number of possible applications for this is pretty endless; Build notifications, CPD/CodeSniffer violations, bug assignments … even a tea rota.
The problem is that the executable “notify-send” must be run on the remote machine in question, so rather than come up with a daemon of some sort, I opted for SSH. Obviously, having a centralised machine logging in to each developer machine has some security bells ringing, so you can improve on that yourself by setting up a jail or something similar. This is an example in its most basic form. For simplicity, I’m also assuming that you have a passphraseless key setup on the build-server as we’ll call it.
Start by adding the build-server’s public key to your local
~/.ssh/authorized_keys. Once the build server can ssh in, it can trigger the notify-send binary (As an aside, I like restricting the use of SSH keys to specific hosts if I can. Look for “pattern-list” in
man sshd 8 in the AuthorizedKeys File Format section for more information). The magic foo took a couple of iterations to get right, but we got there in the end:
ssh root@dev -t "DISPLAY=:0 sudo -u adrian /usr/bin/notify-send -i /usr/share/icons/gnome/48x48/status/weather-clear.png --hint=int:transient:1 'quick alert' 'New lines andnbasic emphasis are supported'"
-i switch can point to any image file (within reason) and the
--hint business helps people using GNOME 3 and above; without this switch, the notification has to be removed manually, which gets tiresome very quickly. People on GNOME 3 also might want to consider the ShellOSD extension which makes your notifications appear in the good ol’ top right corner.
Now, when a lengthy task has completed you can notify interested parties in such a way that it won’t interfere with their work flow. I’ve even considered writing a bash script which picks a PC at random and tells them to turn the kettle on. However, due to a bug, it will somehow never pop up on my PC.
This is the most basic use case and if you’re security conscious, I can appreciate the shuffling in seats that might be going about a machine logging into yours as root every 20 minutes. However, this post is about the applications of notify-send, not SSH jails.