#!/bin/sh

PROGNAME='Check Toner 4 Color Printers ver. 0.1'

SCP="snmpget"
ARGS='-c public -v 1 -O v'
HOST=$1
TONER=$2

#For Utax / Kyocera Printers

CM_OID='.1.3.6.1.2.1.43.11.1.1.8.1.1' # Max Cyan Toner 
CR_OID='.1.3.6.1.2.1.43.11.1.1.9.1.1' # Remaining Cyan Toner
MM_OID='.1.3.6.1.2.1.43.11.1.1.8.1.2' # Max Magenta Toner
MR_OID='.1.3.6.1.2.1.43.11.1.1.9.1.2' # Remaining Magenta Toner
YM_OID='.1.3.6.1.2.1.43.11.1.1.8.1.3' # Max Yellow Toner
YR_OID='.1.3.6.1.2.1.43.11.1.1.9.1.3' # Remaining Yellow Toner
KM_OID='.1.3.6.1.2.1.43.11.1.1.8.1.4' # Max Black Toner
KR_OID='.1.3.6.1.2.1.43.11.1.1.9.1.4' # Remaining Black Toner



#For HP Printers

HKM_OID='.1.3.6.1.2.1.43.11.1.1.8.1.1' # Max Black Toner
HKR_OID='.1.3.6.1.2.1.43.11.1.1.9.1.1' # Remaining Black Toner
HCM_OID='.1.3.6.1.2.1.43.11.1.1.8.1.2' # Max Cyan Toner 
HCR_OID='.1.3.6.1.2.1.43.11.1.1.9.1.2' # Remaining Cyan Toner
HMM_OID='.1.3.6.1.2.1.43.11.1.1.8.1.3' # Max Magenta Toner
HMR_OID='.1.3.6.1.2.1.43.11.1.1.9.1.3' # Remaining Magenta Toner
HYM_OID='.1.3.6.1.2.1.43.11.1.1.8.1.4' # Max Yellow Toner
HYR_OID='.1.3.6.1.2.1.43.11.1.1.9.1.4' # Remaining Yellow Toner



CM_CMD=`$SCP $ARGS $HOST $CM_OID |sed 's/INTEGER: //'`
CR_CMD=`$SCP $ARGS $HOST $CR_OID |sed 's/INTEGER: //'`
MM_CMD=`$SCP $ARGS $HOST $MM_OID |sed 's/INTEGER: //'`
MR_CMD=`$SCP $ARGS $HOST $MR_OID |sed 's/INTEGER: //'`
YM_CMD=`$SCP $ARGS $HOST $YM_OID |sed 's/INTEGER: //'`
YR_CMD=`$SCP $ARGS $HOST $YR_OID |sed 's/INTEGER: //'`
KM_CMD=`$SCP $ARGS $HOST $KM_OID |sed 's/INTEGER: //'`
KR_CMD=`$SCP $ARGS $HOST $KR_OID |sed 's/INTEGER: //'`

HCM_CMD=`$SCP $ARGS $HOST $HCM_OID |sed 's/INTEGER: //'`
HCR_CMD=`$SCP $ARGS $HOST $HCR_OID |sed 's/INTEGER: //'`
HMM_CMD=`$SCP $ARGS $HOST $HMM_OID |sed 's/INTEGER: //'`
HMR_CMD=`$SCP $ARGS $HOST $HMR_OID |sed 's/INTEGER: //'`
HYM_CMD=`$SCP $ARGS $HOST $HYM_OID |sed 's/INTEGER: //'`
HYR_CMD=`$SCP $ARGS $HOST $HYR_OID |sed 's/INTEGER: //'`
HKM_CMD=`$SCP $ARGS $HOST $HKM_OID |sed 's/INTEGER: //'`
HKR_CMD=`$SCP $ARGS $HOST $HKR_OID |sed 's/INTEGER: //'`

