LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-10-2014, 08:44 AM   #1
NerdGZ
LQ Newbie
 
Registered: Feb 2014
Posts: 12

Rep: Reputation: Disabled
Make a script to check loadbalancer with Nagios


Hello Everybody,

i have two server when one is active the other is in standby. So i have already two script 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" = "Active" -a "$STATE2" = "Active" ]
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
 
Old 02-10-2014, 04:39 PM   #2
twantrd
Senior Member
 
Registered: Nov 2002
Location: CA
Distribution: redhat 7.3
Posts: 1,440

Rep: Reputation: 52
How are you defining this check in commands.cfg? Looks like it's configured to use NRPE, which it shouldn't, and that's why you're getting that error message.
 
Old 02-10-2014, 04:58 PM   #3
NerdGZ
LQ Newbie
 
Registered: Feb 2014
Posts: 12

Original Poster
Rep: Reputation: Disabled
Hello,

yes, i configured this to use nrpe. this check is on the server because i'm using another command to get the words Active, Standby and Offline.

the script is this:

/usr/bin/dscontrol hi status | grep ^State | cut -c24-

I think my problem is because i'm missing some variables. regarding $STATE_CRITICAL and $STATE_OK
 
Old 02-10-2014, 11:32 PM   #4
SAbhi
Member
 
Registered: Aug 2009
Location: Bangaluru, India
Distribution: CentOS 6.5, SuSE SLED/ SLES 10.2 SP2 /11.2, Fedora 11/16
Posts: 664

Rep: Reputation: 81
Also there a lot use of "if" , its better if you use nested if in place of different instances.
Secondaly using nrpe here isnt advisable, i guess its being used inside dscontrol!!

you can check the availability of nodes with nmap command and directly echo the status for a successful output.
 
Old 02-17-2014, 02:22 AM   #5
NerdGZ
LQ Newbie
 
Registered: Feb 2014
Posts: 12

Original Poster
Rep: Reputation: Disabled
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!!
 
Old 02-19-2014, 02:15 AM   #6
NerdGZ
LQ Newbie
 
Registered: Feb 2014
Posts: 12

Original Poster
Rep: Reputation: Disabled
The Script works. I need to give Nagios rights to the script. Beginner mistake
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Trying to make a script in Nagios brownie_cookie Linux - Newbie 12 03-29-2011 07:29 AM
[SOLVED] problem with 6.9glibc make -k check 2>&1 | tee glibc-check-log bhismnarayan Linux From Scratch 3 10-01-2010 08:51 AM
problem with 6.9glibc make -k check 2>&1 | tee glibc-check-log bhismnarayan Linux From Scratch 1 09-30-2010 03:04 PM
How can I make my script check to see if a file is empty? spiffytech Linux - Software 6 01-01-2006 09:35 AM
gcc-3.3.1 make -k check - make [check] Error 2 BarryM45 Linux From Scratch 1 02-05-2004 08:44 AM


All times are GMT -5. The time now is 05:15 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration