#! /bin/bash
#
# Nagios-Plugin zum �berpr�fen von Verbrauchsmaterialien in HP Druckern
# Last Modified: 20-10-2006

# Paths to commands used in this script.  These
# may have to be modified to match your system setup.

PATH=""

SNMPGET="/usr/bin/snmpget"
EXPR="/usr/bin/expr"

PROGNAME=`/bin/basename $0`
PROGPATH=`echo $0 | /bin/sed -e 's,[\\/][^\\/][^\\/]*$,,'`
REVISION=`echo '$Revision: 1.4 $' | /bin/sed -e 's/[^0-9.]//g'`

. $PROGPATH/utils.sh

print_usage() {
    echo "Usage: $PROGNAME -H Host -OM OID-Max -OC OID-Cur -w Warn in % -c Critical in %"
    echo "Usage: $PROGNAME --help"
    echo "Usage: $PROGNAME --version"
}

print_help() {
    print_revision $PROGNAME $REVISION
    echo ""
    print_usage
    echo ""
    echo "�berpr�fe Verbrauchsmaterial von HP-Druckern"
    echo ""
    support
}

# Make sure the correct number of command line
# arguments have been supplied

if [ $# -lt 1 ]; then
    print_usage
    exit $STATE_UNKNOWN
fi

# Grab the command line arguments

#host=$1
#oidmax=$2
#oidcur=$3
exitstatus=$STATE_WARNING #default
while test -n "$1"; do
    case "$1" in
        --help)
            print_help
            exit $STATE_OK
            ;;
        -h)
            print_help
            exit $STATE_OK
            ;;
        --version)
            print_revision $PROGNAME $VERSION
            exit $STATE_OK
            ;;
        -V)
            print_revision $PROGNAME $VERSION
            exit $STATE_OK
            ;;
        --host)
            host=$2
            shift
            ;;
        -H)
            host=$2
            shift
            ;;
        --oidmax)
            oidmax=$2
            shift
            ;;
        -OM)
            oidmax=$2
            shift
            ;;
        --oidcur)
            oidcur=$2
            shift
            ;;
        -OC)
            oidcur=$2
            shift
            ;;
        --warn)
            warn=$2
            shift
            ;;
        -w)
            warn=$2
            shift
            ;;
        --current)
            critical=$2
            shift
            ;;
        -c)
            critical=$2
            shift
            ;;
        -x)
            exitstatus=$2
            shift
            ;;
        --exitstatus)
            exitstatus=$2
            shift
            ;;
        *)
            echo "Unknown argument: $1"
            print_usage
            exit $STATE_UNKNOWN
            ;;
    esac
    shift
done

MAX=`/usr/bin/snmpget -O Uvbqs -v 2c -c public $host $oidmax`
REST=`/usr/bin/snmpget -O Uvbqs -v 2c -c public $host $oidcur`
HUNDERT=100

   CURRENT=`/usr/bin/expr $MAX - $REST`
   CURPERCENT=`/usr/bin/expr $CURRENT "*" $HUNDERT "/" $MAX`
   
   if [[ -z $MAX ]]; then
      echo "CRITICAL - $host seems to be dead"
      exitstatus=2
   elif [[ $CURPERCENT -lt $warn ]]; then
      echo "OK - $host: $CURRENT / $CURPERCENT% |Pages=$CURRENT;"
      exitstatus=0
   elif [[ $CURPERCENT -lt $critical ]]; then
      echo "WARNING - $host: $CURRENT / $CURPERCENT% |Pages=$CURRENT;"
      exitstatus=1
   elif [[ $CURPERCENT -gt $critical ]]; then
      echo "CRITICAL - $host: $CURRENT / $CURPERCENT% |Pages=$CURRENT;"
      exitstatus=2
   else
      echo "UNKNOWN - I see dead people - Something is wrong"
      exitstatus=3
   fi

exit $exitstatus
