Plugin for Nagios in Bash

(0 comments)

Today we make simple plugin in Bash

We need to know that Nagios’ plugins should return code:

Exit Code Status
0 OK
1 WARNING
2 CRITICAL
3 UNKNOWN

For example, we need count of number something process in Linux

 #ps ax |grep collector | wc -l
33

we have 33 processes of ‘collector’ , we assume that is correct number of processes and if this value not much then plugin should return CRITICAL code

#!/bin/bash

#do work#######
COUNT=`ps ax |grep collector | grep -v grep |grep -v check_collector| wc -l`
CNTSHOULDBE=$1
if
    [ $COUNT -eq $CNTSHOULDBE ] ; then
        echo "OK - $COUNT connections, should be $CNTSHOULDBE "
        exit 0

elif
   [ $COUNT -lt $CNTSHOULDBE ] ; then
        echo "CRITICAL - $COUNT connections should be $CNTSHOULDBE "
        exit 2

elif
   [ $COUNT -ge $CNTSHOULDBE ] ; then
        echo "CRITICAL - $COUNT connections should be $CNTSHOULDBE "
        exit 2

else
        echo "UNKNOWN - $COUNT connections"
        exit 3
fi


argument for this plugin will be some number

save this code in

/usr/local/nagios/libexec

And make executable

chmod +x check_collector

We are ready to test

Adding plugins in NRPE

Add plugin in NRPE config file with argument for example

command[check_collector]=/usr/local/nagios/libexec/check_collector 33

33 -  in this case correct value for our system.

restart nrpe:

#killall nrpe

#/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d

go to the nagios host to set up for this plugin.

Add in config file :

define service{
       use generic-service ; Name of service template to use
       host_name rec-1
       service_description Check Collector
       check_command check_nrpe!check_collector
}

restart nagios:

#server nagios restart

in WEB interface nagios we should see:

check_collector

Setup plugin for Nagios done.

Currently unrated

Comments

There are currently no comments

New Comment

required

required (not published)

optional

required