Water Leak Detection with Nagios: How-To

Download the Plugin

View the companion guide: build a stand for the water sensor in this article


I reviewed several water leak detection solutions for our server rooms when we needed to begin environmental monitoring. I had several criteria for selection, in order of importance:

  • How effective is the solution at detecting water leaking onto servers/floor/ceiling?
  • How much does the solution cost per square meter?
  • How easily and quickly can the solution be integrated into our existing Nagios monitoring system?

I reviewed one solution which used water-sensing tiles which would sit on top of existing ceiling tiles, and had thin, water sensing cables for deployment on a floor. This solution was absolutely the most effective out of the products I looked at. Only one huge problem – a huge price tag! If you have the money, these types of sensors will probably give you the most visibility into water leaks. The price was not right, though.

I was asked to look into lower-cost products after presenting the tiles/cables solution. It was here that I found that Watchguard, as well as several other manufacturers, made small, localized leak detectors. Being familiar with writing plugins for Watchguard, and with Watchguard’s water sensor being the cheapest in this category, I decided to go with their Watchport/W sensor.

For the plugin I decided on Python. I like Python’s serial library more than Perl’s. On Windows, Perl’s Win32::SerialPort library requires a convoluted and an, in my opinion, annoying-to-generate config file. I also had trouble with serial communication in general working with the water sensor when I began writing the plugin with Perl. Conversely, Python’s PySerial library seems to be a much more direct interface with the serial port and with C’s serial functionality, and doesn’t require a config file on Windows.

Basic Usage:

Use this plugin like any other – simply call it with its respective interpreter (Python) using either Nagios locally, or NRPE/NSCA++ on a remote server. I run this check every five minutes on each host with a water sensor attached. The switches are straightforward:

  • -p or –port allows you to specify a port, which is usually /dev/TTYUSB<portnum> on Linux, or COM<portnum> on Windows
  • -t or –timeout let you specify a timeout for the serial port read. If you are testing a lot with this plugin and expect to receive timeouts, setting this low is convenient.

An example config might be:

Windows NSCA++:
command[check_water]= C:\Python31\python.exe C:\nagios\check_watchptwater.py -p COM3
Linux NRPE:
command[check_water]=/usr/bin/python /usr/lib/nagios/plugins/check_watchptwater.py -p /dev/TTYUSB0
Nagios Server:
#This defines a check command for Nagios. Once this is defined, you can use check_water in
a service check on a host which can execute check_watchptwater.py. You should create a
hostgroup for all of the hosts in your environment with water sensors attached for easy
define command {
    command_name check_water
    command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c check_water -t 40

And there you have it! Hopefully this helps someone keep tabs on a problem A/C unit or pipe, or catch an unforeseen leak. I have several of these scattered on the floor in each of our server rooms. Please leave me some feedback if you have any suggestions or questions. Thanks for reading!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s