[rsyslog] desktop notifications from syslog
Tom Metro
tmetro+rsyslog at gmail.com
Wed Apr 29 22:05:11 CEST 2009
Is there a recommended technique for displaying notifications on a GUI
desktop from syslog? To me it seems like a significant oversight that
such a feature isn't built-in to modern desktop distributions of Linux.
Below the covers the machine could be in serious distress, and the
casual GUI user would be oblivious to it. (I'm aware of xconsole, but
it's more for viewing logs, not getting notifications of just the
serious problems.)
In an attempt to implement such a feature using a small bit of
scripting, the notify-send command (uses libnotify for GUI
notifications), and named pipes fed by sysklogd, I ran into reliability
problems. It seemed like sysklogd sometimes closed the pipe and never
reopened it again until it was restarted.
That led me to rsyslog, which supports the convenient command-execute
target. So a rule like:
*.crit ^/usr/local/bin/rsyslog-notify
executing a script like:
#!/bin/bash
XOWNER=<user>
DISPLAY=:0.0 XAUTHORITY=/home/$XOWNER/.Xauthority notify-send
--urgency=critical --expire-time=0 "SYSLOG: $1" 2>>
/var/log/rsyslog-notify.log
does the trick. (It needs a bit of code added to automatically figure
out the owner of the display. For now, <user> is statically replaced
with the correct user.) However, it took a little bit longer than
necessary to determine that the DISPLAY and XAUTHORITY variables were
necessary, because rsyslog ignores the STDERR produced by the executed
command. It'd be nice if that output was logged, or otherwise brought to
the admin's attention.
I'm wondering if notify-send should be ran in the background to avoid it
potentially hanging rsyslog, as warned in the documentation. I don't
think doing so would have any negative impact on the operation.
An rsyslog output module that directly used the libnotify API might be a
nice thing to have, too.
-Tom
More information about the rsyslog
mailing list