Whatmon is was a small Safari extension modeled after the moderately successful
extension I created for Mozilla Firefox/Thunderbird: it provides an extension
bar on which a text retrieved from a Web service you provide is displayed, together with a small green/yellow/red indicator alerting you to the fact that your Web service status is OK, in warning, or critical state.
Whatmon 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 provide a JSON file, either statically or on the fly with a CGI interface in Perl, Python, PHP, C or any other language you feel comfortable with.
Whatmon periodically retrieves a JSON text from a web server. The JSON contains an integer status and a single text string. In practice, that text string can contain whatever the administrator desires.
The program that produces that line of text also returns a numeric integer indicating okay, warning or critical so that the extension can color-code the status bar accordingly. A sample JSON read by the extension:
{
"status": 0,
"text": "Your message here"
}
A small program that produces, say, load average and user count:
#!/usr/bin/env python
import sys
import os
import json
import subprocess
loadavg = os.getloadavg()
users = -1
try:
proc = subprocess.Popen(['who | wc -l'], shell=True, stdout=subprocess.PIPE)
line = proc.communicate()[0]
users = int(line)
except (OSError, ValueError):
pass
loadstr = "load: %.2f %.2f %.2f" % loadavg
userstr = "users: %d" % users
status = 0
if loadavg[0] > 1:
status = 1
if loadavg[0] > 2:
status = 2
whatmon = { "status" : status, "text" : loadstr + ', ' + userstr }
json.dump(whatmon, sys.stdout, indent=4)
The JSON fields evaluated by whatmon are:
- status: mandatory. An integer value representing a color.
- 0 = OK: green
- 1 = WARNING: yellow.
- 2 = CRITICAL: red.
- text: mandatory. A string value containing what you want drawn on the extension bar.
- url: optional. If this is set, the text will turn into a clickable link with this url as target. Clicking on the link takes you to a page you provide with, say, additional information on the status of whatever you are monitoring.
- tooltip: optional. A string containing a title for the link produced by url. If url is not specified, there is no point in adding tooltip.
{
"status": 0,
"text": "Your message here",
"url" : "http://example.com/nagios",
"tooltip" : "Houston, there's a problem here..."
}
Installation
Open the Whatmon-s Safari extension after downloading it and confirm you want to install it. Whatmon will then look like this:
Go to Safari’s settings and set the URL for your Web service as well as the refresh rate in seconds – every seconds whatmon will attempt to retrieve JSON from the specified URL. If you set seconds to something that evaluates to less than 20, the extension uses 20 seconds.
Web service
You then have to set up a Web service to provide Whatmon with the required JSON file. How you do this in detail is beyond scope of this article, but here are some ideas to get you started.
- If you don’t want to create a CGI-like script for your Web server, periodically run a shell script or other program (e.g. the Python program above) to produce a static JSON file your Web server delivers to whatmon.
- Use some sort of CGI mechanism (Perl, PHP, etc.) to produce the required JSON string on the fly.
Change log
- 29-Jun-2011 version 1.3
- Initial public version
Download
Whatmon for Safari is available here, and it’s source code is here.