0

Script is at Server:

#!/bin/bash


if [ ! $# == 1 ]; then
echo "Usage check_cluster "
fi;
clu_srv=$1
error="stopped"
error1="disabled"
error2="recoverable"
host1=`sudo /usr/sbin/clustat|grep $1| awk {'print $2'}`
host2=`sudo /usr/sbin/clustat|grep $1| awk {'print $3'}`
service1=`sudo /usr/sbin/clustat|grep $clu_srv| awk {'print $1'}`
if [[ "$host2" == "$error" ]] || [[ "$host2" == "$error1" ]]; then
echo "CRITICAL - Cluster $clu_srv service failover on $host1 and state is '$host2'"
else
echo "OK - Cluster  $clu_srv service is on $host1 and state is '$host2'"
fi;

##--EndScript


It receives thee argument from script correctly. When I running this script manually at Server from command line it returns correct information, for example:

# /usr/local/nagios/libexec/check_rhcs-ERS NFSService
OK - Cluster  NFSService service is on NODE1 and state is 'started'

But when I tried with the script (check_nrpe) remotely with following command its showing incorrect information:

# ./check_nrpe -H localhost -c check_rhcs-ERS
OK - Cluster  NFSService service is on  and state is ''

nrpe.cfg:

# command[check_rhcs-ERS]=/usr/local/nagios/libexec/check_rhcs-ERS  NFSService

What is Wrong with the script, How to fix it?

Gaurav
  • 3

2 Answers2

1

Your NRPE user most likely doesn't have permissions to run commands with sudo access.

To allow this, you can add the line below to your /etc/sudoers file using visudo. You can also omit the NFSService part if you don't want to restrict that part.

nrpe ALL=(ALL) NOPASSWD: /usr/sbin/clustat NFSService

That said, your script does need improving. It also only takes one parameter, not three - the $2 and $3 variables are awk arguments, not bash parameters.

My partially-edited version is below:

#!/bin/bash


if [ $# -ne 1 ]; then
  echo "Usage check_cluster " >&2
  exit 1
fi

clu_srv=$1

error="stopped"
error1="disabled"
error2="recoverable"

host1=$(sudo /usr/sbin/clustat | grep "${clu_srv}" | awk '{ print $2 }')
host2=$(sudo /usr/sbin/clustat | grep "${clu_srv}" | awk '{ print $3 }')
service1=$(sudo /usr/sbin/clustat | grep "${clu_srv}" | awk '{ print $1}')

The error-handling part of your script needs clarifying - what conditions do you want to catch? Your OK output gives the status for host2, but says that the service is on host1.

Craig Watson
  • 9,790
1

If you have configured sudo correctly its probably a problem with Requiretty, you should tell sudo not to require for nrpe.

See sudoers: how to disable requiretty per user