Question on creating a passive check

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
a31modela
Posts: 18
Joined: Thu Jun 24, 2010 12:40 pm

Question on creating a passive check

Post by a31modela »

Hello All,

I am having an issue creating my 1st passive check for Nagios Core and can't figure out the disconnect. I am running a distributed environment with Linux and have a need to check space on a partition from a legacy server.

if I run the test manually from the command line on the remote distributed server, I get the expected response :
nagios@str7924sa:/usr/local/nagios/libexec> ./check_starlite_size str7924 70 90
[1287604790] PROCESS_SERVICE_CHECK_RESULT;str7924;2;Critical. Free Space: 2 % available

On my central server, in nagios.log I am getting the following :
PASSIVE SERVICE CHECK: str7924sa;Starlite Size;3;(null)

Now, I do not have the legacy server ( str7924 ) listed as a host in the hosts.cfg file as I didn't think I had to.

Tried running the script with the echo command redirected to the nagios.cmd file and without with no success.

Can anyone tell me what I am missing here? Our environment will need to use alot of passive checks from existing 3rd party scripts.

libexec script

Code: Select all

#!/bin/bash
#
# Plugin to check free disk space for starlite
# using rsh
#
# Command-Line for service (example)
#
##########################################################

CLOCK=`date +%s`
HOST=$1



case $1 in
  --help | -h )
         echo "Usage: check_starlite_size [dev] [warn] [crit]"
         echo " [warn] and [crit] as int"
         echo " Example: check_starlite_size str7924 70 90"
         exit 3
         ;;
  * )
    ;;
esac


if [ ! "$1" -o ! "$2" -o ! "$3" ]; then
        echo "Usage: check_diskfree [dev] [warn] [crit]"
        echo " [warn] and [crit] as int"
        echo " Example: check_diskfree hda1 70 90"
        echo "Unknown: Options missing"
        exit 3
fi

used=`sudo /usr/bin/rsh $1 df -v |grep /starlite6 | head -1 | awk '{print $4}'`
free=`sudo /usr/bin/rsh $1 df -v |grep /starlite6 | head -1 | awk '{print $5}'`
full=`echo $(($used+$free))`
percent=`echo $((( $free * 100 ) / $full))`
warn=`echo $((( $full * $2 ) / 100 ))`
crit=`echo $((( $full * $3 ) / 100 ))`

if [ "$warn" -gt "$crit" -o "$warn" -eq "$crit" ]; then
  echo "Unknown: [crit] must be larger than [warn]"
      exit 3
fi

if [ "$used" -lt "$warn" -o "$used" -eq "$warn" ]; then
      OUTPUT="OK. Free Space: $percent % available"
     STATUS= 0

elif [ "$used" -gt "$warn" -a "$used" -lt "$crit" ]; then
     OUTPUT="Warning. Free Space: $percent % available"
   STATUS=1

elif [ "$used" -gt "$crit" ]; then
    OUTPUT="Critical. Free Space: $percent % available"
   STATUS=2
else
 OUTPUT="Unknown"
exit 3
fi

echo "[$CLOCK] PROCESS_SERVICE_CHECK_RESULT;$HOST;$STATUS;$OUTPUT"

#> /usr/local/nagios/var/rw/nagios.cmd
services.cfg & command.cfg pieces

Code: Select all

define service{
       use                             generic-service
       host_name                        str7924sa
#       hostgroup_name                  Store_servers
       notification_options            w,c
       service_description             Starlite Size
       check_command                   check_starlite_size!str7924!70!90
}

define command {

        command_name    check_starlite_size

        command_line    $USER1$/check_starlite_size -H $HOSTNAME$  -w $ARG1$ -c $ARG2$

}
Thanks very much,
Steve
tonyyarusso
Posts: 1128
Joined: Wed Mar 03, 2010 12:38 pm
Location: St. Paul, MN, USA
Contact:

Re: Question on creating a passive check

Post by tonyyarusso »

You do need to have both the host and service defined in Nagios, and include that information in the send_nsca arguments. If a definition is not found, the check result will be received and then just discarded into the ether.
Tony Yarusso
Technical Services
___
TIES
Web: http://ties.k12.mn.us/
a31modela
Posts: 18
Joined: Thu Jun 24, 2010 12:40 pm

Re: Question on creating a passive check

Post by a31modela »

Thanks very much for the info. I did managed to finally get a check created for the issue.
Now moving forward, we have a number of checks that we currently do and send them to Tivoli for managing. What they currently do is in their scripts they have a line of code send_alert

Code: Select all

send_alert Y 1 $DB_NAME "`basename $0` Schema <> control file?"
which runs a ksh script that sends the following to Tivoli

Code: Select all

/usr/tecad/bin/postemsg -S tivoli1 -r CRITICAL -m "Alert=1 2010 10 23 01:00 AM db=db1 msg=restore_app.ksh Error in restoring database" hostname=0262sa ticket=YES page=NO UDB_Store_XXXXXX_1 STORE
By using a passive check from a db2 script, I would send the script results as noted above to the nagios.cmd file on the distributed server, once there, Nagios moves it to the Central server. Now what I don't get, there still has to be some kind of nagios check to know what to do with the info sent up correct?? Is this just as simple as creating a check in the services & commands files on the central server ?

Not seeing how to facilitate Nagios's ability to process results from a 3rd party script.

Thanks again for your help,
Steve
tonyyarusso
Posts: 1128
Joined: Wed Mar 03, 2010 12:38 pm
Location: St. Paul, MN, USA
Contact:

Re: Question on creating a passive check

Post by tonyyarusso »

No, there's no extra check. There's send_nsca, which dictates a very precise pattern for how the data should be passed, which includes things like the service state that tell Nagios how to treat the result.
Tony Yarusso
Technical Services
___
TIES
Web: http://ties.k12.mn.us/
a31modela
Posts: 18
Joined: Thu Jun 24, 2010 12:40 pm

Re: Question on creating a passive check

Post by a31modela »

Tony,

Thanks for the follow up... It appears my issue was I forgot about using send_nsca.... I have a distributed set up and the central server is doing no checks. My distributed server is doing all checks to his hosts by check_by_ssh. ( remote local site) Since I have successfully set up the distributed servers, I assumed that the send_nsca was there & running as well.

Just for my own knowledge ( and anyone else reading thru this) the nagios checks running on my remote distributed server are running thru the nagios.cmd file. This is based upon the settings in my nagios.cfg file for external commands. The send_nsca is sending an encrypted statement directly from the distributed server to the central server. The 2 pieces ( send_nsca & the checks going via nagios.cmd ) are 2 different methods of getting results back. Is oversimplified statement correct?

I apologize for my lack of understanding of this but chances are I spent too much time reading too much stuff.

Thanks again for your help,
Steve
tonyyarusso
Posts: 1128
Joined: Wed Mar 03, 2010 12:38 pm
Location: St. Paul, MN, USA
Contact:

Re: Question on creating a passive check

Post by tonyyarusso »

Correct enough anyway. Ultimately everything goes the same place I think, but through different channels along the way.
Tony Yarusso
Technical Services
___
TIES
Web: http://ties.k12.mn.us/
Locked