arch bash cakephp dauth devops drupal fosdem foss git golang information age linux lua mail monitoring music n900 netlog openstack php productivity python real life thesis travel uzbl vimeo web2.0

Nagios monitoring in your desktop panel aka Xfce Genmon panel plugin rules!

FOSS is written by users, for users, and what I've been doing/experiencing this afternoon is a perfect example of that.
First of all take Xfce: a lightweight but sleek and flexible Desktop Environment. Then take a look at the Xfce Goodies project, more specifically the Panel Plugins page. There are plenty of panel plugins to make your life easier: they check your mail, you can control your media player, they can show how your pc performs, built-in dictionaries, translate tools or command lines, show weather forecasts and so on.

Now, for work I need to keep an eye on Nagios, (Nagios is a great FOSS host/service monitoring web application) but I don't like periodically checking the same webpage over and over again:
news should come to me, not the other way around.

Now, I had already found an excellent Nagios Checker Firefox extension but then I would need to have Firefox open all the time, which I don't.
So at first I wanted to write my own panel plugin that would let me allow seeing the most important Nagios status information but then I came across the coolest Xfce panel plugin of them all: the Genmon plugin. This is a plugin which you can add as many times to your panel as you want, and for each instance you can configure a script that it should run, and the frequency of it. Like this you can create your own simple scripts (in php, bash, perl, python,...) which generate content (eg: text and images to be shown on the panel, tooltip, on-click action etc) and the Genmon plugin takes care of the rest.

This is exactly what I've done and in less then an hour everything was working just like I wanted :-)
Well, not exactly: apparently the on-click action is bound to the image you show. I would rather show no image at all and just show text with an on-click action bound to it, but this seems not possible so I had to use an icon. This made my panel a bit larger (as text is shown beneath the icon, you can't configure it to place it next to it) Also it would be neat if I could work with colors: red for hosts who are down, green for those who are up etc. Some details I could achieve if I would make my hands dirty, but for now I don't have time to enhance the Genmon plugin or to write my own, so I just live with it ;-)

Anyways, enough talk.

Here is a screenshot:

The cursor is not on the screenshot but I was obviously hoovering over the panel plugin to show the tooltip.
You can also see at the left the notes plugin and the mail checker plugin and at the right the volume control, trash applet, battery monitor, systray, clock and action button(s) panel plugins.

And here is the source code of my bash script

#!/bin/bash

#
# Written by Dieter Plaetinck
# Licensed under the GPL V3
# See gnu.org/licenses/gpl-3.0.html
#
# works for Nagios 2.x No idea about 3.x 


URL=https://<yourhost>/nagios/cgi-bin/tac.cgi
USERNAME=username
PASSWORD=password

PAGE=$(curl -s -k -u $USERNAME:$PASSWORD $URL)
HOSTS_DOWN=$(           echo -e "$PAGE" | grep "hoststatustypes=4' class='hostHeader'" | awk '{print $5}' | cut -c 20-)
HOSTS_UNREACHABLE=$(    echo -e "$PAGE" | grep "hoststatustypes=8' class='hostHeader'" | awk '{print $5}' | cut -c 20-)
HOSTS_UP=$(             echo -e "$PAGE" | grep "hoststatustypes=2' class='hostHeader'" | awk '{print $5}' | cut -c 20-)
HOSTS_PENDING=$(        echo -e "$PAGE" | grep "hoststatustypes=1' class='hostHeader'" | awk '{print $5}' | cut -c 20-)

SERVICES_CRIT=$(        echo -e "$PAGE" | grep "servicestatustypes=16' class='serviceHeader'" | awk '{print $5}' | cut -c 23-)
SERVICES_WARN=$(        echo -e "$PAGE" | grep "servicestatustypes=4' class='serviceHeader'" | awk '{print $5}' | cut -c 23-)
SERVICES_UNKNOWN=$(     echo -e "$PAGE" | grep "servicestatustypes=8' class='serviceHeader'" | awk '{print $5}' | cut -c 23-)
SERVICES_OK=$(          echo -e "$PAGE" | grep "servicestatustypes=2' class='serviceHeader'" | awk '{print $5}' | cut -c 23-)
SERVICES_PENDING=$(     echo -e "$PAGE" | grep "servicestatustypes=1' class='serviceHeader'" | awk '{print $5}' | cut -c 23-)
echo "<img>scripts/nagios.gif</img>"
echo "<txt>$HOSTS_DOWN-$SERVICES_CRIT/$SERVICES_WARN</txt>"
echo "<tool>Hosts: $HOSTS_DOWN down / $HOSTS_UNREACHABLE unreachable / $HOSTS_UP up / $HOSTS_PENDING pending
Services: $SERVICES_CRIT crit / $SERVICES_WARN warn / $SERVICES_UNKNOWN unknown / $SERVICES_OK ok / $SERVICES_PENDING pending</tool>"
echo "<click>firefox https://<yourhost>/nagios</click>"

At my company we use https, If you use http I don't know if the authentication method is the same. If not check the -d flag for curl.
The icon is just one I took from the nagios page and resized it a bit. The script will be running in your home directory (even though you can put it anywhere you want)

