Inverting check_snmp status

Martin Melin martinm at op5.org
Fri Mar 12 01:44:11 CET 2010


On Thu, Mar 11, 2010 at 4:07 PM, <nigel.leach at uk.bnpparibas.com> wrote:

>
> RHEL AS4 U6
> Nagios        v3.2.0
> check_snmp v1.4.14
>
> A small and annoying problem, that I'm hoping will have some whizzy easy
> fix.
>
> I use check_snmp to get the location and contact details of my servers.
> Something like this
>
>         ./check_snmp -H localhost -o sysLocation.0 -l ""
>         OK - London XX YYY
>
> This, of course, assumes snmpd.comf has been populated correctly. If it
> hasn't I get something like this
>
>         ./check_snmp -H localhost -o sysLocation.0 -l ""
>          OK - Unknown (edit /etc/snmp/snmpd.conf) |
>
> I'd like this to produce a warning, and thought I could achieve this with a
> regular expression, but haven't been able to yet. Is there any way I can
> invert a regex, or use thresholds to force a NOTOK status.
>

I tried creating an inverted regex to use in the --ereg parameter to
check_snmp, but wasn't able to get a negative lookahead working, which is
how I usually create these kinds of inverted regexps. check_snmp kept
complaining it couldn't parse the regex, so I guess the regex support may be
limited - or I might just be letting bash interfere with my arguments due to
the late hour ;-)


>
> This doesn't work
>
>         ./check_snmp -H localhost -o sysLocation.0 -l "" -r "!etc"
>         -bash: !etc: event not found
>
> Not urgent, but any help much appreciated.
>

In keeping with the KISS principle, I suggest a quick wrapper script for
your location check. Any other solution would require you to use a separate
check_command in Nagios anyway, so it might just be simpler to go the easy
route here.

Nagios itself does not care about the text output from plugins, only the
exit code, so you could have a wrapper script return warning for locations
that contain the string Unknown by simply doing this:

RESULT=`/replace/with/variable/check_snmp -H $1 -o sysLocation.0 -l ""`
echo $RESULT
if [[ $RESULT =~ "Unknown" ]]; then
        exit 1
fi
exit 0

Of course, you could make the text output make more sense with sed et. al.,
but Nagios itself is happy with the above.

HTH,

-- 
Martin Melin

May your delusions be benign and your compulsions have utility
____________________________
op5 AB
http://www.op5.com

http://www.op5.org/
http://www.op5.com/op5/products/network-monitor/nagios/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.monitoring-lists.org/archive/users/attachments/20100312/84e890af/attachment.html>
-------------- next part --------------
------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
-------------- next part --------------
_______________________________________________
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