CHKPTR=`$SCP $ARGS $HOST iso.3.6.1.2.1.25.3.2.1.3.1 |grep -o 'CDC'`


 UTAX () {

while [ "$TONER" = "C" ] 
do

 if [ $CR_CMD -gt 150  ] ; then
	OUTPUT="${OUTPUT} CYAN Toner OK -- Toner Levels: `echo $CR_CMD` of `echo $CM_CMD` Remaining | `echo $CR_CMD`"
	STAT=0
		else
			OUTPUT="${OUTPUT} CYAN Toner Low -- Toner Levels: `echo $CR_CMD` of `echo $CM_CMD` Remaining | `echo $CR_CMD`" 
			STAT=2
fi
TONER="AB"
done


while [ "$TONER" = "M" ] 
do

 if [ $MR_CMD -gt 150  ] ; then
	OUTPUT="${OUTPUT} MAGENTA Toner OK -- Toner Levels: `echo $MR_CMD` of `echo $MM_CMD` Remaining | `echo $MR_CMD`"
	STAT=0
		else
			OUTPUT="${OUTPUT} MAGENTA Toner Low -- Toner Levels: `echo $MR_CMD` of `echo $MM_CMD` Remaining | `echo $MR_CMD`" 
			STAT=2
fi
TONER="AB"
done


while [ "$TONER" = "Y" ] 
do

 if [ $YR_CMD -gt 150  ] ; then
	OUTPUT="${OUTPUT} YELLOW Toner OK -- Toner Levels: `echo $YR_CMD` of `echo $YM_CMD` Remaining | `echo $YR_CMD`"
	STAT=0
		else
			OUTPUT="${OUTPUT} YELLOW Toner Low -- Toner Levels: `echo $YR_CMD` of `echo $YM_CMD` Remaining | `echo $YR_CMD`" 
			STAT=2
fi
TONER="AB"
done

while [ "$TONER" = "K" ] 
do

 if [ $KR_CMD -gt 150  ] ; then
	OUTPUT="${OUTPUT} BLACK Toner OK -- Toner Levels: `echo $KR_CMD` of `echo $KM_CMD` Remaining | `echo $KR_CMD`"
	STAT=0
		else
			OUTPUT="${OUTPUT} BLACK Toner Low -- Toner Levels: `echo $KR_CMD` of `echo $KM_CMD` Remaining | `echo $KR_CMD`" 
			STAT=2
fi
TONER="AB"
done
} 

 HP () {

while [ "$TONER" = "C" ] 
do

 if [ $HCR_CMD -gt 150  ] ; then
	OUTPUT="${OUTPUT} CYAN Toner OK -- Toner Levels: `echo $HCR_CMD` of `echo $HCM_CMD` Remaining | `echo $HCR_CMD`"
	STAT=0
		else
			OUTPUT="${OUTPUT} CYAN Toner Low -- Toner Levels: `echo $HCR_CMD` of `echo $HCM_CMD` Remaining | `echo $HCR_CMD`" 
			STAT=2
fi
TONER="AB"
done


while [ "$TONER" = "M" ] 
do

 if [ $HMR_CMD -gt 150  ] ; then
	OUTPUT="${OUTPUT} MAGENTA Toner OK -- Toner Levels: `echo $HMR_CMD` of `echo $HMM_CMD` Remaining | `echo $HMR_CMD`"
	STAT=0
		else
			OUTPUT="${OUTPUT} MAGENTA Toner Low -- Toner Levels: `echo $HMR_CMD` of `echo $HMM_CMD` Remaining | `echo $HMR_CMD`" 
			STAT=2
fi
TONER="AB"
done


while [ "$TONER" = "Y" ] 
do

 if [ $HYR_CMD -gt 150  ] ; then
	OUTPUT="${OUTPUT} YELLOW Toner OK -- Toner Levels: `echo $HYR_CMD` of `echo $HYM_CMD` Remaining | `echo $HYR_CMD`"
	STAT=0
		else
			OUTPUT="${OUTPUT} YELLOW Toner Low -- Toner Levels: `echo $HYR_CMD` of `echo $HYM_CMD` Remaining | `echo $HYR_CMD`" 
			STAT=2
fi
TONER="AB"
done

while [ "$TONER" = "K" ] 
do

 if [ $HKR_CMD -gt 150  ] ; then
	OUTPUT="${OUTPUT} BLACK Toner OK -- Toner Levels: `echo $HKR_CMD` of `echo $HKM_CMD` Remaining | `echo $HKR_CMD`"
	STAT=0
		else
			OUTPUT="${OUTPUT} BLACK Toner Low -- Toner Levels: `echo $HKR_CMD` of `echo $HKM_CMD` Remaining | `echo $HKR_CMD`" 
			STAT=2
fi
TONER="AB"
done
} 

	if [ "$CHKPTR" = "CDC" ] ; then
		UTAX
		else
		HP
	fi

echo $OUTPUT
exit $STAT 
