Page 1 of 2
Make a script to check loadbalancer with Nagios
Posted: Mon Feb 10, 2014 10:27 am
by nerdgz
Hello Everybody,
i have two server when one is active the other is in standby. So i have already two scripts in each server that tells me when the server have this status. i want to get an alert when one of this servers goes offline. But i make a script to monitoring this with Nagios and i cannot make it works.
This is the script i wrote, i'm new in this so i think there are a lot of mistakes.
Thank you in advance!
Code: Select all
# Check the status of the local and the remote lb max 3 times every 10 seconds
I=1
X=0
while [ $I -le 3 ]
do
STATE1=`/path/script.sh`
if ping -c 1 -w 3 "secondHost" > /dev/null 2>&1
then
STATE2= ssh "secondHost" /path/script.sh"`
else
STATE2="Offline"
fi
if [ "$STATE1" = "Active" -a "$STATE2" = "Standby" -o "$STATE1" = "Standby" -a "$STATE2" != "Active" ]
then
echo "One lb is active. Everything seems to be okay."
exit $STATE_OK
fi
if [ "$STATE1" = "Active" -a "$STATE2" = "Offline" -o "$STATE1" = "Offline" -a "$STATE2" = "Active" ]
then
echo "One lb is offline."
exit $STATE_CRITICAL
fi
if [ "$STATE1" = "Active" -a "$STATE2" = "Active" ]
then
echo "Both lb are active the same time!"
exit $STATE_CRITICAL
fi
if [ "$STATE1" = "Offline" -a "$STATE2" = "Offline" ]
then
echo "No lb active."
exit $STATE_CRITICAL
fi
X=1
let I=$I+1
sleep 10
done
exit $EXIT
I always get the error "NRPE: Unable to read output"
Kind regards,
NerdGZ
Re: Make a script to check loadbalancer with Nagios
Posted: Mon Feb 10, 2014 11:15 am
by abrist
You have a few variables that have not been declared, for example "$STATE_CRITICAL". Are you defining these in the environment or another script?
Re: Make a script to check loadbalancer with Nagios
Posted: Mon Feb 10, 2014 3:30 pm
by nerdgz
Hello Abrist,
the other script i have is only to take out the words of Active, Standby and Offline. How i can declare the variables?
regards
Re: Make a script to check loadbalancer with Nagios
Posted: Mon Feb 10, 2014 4:06 pm
by abrist
You probably want to set:
Near the top of the script, but I have yet to see your other script. Can you post it?
Re: Make a script to check loadbalancer with Nagios
Posted: Mon Feb 10, 2014 5:10 pm
by nerdgz
Hello,
the scritp is only this:
/usr/bin/dscontrol hi status | grep ^State | cut -c24-
Then i get the output Active, Standby and Offline.
i tried to put the variable you wrote and i get NRPE: Unable to read output
Re: Make a script to check loadbalancer with Nagios
Posted: Tue Feb 11, 2014 2:14 pm
by abrist
Are you using environment variables? Your script does not declare a number of bash variables. . .
Re: Make a script to check loadbalancer with Nagios
Posted: Mon Feb 17, 2014 3:20 am
by nerdgz
Hello Everyone,
i wrote again the script and i only have the result of the last sentence of the script "msg="CRITICAL: No lb active." . But the status of the loadbalancer is ok. Seems that Nagios only read the last part of the script. I dont know how to do...
See here the new script i wrote:
!/usr/bin/ksh
#Output : LoadBalancer TAM
################################################################################################################
STATE1=$(/path/state1)
STATE2=$(ssh secondhost /path/state2)
if [ "$STATE1" ="Active" ]; then
if [ "$STATE2" ="Standby" ]; then
msg="OK:One lb is active. Everything seems to be okay."
rc=0
elif [ "$STATE2" = "Offline" ]; then
msg="CRITICAL: One lb is offline."
rc=2
elif [ "$STATE2" = "Active" ]; then
msg="CRITICAL: Both lb are active the same time!"
rc=2
fi
elif [ "$STATE2" ="Active" ]; then
if [ "$STATE1" = "Standby" ]; then
msg="OK:One lb is active. Everything seems to be okay."
rc=0
elif [ "$STATE1" = "Offline" ]; then
msg="CRITICAL: One lb is offline."
rc=2
elif [ "$STATE1" = "Active" ]; then
msg="CRITICAL: Both lb are active the same time!"
rc=2
fi
else
msg="CRITICAL: No lb active."
rc=2
fi
echo $msg
return $rc
this script is connecting to nagios via nrpe
thanks in advance!!
Re: Make a script to check loadbalancer with Nagios
Posted: Mon Feb 17, 2014 1:15 pm
by abrist
Are the paths below binaries or text files (like /proc/x or /sys/x etc)?:
Code: Select all
STATE1=$(/path/state1)
STATE2=$(ssh secondhost /path/state2)
If they are text files, you will need to cat the file to load it into a variable:
Code: Select all
STATE1=$(cat /path/state1)
STATE2=$(ssh secondhost cat /path/state2)
If the paths are bins, then you do not need to change the commands.
If that does not work, try adding some echos to the script:
Code: Select all
STATE1=$(/path/state1)
STATE2=$(ssh secondhost /path/state2)
echo "$STATE1"
echo "$STATE2"
if [ "$STATE1" ="Active" ]; then
if [ "$STATE2" ="Standby" ]; then
msg="OK:One lb is active. Everything seems to be okay."
rc=0
elif [ "$STATE2" = "Offline" ]; then
msg="CRITICAL: One lb is offline."
rc=2
elif [ "$STATE2" = "Active" ]; then
msg="CRITICAL: Both lb are active the same time!"
rc=2
fi
elif [ "$STATE2" ="Active" ]; then
if [ "$STATE1" = "Standby" ]; then
msg="OK:One lb is active. Everything seems to be okay."
rc=0
elif [ "$STATE1" = "Offline" ]; then
msg="CRITICAL: One lb is offline."
rc=2
elif [ "$STATE1" = "Active" ]; then
msg="CRITICAL: Both lb are active the same time!"
rc=2
fi
else
msg="CRITICAL: No lb active."
rc=2
fi
echo $msg
return $rc
Re: Make a script to check loadbalancer with Nagios
Posted: Wed Feb 19, 2014 3:12 am
by nerdgz
Hello Abrist,
i had a begginner mistake, the user Nagios couldnt read the script, this is why i get errors all the time. i give rights to Nagios user for ssh with RSA key and also for all the scripts.
so the Script is working via nrpe !!
Thank you very much for your help!!
Re: Make a script to check loadbalancer with Nagios
Posted: Wed Feb 19, 2014 10:20 am
by tmcdonald
Is it safe to close this thread? Everything is working?