NRPE output issue
I have the script below running on a remote server. When its run command line, the correct output returns, which is 5. But when executed with nrpe from the Nagios server, it always returns 0. Im guessing the line with the wc -l is not interpreting with NRPE. What am i missing?
This is to tell how many drives are avail BTW. #!/bin/sh # STATE_OK=0 STATE_CRITICAL=2 STATE_WARNING=1 y=`/usr/openv/volmgr/bin/vmoprcmd -d ds | grep "TLD " | awk '{print $3}' | wc -l` if [ $y == 0 ] then echo "CRITICAL: $y drives availible" exit $STATE_CRITICAL fi echo "OK: $y drives avail" exit $STATE_OK ~ |
Try this instead;
#! /bin/sh # STATE=$(/usr/openv/volmgr/bin/vmoprcmd -d ds|/bin/grep "TLD "|/bin/awk '{print $3}'|wc -l) STATE_OK=0 STATE_CRITICAL=2 STATE_WARNING=1 if [ ${STATE} -eq 0 ]; then print "CRITICAL: ${STATE} drives availible" exit $STATE_CRITICAL else print "OK: ${STATE} drives avail" exit ${STATE_OK} fi Note that you want to use the full path to the binaries in a script like this (esp. if it runs as root) Also "print" (rather than "echo") *should* be a built-in shell function (rather than something in /bin or /usr/bin, YMMV). EDIT: added the missing "| wc -l" |
A little feedback...I like that you changed "y" to something more descriptive,
however I think "NUMBER_OF_DRIVES" is a better descriptor than "STATE" in this case. Also, running "type print" shows that it's not a built in shell function for /bin/sh. Try xeleema's method with a couple of updates: Code:
#! /bin/sh |
carltm,
Nice tweaks! Thanks! :) Sorry about the print versus echo non-sense. I was sitting in ksh and not Bourne sh when I checked. investmentbnker75, It's been a while since I've messed with NRPE. Does it have to be a Bourne shell script? Would it take a full-blown bash script? (quite a few built-ins, there). |
Yes, it could be any kind of script or program that sends output
and has an exit status. Although it would work with bash, I recommend using sh, since that is more portable. Anything written in sh will run in bash, but not the other way around. |
Sure anything but perl or ksh :) Thanks for the help guys ill try out the suggestions and post back right away, as i need to resolve this issue.
|
Heres what the output is showing:
[root@stand.edu] ./test ./test: line 8: [: too many arguments OK: TLD TLD drives avail Its not telling me the number of drives avail, just TLD. The output should read OK: 5 drives avail, or Critical: 0 drives avail when run. Thanks, |
I just edited the code above. We missed the "|/usr/bin/wc -l" part.
|
Uggg! still same issue. Command line, it works on the remote server. It returns: OK: 5 drives avail.
But when run through nrpe on the monitoring server, it returns critical: 0 drives avail. It cant read the actual number that is being returned for some reason. everything looks good, so i am stumped! Has to be something to do with the line: NUMBER_OF_DRIVES=$(/usr/openv/volmgr/bin/vmoprcmd -d ds|/bin/grep "TLD "|/bin/awk '{print $3}'|/usr/bin/wc -l) A different version of this script i found at the link below, which has the same issue. I feel if i am able to return the number of avail drives another way maybe that will resolve the issue? http://exchange.nagios.org/directory...Drives/details Thanks for the help guys! Hopefully this can be solved. |
Anyone? Anyone? Bueller? Bueller?
|
I'm setting up Nagios right now so I can mess with this and try to figure it out, too.
Gimme a few hours (course, at this rate, I might need a whole day or two) |
Thanks for doing spending the time to help with this xeleema, let me know if you need help with the setup.
|
Okay, here's what I've learned so far;
I've had to pull up the Veritas Netbackup Commands guide for version 6.5 (in PDF format) in order to find out if there's a syntax problem with your 'vmoprcmd -d -ds' command. However, I'm pretty sure you need a few more environment variables setup in order for Netbackup commands to work just right. So I have a few more questions for you; 1) You're NPRE setup is using it's own account, or 'root'? 2) What account does all of your Netbackup stuff usually run under? (I know most people setup a separate account so they can do privlege separation) 3) If you have a diff account for your Netbackup stuff, what's the default shell & environment setup like? Anything in it's ~/.profile or ~/.kshrc or ~/.bashrc or ~/.bash_profile that could be specific to it? 4) When you run the "/usr/openv/volmgr/bin/vmoprcmd" command (and it works), what account are you? You might have to run "env" within that account, then "su -" to the NPRE account and do an "env" there, then compare the results. Something is just not clicking with this. I've got a similar thing setup, and it's working (however, every account has the same global profile on my boxen). |
Quote:
|
Thanks for the suggestion quanta, but grep -c wont work in this situation.
|
All times are GMT -5. The time now is 07:06 PM. |