Page 1 of 1

Bash Shell Scripting Help Needed - IPMI Monitoring

Posted: Fri May 18, 2012 11:46 pm
by cau.odesk
I have Nagios 3.3.1 installed on CentOS 5.8. I'm trying to make a shell script to use the ipmimonitoring function of freeipmi to gather Temperatures from Sun ILOM.

My script is written as below:

[root@localhost libexec]# vi ipmimonitoring.sh
#!/bin/bash

TempFile=$(mktemp)

STATUS=$(/usr/local/sbin/ipmimonitoring -u test -p test -l user -h $1 -W endianseq | grep "mb.t_amb")
echo $STATUS > TempFile

Check=$(grep "OK" TempFile)

if [ "$Check" != "" ];
then
ECHOOK="Temperature OK, Result: $STATUS"
echo $ECHOOK
exit 0

else
echo "WARNING: Temperature NOT OK, Result: $STATUS"
exit 1
fi

rm -f $TempFile

When I execute it in the command line, it works fine:
[root@localhost libexec]# ./ipmimonitoring.sh 10.20.60.12
Temperature OK, Result: 4608 | mb.t_amb | Temperature | Nominal | 28.00 | C | 'OK'


But when I execute it in Nagios, it always goes to the else condition even if it is picking up the Temperature:

define command {
command_name ipmimonitoring
command_line $USER1$/ipmimonitoring.sh $HOSTADDRESS$ }


Nagios Webpage Output is:
Current Status: WARNING for 0d 0h 56m 23s)
Status Information: WARNING: Temperature NOT OK, Result: 4608
Performance Data: mb.t_amb | Temperature | Nominal | 28.00 | C | 'OK'
Current Attempt: 3/3 (HARD state)
Last Check Time: 05-19-2012 00:36:08
Check Type: ACTIVE


I have done pre-flight check and service nagios restart but the problem keeps recurring.

Please advise if I'm doing something wrong. Thanks in advance for any help.

Re: Bash Shell Scripting Help Needed - IPMI Monitoring

Posted: Mon May 21, 2012 9:35 am
by agriffin
I don't have ipmimonitoring to test against, but I cleaned up your script a bit and fixed some bugs you had with quoting and writing to a file literally named TempFile (rather than the variable $TempFile). Also, pipe characters in plugin output are treated special by Nagios, and should be avoided unless you are providing performance data for graphing. See if those changes help.

Code: Select all

#!/bin/bash

TempFile=$(mktemp)

STATUS=$(/usr/local/sbin/ipmimonitoring -u test -p test -l user -h "$1" -W endianseq | grep "mb.t_amb" | sed 's/|/-/g')
echo "$STATUS" > "$TempFile"

if grep "OK" "$TempFile"; then
	echo "Temperature OK, Result: $STATUS"
	exit 0
else
	echo "WARNING: Temperature NOT OK, Result: $STATUS"
	exit 1
fi

rm -f "$TempFile"
When you test your plugins, you should be running them as the Nagios user to make sure there are no permission issues. For example:

Code: Select all

su nagios -s /bin/bash -c "./ipmimonitoring.sh 10.20.60.12"

Re: Bash Shell Scripting Help Needed - IPMI Monitoring

Posted: Mon May 21, 2012 10:06 am
by cau.odesk
Thanks for your quick reply and for helping to fix my poor scripting.

The script works. Turns out that nagios as a user doesn't have permissions to access TempFile while root had it.

Thanks a lot again.

Re: Bash Shell Scripting Help Needed - IPMI Monitoring

Posted: Mon May 21, 2012 11:17 am
by agriffin
You're welcome!