Ah thank you!
So entering a little bit of code to output the results helped.
I changed the script output both the wc -l and the full MegaCLI64 command output to /tmp/test.
Code: Select all
#!/bin/sh
# script to check the status of the RAID volume on a server with a Megaraid RAID card
# Get status of RAID card
COUNT=`sudo /usr/local/bin/MegaCli64 -LDInfo -Lall -aALL|grep Degraded|wc -l`
sudo /usr/local/bin/MegaCli64 -LDInfo -Lall -aALL|grep Degraded|wc -l >/tmp/test
sudo /usr/local/bin/MegaCli64 -LDInfo -Lall -aALL >>/tmp/test
if [ $COUNT -ge 1 ]
then
echo "CRITICAL: RAID Errors Present"
exit 2
elif [ $COUNT -eq 0 ]
then
echo "OK: No Errors Found"
exit 0
fi
So again I can run this custom script with the nagios user. It outputs the the correct values to /tmp/test
sh-3.2$./raid_monitoring_megaraid.sh
CRITICAL: RAID Errors Present
sh-3.2$ cat /tmp/test
1
Adapter 0 -- Virtual Drive Information:
Virtual Drive: 0 (Target Id: 0)
Name :
RAID Level : Primary-1, Secondary-0, RAID Level Qualifier-0
Size : 233.312 GB
State : Optimal
Strip Size : 64 KB
Number Of Drives : 2
Span Depth : 1
Default Cache Policy: WriteThrough, ReadAhead, Direct, No Write Cache if Bad BBU
Current Cache Policy: WriteThrough, ReadAhead, Direct, No Write Cache if Bad BBU
Access Policy : Read/Write
Disk Cache Policy : Disk's Default
Encryption Type : None
Virtual Drive: 1 (Target Id: 1)
Name :
RAID Level : Primary-1, Secondary-0, RAID Level Qualifier-0
Size : 3.637 TB
State : Degraded
Strip Size : 64 KB
Number Of Drives per span:2
Span Depth : 2
Default Cache Policy: WriteThrough, ReadAhead, Direct, No Write Cache if Bad BBU
Current Cache Policy: WriteThrough, ReadAhead, Direct, No Write Cache if Bad BBU
Access Policy : Read/Write
Disk Cache Policy : Disk's Default
Encryption Type : None
Exit Code: 0x00
Then I try to run it through the Nagios server manually using NRPE:
[root@nagios servers]# /usr/local/nagios/libexec/check_nrpe -H nas1 -c check_raid_status
OK: No Errors Found
And the output of /tmp/test:
sh-3.2$ cat /tmp/test
0
So this tells me that the script is running, but it's not displaying anything because it can't run the MegaCli64 program successfully. Which doesn't make sense. I gave sudo rights to the Nagios user on the nas, and set to ALL with NOPASSWD. Furthermore, I can run the script manually just fine using the nagios user. So I'm REALLY confused now. Any thoughts?