Sending alerts to your Linux desktop when things go wrong

I run gnome on my work desktop, and even with our various monitoring solutions I still use some custom notification tools to get alerted when specific issues occur. One of these tools is gnome-notify, which allows you to create a visible notification inside your desktop workspace. This tool has several useful options, which are displayed when you run notify-send with the “-?” option:

$ /usr/bin/notify-send -?

/usr/bin/notify-send [OPTION...] [BODY] - create a notification

Help Options:
-?, --help Show help options

Application Options:
-u, --urgency=LEVEL Specifies the urgency level (low, normal, critical).
-t, --expire-time=TIME Specifies the timeout in milliseconds at which to expire the notification.
-i, --icon=ICON[,ICON...] Specifies an icon filename or stock icon to display.
-c, --category=TYPE[,TYPE...] Specifies the notification category.
-h, --hint=TYPE:NAME:VALUE Specifies basic extra data to pass. Valid types are int, double, string and byte.
-v, --version Version of the package.

To use this tool to send an alert when a fault is detected, I typically wrap some conditional logic to parse the output of one or more commands:


if [ "${system_check}" = "1" ] then;
    /usr/bin/notify-send -t 10000 -u critical "Problem with server X"

The code above will run the command embedded inside $(), and capture the output from this command in the variable system_check. If the value of the output is 1, then notify-send will be invoked to send a notification with the string “Problem with server X” to my desktop. The real value of notify-send comes when you combine it with the clusterit tools, and generate notifications based on the result of running a command across ALL of your servers. Nice!

This article was posted by Matty on 2010-05-30 08:44:00 -0400 EDT