#!/bin/sh
# bb-hplj.sh
#
# BIG BROTHER - HP LaserJet External Script
# Copyright (c) 2002 by Pascal Fuckerieder
#
# 2002-08-12 Some fixes by (Thanx to Andreas Schulz)
#

HOSTIP=$1
FULLNAME=$2

BBPROG=bb-hplj.sh; export BBPROG

#
# SNMPGET shows us where to find snmpget
#
SNMPGET="/usr/bin/snmpget"
SNMPWALK="/usr/bin/snmpwalk"

if test "$BBHOME" = ""
then
        echo "BBHOME is not set... exiting"
        exit 1
fi

if test ! "$BBTMP"                      # GET DEFINITIONS IF NEEDED
then
        . $BBHOME/etc/bbdef.sh          # INCLUDE STANDARD DEFINITIONS
fi

#
# SELECT SOME LEVELS... GREEN IS THE DEFAULT...
#
CONSUM_WARN="10"		# GO YELLOW AT THIS LEVEL
CONSUM_PANIC="5"		# GO RED AND PAGE AT THIS LEVEL

LINE=""
COLOR="green"

#
# GRAB THE MODEL AND THE CONSUMABLES FROM THE PRINTER VIA SNMP
#
MODEL=`$SNMPGET -v 1 -c public $HOSTIP host.hrDevice.hrDeviceTable.hrDeviceEntry.hrDeviceDescr.1 2>/dev/null | cut -d" " -f3-`
LOCATION=`$SNMPGET -v 1 -c public $HOSTIP system.sysLocation.0 | cut -d " " -f3-`
COUNTER=`$SNMPGET -v 1 -c public $HOSTIP 43.10.2.1.4.1.1 | cut -d " " -f 4`
MESSAGES=`$SNMPWALK -v 1 -c public $HOSTIP 43.18.1.1.8 | cut -d " " -f3- | tr -d "\""`

BLACK_UNITNAME=`$SNMPGET -v 1 -c public $HOSTIP 43.11.1.1.6.1.1 2>/dev/null | cut -d " " -f3- | tr -d "\""`
BLACK_FULL=`$SNMPGET -v 1 -c public $HOSTIP 43.11.1.1.8.1.1 2>/dev/null | cut -d " " -f3- | tr -d "\""`
BLACK_STATUS=`$SNMPGET -v 1 -c public $HOSTIP 43.11.1.1.9.1.1 2>/dev/null | cut -d " " -f3- | tr -d "\""`
BLACK_LEVEL=`echo $BLACK_STATUS*100/$BLACK_FULL | bc 2>/dev/null`

#
# CHECK BLACK TONER
#
if [ "$BLACK_LEVEL" = "" ]
then
        COLOR="black"
        LINE="&black No status available"
else
	if [ "$BLACK_LEVEL" -le "$CONSUM_PANIC" ]
	then
		COLOR="red"
		LINE="$LINE&red $BLACK_UNITNAME of $MODEL in $LOCATION is at panic level ($BLACK_LEVEL%)
"
	else
		if [ "$BLACK_LEVEL" -le "$CONSUM_WARN" ]
		then
			COLOR="yellow"
			LINE="$LINE&yellow $BLACK_UNITNAME of $MODEL in $LOCATION is at warning level ($BLACK_LEVEL%)
"
		fi
	fi
fi

#
# CREATE OUTPUT FOR STATUS PAGE
#
if [ "$COLOR" = "green" ]
then
	LINE="&green All items of $MODEL are OK
"
fi
MSG_BLACK=`printf "%-50.50s %3.0f%%\n" "$BLACK_UNITNAME" $BLACK_LEVEL`
MSG_COUNTER=`printf "%-48.48s %6.0f\n" "Page Counter" "$COUNTER"`
LINE="
$LINE
$MSG_BLACK
$MSG_COUNTER

Messages:
$MESSAGES
"

$BB $BBDISP "status ${MACHINE}.toner $COLOR `date` $LINE"




