Nagios (or its recent fork Icinga) implement an Open Source network
and application monitoring system. I use Nagios extensively, and I wanted to
build an Arduino monitor for it – a little gadget that sits next to my
screen, where I can glance at it quickly to see if everything is running.
As you’ll see below, this project doesn’t require a particular network or
service monitoring system; you should be able to easily adapt the code to
display whatever you want onto the LCD.
The S65 shield is designed and sold by Watterott in Germany. It has a
backlit 176x132 pixel LCD display, a microSD socket, and a rotary
encoder. (The small yellow tag on the top left is to peel off the
protective covering of the LCD; I still have it on here.) Code and schematics
for the S65 shield are here.
These photographs show the Arduino, and the Ethernet and S65 shields from left
to right, respectively (stacked upon eachother) from bottom to top.
After stacking the two shields onto my Arduino, I’m ready to rumble. As I
said: no soldering. :-)
My little Naguino monitor is fed Nagios events over HTTP POST messages.
These include a state which indicates whether a particular service is OK, has
a WARNING or is CRITICAL, as well as a 21 character message that shows up on
the Naguino display. The messages are colour-coded: green is OK, yellow is
Warning, and red means Critical.
Messages are displayed on the bottom of the LCD and “scroll up” automatically,
as soon the display is full. If you want to, you can use the rotary encoder to
page up and down by turning the encoder left or right respectively. (I’m doing
that in the photo above.) The time on the LCD title bar is obtained during the
HTTP POST to the Naguino – it is the time of the last message.
Processing HTTP on the Arduino
The Arduino Ethernet shield can be a Web (or any other TCP) server, and
there exist examples for doing so, e.g. here. The best I found however,
is Ben Combee’s webduino, an extensible Web server library. Its
documentation is a bit scarce, but Ben gives us four very useful and
well-commented examples with which to start off. Highly recommendable, and
that is what Naguino uses to process Nagios alerts. So, without further ado,
here is the Naguino sketch:
Download the sketch for Naguino and upload that to the Arduino, after
ensuring you’ve changed the IP address (the values in the ip array) to
match your network. When Naguino initializes, it will print its IP address
to the LCD.
You can easily test it by sending it a simple message with cURL:
which should print the string “hello world” in green letters on the last line
of the LCD.
So, I configured a global service event handler in my nagios.cfg. This is
invoked whenever a service state changes. (Note: I’m interested in service
events only, but the process is similar for host events.)
I then described nagev command in the appropriate commands resource; in my
setup commands are in commands.cfg:
My service event handler command nagev is quite simple: whenever it detects
a HARD Nagios transition, it extracts the service state (OK, WARNING, …),
the name of the host on which the service is running, the service name itself
and POSTs that via HTTP to the Arduino Ethernet shield.
Nagios passes the macros we need to determine service and
hostnames, states, etc. into the Perl program as environment variables, making
it easy to retrieve the information we need. Note how I am formatting the
message in such a way as that the host and service names get a maximum width.
(Note that this will work fine for smallish Nagios installations, but on very
large ones with hundreds of event notifications, the nagev program can
become a bottleneck, because the Arduino Ethernet shield allows only one
simultaneous connection to its TCP server stack, causing parallel requests to
block until the “Web server” is available. (This is not a limitation of
webduino but of the TCP code in the Ethernet.h library.) If you want to
cater for large installations, I’d recommend serializing events into a file or
database of some sort, having a separate standalone program feed those
serialized events to Naguino.)
GETting something back
If you access Naguino with a HTTP GET request (e.g. by simply pointing a Web
browser to it), Naguino will show you the list of messages it has in it –
typically more than what you see on the LCD of the S65 shield. The “height” of
the internal Naguino list is controlled by the definition of MLISTSIZE in
The Naguino is extremely easy to assemble and works rather well. Some ideas
Add a small piezo buzzer that sounds a tone (high-low) when a critical message is posted, and another (low-high) when the all-clear arrives.
Do something clever with the push-button on the rotary encoder: maybe change colours, reset Naguino, “ping” Nagios host, get/display alternate information on LCD.
Use the “long push” on the button to store state on a microSD card on the S65 shield, and reload that state when Arduino powers up.
If you have any other ideas, I’d be delighted to here them.
What I now still have to do is to build a nice enclosure for Naguino (sigh).