Template for Generic Nagios Plugin

I love nagios it’s the perfect way to monitor linux.  Monitoring command can be written in almost any language: nagios expects a exit code and a exit string and it works.   I write most of my plugins in bash shell.  Here is a generic plugin template:

#!/bin/bash

# Sanity check
if [ $# -ne 2 ]; then
        echo "Usage: $0 commandline1 commandline2"
        exit
fi



COMMAND=`command_here`
E_SUCCESS="0"
E_WARNING="1"
E_CRITICAL="2"
E_UNKNOWN="3"


if grep -q "succeeded!" <<< $COMMAND; then
        echo "OK - $1 $2 working"
        exit ${E_SUCCESS}
        else
        echo "CRITICAL - $1 $2 not working"
        exit ${E_CRITICAL}
fi

One Reply to “Template for Generic Nagios Plugin”

  1. many thanks, this helped me a lot.

    there is no need to do more documentation on how to write a nagios “plugin”.

    just one hint: the user used on execution is “nagios”, not “root”.

Leave a Reply to Matthias Geörg Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.