PS: does anyone know a good Apple Keychain- like daemon that I can query from other scripts to receive passwords? Preferably GTK ones that do not pull in Gnome deps. So I don't have to store passwords in cleartext... (and I need this anyway for other purposes :p)

Comments

Don't you modified your script for conky monitor?

No, but it should be easy to do if you are a bit familiar with shell scripting.

(In fact, looking back at it now, this code makes me blush a bit :-)

That plugin is useful and fun. If the height of your panel is less than 25, then the image and the text will be placed together and just take one line. (This is hard code, so you can not change this limit unless you recompile it.) Also, you can modify the source to make text clickable, which should be easy since you could copy the code which makes the picture clickable.

That script works great, thanks for sharing it! I have adapted it for conky, you can find it here:

http://www.epr.ch/brb/wiki/doku.php/blog/display_nagios_status_on_the_de...

Thanks for this, it was exactly what I was looking for. I know you said that you didn't like having to have the icon, but I actually have turned that to an advantage. I modified the script to change the icon based on the status. It is a monitor icon if everything is okay, a yellow triangle warning icon if there are any unknown or warn services or unreachable hosts, and an red circle error if there are any critical services or hosts down.

I think I have used standard gnome icons, so hopefully they should be already on your system. Also, I have tried it on nagios 3 as well with no issues so far. Here is my modified version:

# # Written by Dieter Plaetinck # Licensed under the GPL V3 # See gnu.org/licenses/gpl-3.0.html # # works for Nagios 2.x No idea about 3.x URL=http://your_url/nagios2/ USERNAME=username PASSWORD=password PAGE=$(curl -s -k -u $USERNAME:$PASSWORD $URL) HOSTS_DOWN=$( echo -e "$PAGE" | grep "hoststatustypes=4' class='hostHeader'" | awk '{print $5}' | cut -c 20-) HOSTS_UNREACHABLE=$( echo -e "$PAGE" | grep "hoststatustypes=8' class='hostHeader'" | awk '{print $5}' | cut -c 20-) HOSTS_UP=$( echo -e "$PAGE" | grep "hoststatustypes=2' class='hostHeader'" | awk '{print $5}' | cut -c 20-) HOSTS_PENDING=$( echo -e "$PAGE" | grep "hoststatustypes=1' class='hostHeader'" | awk '{print $5}' | cut -c 20-) SERVICES_CRIT=$( echo -e "$PAGE" | grep "servicestatustypes=16' class='serviceHeader'" | awk '{print $5}' | cut -c 23-) SERVICES_WARN=$( echo -e "$PAGE" | grep "servicestatustypes=4' class='serviceHeader'" | awk '{print $5}' | cut -c 23-) SERVICES_UNKNOWN=$( echo -e "$PAGE" | grep "servicestatustypes=8' class='serviceHeader'" | awk '{print $5}' | cut -c 23-) SERVICES_OK=$( echo -e "$PAGE" | grep "servicestatustypes=2' class='serviceHeader'" | awk '{print $5}' | cut -c 23-) SERVICES_PENDING=$( echo -e "$PAGE" | grep "servicestatustypes=1' class='serviceHeader'" | awk '{print $5}' | cut -c 23-) HAD_ERROR="FALSE" if [ "$HOSTS_DOWN" != "0" ]; then echo "/usr/share/icons/gnome/16x16/status/dialog-error.png" HAD_ERROR="TRUE" fi if [ "$SERVICES_CRIT" != "0" ]; then echo "/usr/share/icons/gnome/16x16/status/dialog-error.png" HAD_ERROR="TRUE" fi if [ "$HOSTS_UNREACHABLE" != "0" ]; then echo "/usr/share/icons/gnome/16x16/status/dialog-warning.png" HAD_ERROR="TRUE" fi if [ "$SERVICES_WARN" != "0" ]; then echo "/usr/share/icons/gnome/16x16/status/dialog-warning.png" HAD_ERROR="TRUE" fi if [ "$SERVICES_UNKNOWN" != "0" ]; then echo "/usr/share/icons/gnome/16x16/status/dialog-warning.png" HAD_ERROR="TRUE" fi if [ "$HAD_ERROR" = "FALSE" ]; then echo "/usr/share/icons/gnome/16x16/apps/gnome-monitor.png" fi echo "$HOSTS_DOWN-$SERVICES_CRIT/$SERVICES_WARN" echo "Hosts: $HOSTS_DOWN down / $HOSTS_UNREACHABLE unreachable / $HOSTS_UP up / $HOSTS_PENDING pending Services: $SERVICES_CRIT crit / $SERVICES_WARN warn / $SERVICES_UNKNOWN unknown / $SERVICES_OK ok / $SERVICES_PENDING pending" echo "/usr/bin/google-chrome your_url/nagios2/"


Name:


E-mail:


URL:


Comment:


What is the first name of the guy blogging here?


This comment form is pretty crude. Make sure mandatory fields are entered correctly.
Basic html tags (a,i,b, etc) are allowed, others are sanitized