[Nagiosplug-help] Avoiding tmp-files for SNMP-check

Ingo Lantschner ingo.lists at vum.at
Thu Nov 9 20:33:25 CET 2006


Hello,
I wrote a plugin to check the fanstatus in FuSi Servers. The complete  
script is attached at the end of this email.

The plugin works, but what I dont like so much ist this part:
OUTPUT=/tmp/$1-fancheck.tmp
snmpwalk -mAll -v1 -c $2 $1 1.3.6.1.4.1.231.2.10.2.2.5.2.2.1 > $OUTPUT

Using  tempfile is not recommended according to the guidelines for  
nagiosplugins. But how can I store a "multiline-variable" and "grep"  
single lines of it later on?

For the moment I do it like this:
FANSPRESENT=$(grep fanStatus $OUTPUT | grep -v unknown | \
	cut -d " " -f1 | cut -d \. -f2-3)
         for FID in $FANSPRESENT; do
             FNAME=$(cat $OUTPUT | grep fans.16.$FID | cut -d: -f4)
	    ...

May be some of you already came over this prblem - thanks for any  
hint! Ingo.


#! /bin/sh

## 2006-10-23, Ingo Lantschner based on the work of various
## pluginauthors - thanks to all of you!)

## This Plugin checks the fanstatus from FuSi-Severview equiped hosts
## by SNMP

### License Information:
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# you should have received a copy of the GNU General Public License
# along with this program (or with Nagios);  if not, write to the
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA
###

PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin

PROGNAME=`basename $0`
REVISION=`echo 'Revision: 0.1 ' `
ITEM=$3
WARN=$4
CRIT=$5

print_usage() {
         echo "Usage: $PROGNAME <host> <community>"
         echo "No tresholds are set; Checks for failed fans based"
         echo "on the fanStatus from the serverviewagent."
}

print_revision() {
         echo $PROGNAME  - $REVISION
}
print_help() {
         print_revision
         echo ""
         print_usage
         echo ""
         echo "This Plugin checks the fans-status from FuSi-Severview  
equiped hosts."
         echo "No Warning-state is reported, this plugin returns  
CRITICAL if one of "
         echo "the fans has status failed or prefailing."
         echo "ATTENTION: needs SC.MIB installed on checking host to  
work!!"
         echo ""
         exit 0
}

case "$1" in
         --help)
                 print_help
                 exit 0
                 ;;
         --version)
                 print_revision $PROGNAME $REVISION
                 exit 0
                 ;;
         -V)
                 print_revision $PROGNAME $REVISION
                 exit 0
                 ;;
         *)

## Plausibilitaetstes

if [ $# -ne 2 ]; then
    print_usage
    exit 3
    fi

# comment out  this check for MIB if you like
if [ ! -f /usr/share/snmp/mibs/SC.MIB ]; then
    echo "Pls. check if /usr/share/snmp/mibs/SC.MIB exists - plugin  
may fail w/o it!"
    exit 3
    fi

## We start checking ...

#AGENTID=$(snmpget -v1 -mALL -c $2 $1 sniServerMgmt.11.1.1.0)
#if [ $(echo $AGENTID | grep Agent > /dev/null) ]; then
#   echo "No FuSi Serverview Agent present"
#   exit 3
#   fi
OUTPUT=/tmp/$1-fancheck.tmp
snmpwalk -mAll -v1 -c $2 $1 1.3.6.1.4.1.231.2.10.2.2.5.2.2.1 > $OUTPUT
if [ $? -ne 0  ]; then echo "'snmpwalk' failed - probably no SNMP- 
agent installed on this host or wrong IP" ; exit
3; fi
if [ -s $OUTPUT  ]; then
         FANSPRESENT=$(grep fanStatus $OUTPUT | grep -v unknown | cut  
-d " " -f1 | cut -d \. -f2-3)
         for FID in $FANSPRESENT; do
         #echo $FID
            FNAME=$(cat $OUTPUT | grep fans.16.$FID | cut -d: -f4)
            FSTATUS=$(cat $OUTPUT | grep fanStatus.$FID | cut -d: -f4)
            FSRPM=$(cat $OUTPUT | grep fanCurrentSpeed.$FID | cut -d:  
-f4)
            MESSAGE="${MESSAGE} $FNAME is $FSTATUS, $FSRPM r/min.;"
            done
            if [ $(echo $MESSAGE | grep fail > /dev/null) ]; then
               echo "CRITICAL - $(MESSAGE)"
               rm $OUTPUT
               exit 2
               fi
            echo "OK - $MESSAGE"
            rm $OUTPUT
            exit 0
         fi
echo "UNKNOWN - No Fanstatus available on this host."
exit 3
rm $OUTPUT
esac









More information about the Help mailing list