whatmon: Mozilla Extension for Monitoring Whatever

I spend a good part of any day in my favorite web browser, and even if I don't see its whole window, the lower right part of the status bar is always visible under a pile of other application windows (mostly SSH sessions). That status bar is the ideal place to put up a small monitor with which I can keep an eye on a number of important servers, without having to wait for alerts sent to me by Nagios.
To this effect I have created a tiny Firefox and Thunderbird extension called whatmon, which can monitor almost anything you wish to monitor. Number of logged on users? Current load average? Health of your LDAP servers? Mail server queues? No problem for whatmon, as long as you can create a CGI(Common Gateway Interface) program in Perl, C, or any other language you are comfortable with, or even a PHP or Active-Whatever script which runs on your web server and can produce a wee bit o' XML(eXtensible Markup Language). There is one thing that whatmon can't watch: the web server from which it retrieves that XML …
whatmon periodically reads a short bit of XML text from a web server (in my case: Apache). The XML contains an integer status and a single line of text. In practice, that line of text can contain whatever the administrator desires. I want an indication of the health of the mail queues on a number of mail servers we have inhouse. The line of text therefore contains two-letter codes with which I can identify the hostname of the mail server in question as well as a count of mails on the queue for each of the servers in question.
The program that produces that line of text also returns a numeric integer indicating okay, warning or critical so that the extension can colour-code the status bar accordingly. A sample XML read by the extension.
<code>0</code>
<text>nprocs: 111</text>
</whatmon>
Download this code: whatmon/whatmon-simple.xml
I've tried to keep this as simple as possible so as to not overcomplicate the extension proper (and because creating Mozilla extensions is about the worst I've ever had to do
). Each of the labels and values on the status bar could have been individually described in the extension, but then it would require modification whenever something changes. I didn't want that to happen.
The extension requires two preferences to be set. I've named these whatmon.url and whatmon.refresh. They are the URL from which the XML is to be read and the frequency in seconds in which the extension should do a GET request from the URL.
Both preferences are installed as defaults when whatmon is first installed, but you'll want to change these to reasonable values, using the configuration editor in Firefox or Thunderbird. To call up the preference settings in Firefox, go to the URL about:config. In Thunderbird choose Tools => Options => Advanced => General => Config Editor. The preferences for whatmon should then resemble this:

After restarting Firefox or Thunderbird, whatmon will then periodically perform a GET request on the URL set in the whatmon.url preference.

