simple chech using snmp

Andreas Ericsson ae at op5.se
Mon Oct 2 12:15:02 CEST 2006


Thomas Sluyter wrote:
> Yay, debugging! \o/
> 
> Could be handy if we move this off-list, unless no-one objects to us  
> handling this through the list.
> 
> 
>>> bha! end of the script now looks like this
>>>
>>> ### FINALLY... RETRIEVING THE VALUES ###
>>>
>>> EXITCODE=`$SNMPWALK -v 1 -c $COMMUNITY $HOST $STATUS`
>>> [ $DEBUG -gt 0 ] && echo "Retrieve exit code is $EXITCODE" >>  
>>> $DEBUGFILE
>>>
>>> OUTPUT=`$SNMPWALK -Ovq -v 1 -c $COMMUNITY $HOST $STRING`
>>> [ $DEBUG -gt 0 ] && echo "Retrieve status message is: $OUTPUT" >>
>>> $DEBUGFILE
>>>
>>> if [ $EXITCODE -eq 0 ]; then
>>>    echo "$OUTPUT" | grep -v CRITICAL
>>>    [ $? -eq 1 ] && EXITCODE=2
>>> fi
>>>
>>> echo $OUTPUT
>>> exit $EXITCODE
>>>
>>> but when it runs i get this
>>>
>>> ../libexec/retrieve_custom_snmp: line 84: [: -eq: unary operator  
>>> expected
>>> "CRITICAL emcpowera has 2 dead, 2 alive"
>>>
>> Urgh. My bad. What does EXITCODE contain when you run it in debug  
>> mode?
> 
> It should contain the exact same value it contains when not running  
> in debug mode: the exit code for the Nagios script being run through  
> SNMP exec.
> 

Yes, ofc, or we'd have a Heisenbug :)

What I meant was that it doesn't seem to be a numerical value. If I look 
at it I can see that it may very well be a textual representation, so 
perhaps we just have a clash in nomenclature.

> Could you tell me what exactly is contained on line 84 in your case?  
> Because in the version of the script up on my website, line 84 is  
> part of the Nagios "help" text.
> 
> I think I -should- look into the whole "-Ovq" bit a little bit  
> though. I think the $EXITCODE may benefit from this as well...
> 

Ah, that'd be it. I'm guessing the current output is expected to look 
something like this:

oid.some.more.of.the.oid = INTEGER: $REAL_EXITCODE

which is indeed numerical, but with a lot of junk in front of it. -Ovq 
would indeed help for this.

> If I find some time this afternoon, I'll start digging...
> 
> 
>> (on a side-note, whoever names a variable containing textual output  
>> "EXITCODE" should be shot)
> 
> Yes, that would be me thank you... What kind of gun would you prefer?  
> I would like to smoke a pipe before being executed, though. Mind?
> 

Not at all. If you come to sweden I'll buy you a whiskey to go along 
with that smoke. A water squirt gun to put it out when you're done 
sounds about right ;-)

> But before you pull that trigger, would you please go back just a wee  
> a bit and read my docu on what $EXITCODE contains? Why yes, it -does-  
> in fact contain the exit code of the Nagios script that was run on  
> the client side! OMG! Let me quote the bit in question:
> 
> # Output:
> # The exit code is the exit code retrieved from OID.100.0.
> # The output string is the string retrieved from OID.101.1.
> 
> /me puts on a blind fold.
> 
> Any suggestions for a variable name change are more than welcome. And  
> I guess I -could- elaborate the docu a bit more. Expect a newer  
> version, some time this afternoon.
> 

EXITCODE works fine for me. As for the docu-change, it shouldn't be 
necessary assuming either -Ovq or some sed magic removes all the cruft 
that's *not*, in fact, the exit-code.

>>> ho hum - enjoy the beer
>>>
>> Good plan. Working on it ;-)
> 
> Right about now, I'm wishing I had a nice, cold bottle of "Lambiek  
> Kriek" in my desk drawer.
> 

<offtopic> Never tried that. Where's it from? </offtopic>

-- 
Andreas Ericsson                   andreas.ericsson at op5.se
OP5 AB                             www.op5.se
Tel: +46 8-230225                  Fax: +46 8-230231

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Nagios-users mailing list
Nagios-users at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nagios-users
::: Please include Nagios version, plugin version (-v) and OS when reporting any issue. 
::: Messages without supporting info will risk being sent to /dev/null





More information about the Users mailing list