DBus notify-send over network

Last week I tried to use notify-send to notify me on my laptop when telephone calls come in. I already did that for our TV (Dreambox's /web/message?text= script) and had to have this for the computer since I'm using it more often than TV.

Since I don't use KDE anymore, any knotify tools were out of reach for me. There is a nice notify-send which communicates via DBus and has the ability to display bubbles with icons and priorities.

As I found out in IRC and mailing lists, DBus is networkable, in theory - not in practise. So the hard task was to get my remote home server to use notify-send on my laptop to display the message explicitely for me.

With DBus being not networkable, I needed a server daemon that waited for incoming notifications. Me being a web developer, apache2 is always running - no need for an own php daemon here. A simple php script waiting on my apache instance.

Getting going

The first try: A simple `/usr/bin/notify-send test`, which gave me exactly no errors and no notification. Yep, the trailing 2>&1 was missing which told me:

libnotify-Message: Unable to get session bus: dbus-launch failed to
  autolaunch D-Bus session: Autolaunch error: X11 initialization failed.

Clear as chicken soup: The apache user itself can't be notified since he doesn't have an X session. I need to notify my user, cweiske: `sudo -u cweiske /usr/bin/notify-send test 2>&1` which told me:

sudo: no tty present and no askpass program specified

That problem was quickly solved by doing a visudo and adding apache bogo = (cweiske) NOPASSWD: /usr/bin/notify-send to it. After that, I got the same error as before.

DBus itself doesn't need X11, but somehow it wants X session data - probably to display the notification. So, what do we need? ssh -Y sets $DISPLAY, that's for sure: `export DISPLAY=:0 && sudo -u cweiske /usr/bin/notify-send test 2>&1`. The result was slightly different, but no advance:

libnotify-Message: Unable to get session bus: dbus-launch failed to
  autolaunch D-Bus session: Xlib: connection to ":0.0" refused by server
  Xlib: No protocol specified
  
  Autolaunch error: X11 initialization failed.

So something X-y was still missing... as I learned from my previous CHM on Linux adventure, I need some X authorization (xauth). It's running on my laptop, but can't be found on that sudo session. After exporting $XAUTHORITY, it worked:

export DISPLAY=:0 && export XAUTHORITY=/home/cweiske/.Xauthority && sudo -u cweiske /usr/bin/notify-send test 2>&1

Now I have my notification whenever someone calls!

Screenshot of incoming call   notification

And in case anyone is interested - for call notification, I use a Fritz!box USB on my home server together with a highly customized version of capiISDNmon that has been freed from the broken ldapv2-only name resolution and TCP call notification, and added script invocation on incoming calls.

Written by Christian Weiske.

Comments? Please send an e-mail. Or Reply or Like.