The actual monitoring program is part of your web server, and it can be written in any language supported by it. It must return a tiny bit of XML text specifying both a status code and a string that whatmon will print to the status bar of Firefox or Thunderbird.
This simple example is a shell script which displays the number of currently running processes on the server.
nprocs=`ps ax|wc -l | awk '{print $1}'`
text="nprocs: $nprocs"
code=0 # normal
if [ $nprocs -gt 115 ]; then
code=1 # warning
fi
if [ $nprocs -gt 120 ]; then
code=2 # critical
fi
cat <<ENDXML
Content-type: text/xml
<whatmon>
<code>${code}</code>
<text>${text}</text>
</whatmon>
ENDXML
Download this code: whatmon/simple.sh
Stocks
Another more involved example is shown below. It uses whatmon as a front-end to Yahoo!'s stock symbol lookup.
# whatmon-stock.php by Jan-Piet Mens <jpmens at gmail dot com>
# Simple stock watcher for whatmon (http://fupps.com/extensions/).
# The URL to this will be specified as
# http://www.example.com/stock.php?s=SYMB where SYMB is the stock symbol
# as listed by Yahoo!'s site.
header("Content-type: text/xml");
$symbol = $_GET['s'];
if (!isset($symbol)) {
$symbol = 'GOOG';
}
$url = "http://quote.yahoo.com/d/quotes.csv?f=sl1d1t1c1ohgv&e=.csv&s=";
print "<whatmon>";
if ($fp = @fopen($url . "$symbol", "r")) {
# "GOOG",401.32,"10/3/2006","1:16pm",-0.12,401.29,402.97,398.19,2729528
$list = fgetcsv($fp, 256);
# Note that you could add an alerting (code=1 or code=2) in case
# a stock is lower or higher than you desire...
print "<code>0</code><text>${list[0]}: ${list[1]}</text>";
fclose($fp);
} else {
print "<code>2</code><text>Can't get stock</text>";
}
print "</whatmon>";
?>
Download this code: whatmon/whatmon-stock.php
Note the comments.
Detailed Alerting
Heiko Weber sent in a very useful patch to whatmon. If the XML received by whatmon contains an element named msgurl, whatmon will launch a new browser window to open the URL.
<code>2</code>
<text>nprocs: 231</text>
<msgurl>http://example.com/detailed-info.cgi</msgurl>
<xhover>Tooltip text</xhover>
</whatmon>
Download this code: whatmon/whatmon-msgurl.xml
When whatmon sees a msgurl element in the XML, it will open a new browser window pointing to the specified URL. Note that this URL can of course differ from code to code: simply ensure your CGI produces a different URL.
Changelog
- 09-Aug-2006 1.6.0
- incorporates heiko weber's patch for alert windows
- 27-Sep-2006 2.0.0
- incorporates ian stirling: patch to support file:// URLs, support for Firefox 2.0 RC1, defaults are set upon installation, changed logo
- 27-Sep-2006 2.0.1
- reverted to original GUID, minor code cleanups
- 30-Sep-2006 2.0.2
- added preference observer; If no XML data returned by CGI, the issue diagnostic on status bar
- 15-Oct-2006 2.0.3
- As per suggestion by Petr, a click on whatmon's status bar forces an immediate refresh
- 07-Mar-2007 2.0.4
- Differing icons depending on level (suggested by "Frangi")
- 21-Nov-2007 2.0.5
-
- install.rdf: support for Thunderbird 2.0 (LewS)
- install.rdf: support for Firefox 3.0 (JPM)
- click on whatmon does not add a new timer (Scott Carpenter)
- whatmon.css: max-width: auto (Scott Carpenter)
- 04-Dec-2007 2.0.6
-
- Hover over whatmon status bar shows content of XML's `xhover' element (suggested by Jeremy Vanderb)
- 19-Apr-2008 3.0.0
-
- Show whatmon status as "Loading…" (w/ tooltip containing time) when XMLHTTP request is launched; allows user to detect unresponsive servers. [idea and code by "bitbyte"]
- Many thanks to Sebastian A. who had excellent ideas, most of which had unfortunately already been implemented.
- 21-Apr-2008 3.0.1
-
- Forgot to try/catch xhover element from XML; this results in whatmon printing "Loading…" and nothing else. Update to 3.0.1 or add non-empty xhover element to XML. Bug spotted by Scott Crevier.
- 18-Jun-2008 3.0.4
-
- Options dialog provided by Gábor Lipták (thanks!)
- Bumped to official Firefox 3.0
- 26-Jul-2009 3.1.0
-
- Bumped to official Firefox 3.5.*
Download
Download whatmon from the Mozilla Add-ons site, or grab a local copy.
Improve?
Can this be improved on? You bet! Firefox and/or Thunderbird need restarting whenever the URL preference changes. A nice options dialog with which the extension's preferences can be set would be welcome. Instead of plain text on the labels, I'd have liked to display images generated by the web server which change as the status changes. Any takers?

Still have the issue with 3.6. Just locks up the add-on window and you have to kill FF. What is odd is my home computer, which is configured nearly identically (XP pro) works fine. I initially installed whatmon with FF 3.1 I think. I dont think it was 3.5 but I don't remember exactly. Then I recently (finally) updated to 3.6 and it still works fine. Though I cant say I've tried to open the options dialog for whatmon. But on my work machine (XP pro FF 3.6) in addition to the lockup, the status bar doesn't even show up.
@Mike, I'm running 3.6.4 here and have no issues. Sorry, can't help there.