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.
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!
# 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"
You have a few variables that have not been declared, for example "$STATE_CRITICAL". Are you defining these in the environment or another script?
Former Nagios employee
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
Near the top of the script, but I have yet to see your other script. Can you post it?
Former Nagios employee
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
Are you using environment variables? Your script does not declare a number of bash variables. . .
Former Nagios employee
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
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
################################################################################################################
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
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
Former Nagios employee
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
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.