Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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 -P 2c -C public -o .

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?

share|improve this question
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
Even if the SMART status is not good (if you can test this though) ? – krisFR Mar 31 '14 at 20:19

4 Answers 4

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 -P 2c -C public -o . | grep GOOD

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

share|improve this answer

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:

share|improve this answer

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

share|improve this answer

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 . --invert-search -r "Critical" -o . -r "Critical" -o .  -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 .$i -r Critical)"

if (echo $test | grep -q Critical); then
    #echo "Drive $i" = 0        
    texte+="Drive_$i CRITICAL, "
    perfdata+="Drive_$i=0 "
    #echo "Drive $i" = 1
    texte+="Drive_$i Normal, "
    perfdata+="Drive_$i=1 "
if [ $crit = 1 ]
    resultat="CRITICAL: "
    resultat="OK: "
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_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

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.