Monday, 6 October 2014

Shell Script : How To Write Nrpe plugin

Nrpe plugin to check process state of a service

Here I'm showing you guys how we can make a nrpe plugin using shell script .

This plugin checks if  'haproxy' service running in process state (ps).

Code : 

#!/bin/bash

##### Defining states 

STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3

#### Checking the service name in process state

ps aux| grep -w haproxy | grep -v "grep"


##### Checking the exit status of above command

if [ $? -eq 0 ]
        then
        echo "OK - haproxy process Running"
                exit $STATE_OK

elif [ $? -eq 1 ]
        then
        echo "CRITICAL - haproxy process NOT running"
                        exit $STATE_CRITICAL

else

        echo "UNKNOWN - Information Not Available"
                                exit $STATE_UNKNOWN

fi

###########
Note : Please don't use exact 'haproxy' word as a script name :P 
Thanks :)

No comments:

Post a Comment