Monday, October 24, 2011

Nagios Customize Script

Since Nagios is only using check_nrpe to call / execute the shell script. We can use this command to execute our own write shell script.
Below is the example of script to check the public IP and give output to nagios
-------------------------------------------------------------------------------

#!/bin/sh

IP=`curl -s ifconfig.me`
LEASE=202.147.38.202 

if [ $IP == $LEASE ]; then

        echo $IP
        exit 0

else
        echo $IP
        exit 2

fi

-------------------------------------------------------------------------------

According to nagios, it use exit code to determine the output to give what kind of response.
so below is the exit code


State OK = 0
State Warning = 1
State Critical = 2
State unknown = 3
State Dependent = 4

----------------------------------------------------------

Now we will add this script to the client side and define the command to nagios

We will need to edit nrpe.cfg file and add this into it

command[check_lease]=/etc/nagios/check_lease

this command will allow nagios server to call this command
----------------------------------------------------------

Then we need to define this command at client side for the path of the script to execute at commands.cfg

define command{
     command_name    check_lease
     command_line    /bin/bash /etc/nagios/check_lease
     }

This will state check_lease is refer to which shell script
----------------------------------------------------------

The last part is add the check command to the server side


define service{
      use                             local-service
      host_name                       my-proxy
      service_description             lease
      check_command                   check_nrpe!check_lease
  }

No comments:

Post a Comment