2

I'm trying to configure Icinga to query the SMART status of the hard drives loaded into a storage array I'm configuring.

The issue I've run into is the response from the array when querying the OID of a drive is text, and not a number.

./check_snmp -H 10.0.10.17 -P 2c -C public -o .1.3.6.1.4.1.24681.1.2.11.1.7.1
SNMP OK - "GOOD" |

I'm used to working with numbers rather than strings when dealing with output of check_snmp. Does anyone know how I can create a critical or warning notification when anything other than the output GOOD is returned?

DKNUCKLES
  • 4,028
  • 9
  • 45
  • 60
  • A simple solution would be to just call check_snmp within a script. Have your script get the check_SNMP output, and then perform whatever matching you like on it. But perhaps there is something more elegant. – Zoredache Mar 31 '14 at 19:25
  • I could certainly do that, however I'm kind of hoping that someone knows of a way to evaluate strings rather than numbers with check_snmp :) – DKNUCKLES Mar 31 '14 at 19:26
  • What returns `$?` just after the `check_snmp` command in case of a "NOT GOOD" status ? – krisFR Mar 31 '14 at 19:53
  • Putting the `$?` after the `check_snmp` command simply gives me a `No OIDs Specified` error. – DKNUCKLES Mar 31 '14 at 19:54
  • ?? misunderstood. Should return 0 or 1. Run the `check_snmp` command as you wrote it in your question, once completed run `echo $?` (all these from a terminal) – krisFR Mar 31 '14 at 19:57
  • Ah, my apologies. The echo value was 0. – DKNUCKLES Mar 31 '14 at 20:00
  • 1
    Even if the SMART status is not good (if you can test this though) ? – krisFR Mar 31 '14 at 20:19

5 Answers5

1

You certainly already know that Nagios needs a number (0,1,2,3) as a return status code from the command launched.

if $? for the check_snmp command always returns 0, my advice would be to write your own check adding pipe and grep to the check_snmp command, something like :

./check_snmp -H 10.0.10.17 -P 2c -C public -o .1.3.6.1.4.1.24681.1.2.11.1.7.1 | grep GOOD

This will return 0 (OK) if word GOOD is found within the output, otherwise it will return 1 (Warning).

krisFR
  • 12,830
  • 3
  • 31
  • 40
1

You cannot use the stock check_snmp with non-numerical values; you have to either write a wrapper around the check_snmp plugin, or use/write a plugin that checks the string values. That's why there are hundreds of SNMP plugin variants for specific hardware. That OID is for a QNAP NAS, right?

Usually, you'll find that someone else has already done the work for you. You can probably use one of these plugins as-is, or fork them:

Keith
  • 4,627
  • 14
  • 25
0

I had the same problem as soon as I had to set warning or critical as a string, so I just used it with the --invert-search and --ereg option, like this:

./check_snmp -P 3 -U monitoring_icinga -L authPriv -a SHA -x AES -A 'secr3t' --privpasswd='secr3t' 10.155.0.1 -o .1.3.6.1.4.1.25461.2.1.2.1.11.0 -r Non-functional --invert-search; echo $?
SNMP OK - "active" | 
0
./check_snmp -P 3 -U monitoring_icinga -L authPriv -a SHA -x AES -A 'secr3t' --privpasswd='secr3t' 10.155.0.1 -o .1.3.6.1.4.1.25461.2.1.2.1.11.0 -r active --invert-search; echo $?
SNMP CRITICAL - *"active"* | 
2

try this:

./check_snmp -H 10.0.10.17 -P 2c -C public -o .1.3.6.1.4.1.24681.1.2.11.1.7.1 --ereg GOOD --invert-search
0

If you need names instead of numbers (OID) you need to convert those OID into mibs. Download the required mibs for the given purpose (hard drive, interface of a router, services etc...). After you download try using the script with a given name for the purpose. for example if i like to use check_snmp to check the uptime ill do this: ./check_snmp -H iphosts -P 2c -C public -o sysUpTime.0 you can then replace the number OID with the mibs name ... that is all point

IvanAK
  • 147
  • 1
  • 1
  • 11
0

You must write your own script.

In this script, you can use the following options of the check_snmp plugin:

-s, --string=STRING: Return OK state (for that OID) if STRING is an exact match
-r, --ereg=REGEX: Return OK state (for that OID) if extended regular expression REGEX matches
-R, --eregi=REGEX: Return OK state (for that OID) if case-insensitive extended REGEX matches --invert-search: Invert search result (CRITICAL if found)

For example, I have to verify the state of 3 hdd on my server, with a specified OID. This OID return the string "Normal" when all is ok and "Critical" when there is a problem, so my command is:

./check_snmp -H <@IP> -C <community> -o .1.3.6.1.4.1.2.3.51.3.1.12.2.1.3.0 --invert-search -r "Critical" -o .1.3.6.1.4.1.2.3.51.3.1.12.2.1.3.1 -r "Critical" -o .1.3.6.1.4.1.2.3.51.3.1.12.2.1.3.2  -r "Critical"  -o -l "Drive 0" -l "Drive 1" -l "Drive 2" -l "Drive 3"

It will return when all is ok:

SNMP OK - Drive 0 "Normal" Drive 1 "Normal" Drive 2 "Normal" Drive 3 "Normal" |

and when there is a problem:

SNMP CRITICAL - Drive 0 "Normal" Drive 1 "Normal" Drive 2 "Normal" Drive 3 *"Critical"* 

If you want to have numbers instead strings, you must modify the results your script will send to nagios. In my case, I wanted a text with the normal exit of check_snmp, and the value 1 for Normal state and 0 for Critical value for perfdata. So in my script I did like this:

...    
test="$(/usr/lib/nagios/plugins/check_snmp -H <snip> -C <snip> --invert-search -o .1.3.6.1.4.1.2.3.51.3.1.12.2.1.3.$i -r Critical)"

if (echo $test | grep -q Critical); then
    #echo "Drive $i" = 0        
    texte+="Drive_$i CRITICAL, "
    perfdata+="Drive_$i=0 "
    crit=1
else
    #echo "Drive $i" = 1
    texte+="Drive_$i Normal, "
    perfdata+="Drive_$i=1 "
...
if [ $crit = 1 ]
then
    resultat="CRITICAL: "
    result_code=2
else
    resultat="OK: "
    result_code=0
fi
resultat+="$texte|$perfdata"
echo $resultat
exit $result_code

The exit of your script will be:

CRITICAL: Drive_0 Normal, Drive_1 Normal, Drive_2 Normal, Drive_3 
Normal, Drive_4 Normal, Drive_5 Normal, Drive_6 Normal, Drive_7 Normal, 
Drive_8 CRITICAL, Drive_9 CRITICAL, Drive_10 CRITICAL, |Drive_0=1
Drive_1=1 
Drive_2=1 Drive_3=1 Drive_4=1 Drive_5=1 Drive_6=1 Drive_7=1 Drive_8=0 
Drive_9=0 Drive_10=0

With at left of the "|" the text will appear in nagios, ahd at the right the values for perfdata by disk.

nagios define the state of the service depending on the value returned by the function exit

Sorcha
  • 1,315
  • 8
  • 11