Monday, January 26, 2009

Update 0.3

An update to the check_toner script:
nagiosexchange.org.



#!/bin/bash
#
#check_toner version 0.3
#
#01-26-2009, Henry Franco
#
# This plugin will check the black toner level on a printer via SNMP.
# The plugin returns warning and critical status when the toner
# drops below $CRIT AND $WARN.


if [ $# -lt 1 ]; then
echo "Usage: ./check_toner PRINTER_NAME"
exit 127
fi

HOST=$1
INK="Black ink available:"
CRIT=5
WARN=10
STATUS=0

# GET THE MAXIMUN CAPACITY VALUE FROM SNMP
max_level=`snmpwalk -O qv -v 2c -c public $HOST mib-2.43.11.1.1.8.1.1`
RES=$?

# GET CURRENT SUPPLY LEVEL FROM SNMP
current_level=`snmpwalk -O qv -v 2c -c public $HOST mib-2.43.11.1.1.9.1.1`
RES=$?

#BAIL OUT IF ANYTHING WENT WRONG
if [ $RES != 0 ]; then
INK="Toner Unknown - SNMP problem. No data received from host.";
echo $INK;
STATUS=3;
exit $STATUS;
fi

#CALCULATE TONER LEVEL
result=$(echo "scale=2; $current_level / $max_level;" | bc)

#ACTUAL VALUE OF TONER SUPPLY
percent=`echo "$result"*"100"/"1"|bc`

#CHECK WARNING AND CRITICAL LEVELS
if [ $percent -le $CRIT ]; then
echo "Toner Critical - "$INK $percent"%";
STATUS=2
elif [ $percent -le $WARN ]; then
echo "Toner Warning - "$INK $percent"%";
STATUS=1
else
echo "Toner OK - "$INK $percent"%";
fi

exit $STATUS

2 comments:

  1. Hi, I read this Blog it's really nice, thanks for Sharing with us and find one Of the best deal here:-

    Iphone Accessories
    Canon cartridge
    Epson Ink
    Lexmark Toner
    Toner cartridge
    Canon Printers

    ReplyDelete
  2. Toner cartridge is very useful it is very easily available and your post have a great information.

    http://www.absolutetoner.com

    ReplyDelete