Build precise queries to find exactly what you need
Press ESC to close
Join our next live webinar: “Advanced Nagios Monitoring Techniques” – Register Now
Your review has been submitted and is pending approval.
medium shellscript, wich allows you to check printers via snmp
Current Version
Last Release Date
June 10, 2009
Owner
Nagios Exchange
Website
http://www.monitoring-solution.de/moso/index.html
Compatible With
the new script (0.2)
This script allows you to monitor: *The exact Printer Name - Always OK *The Pagecount - Always OK with Perfromace Data *Some Messages - Always OK *Consumables - Toner,Drum,Transfer,Fuser; If Provided from the Printer, you'll get Performance Data, otherwise only OK,Warning Critical. *The Paper trays - Kindof buggy since some Printers use different OIDs, and most(of them i tested) only give Info about warnig Critical and OK, and some not even that (HP220 is alway ok, even if Tray is pulled out)
I modified this so it can be used to monitor Canon Imagerunner copiers. Here is the code: *************************************************** #!/bin/bash # check_snmp_printer # Description : Check the status of a printer # Version : 1.0 # Author : Yoann LAMY # Licence : GPLv2 # Commands CMD_BASENAME="/bin/basename" CMD_SNMPGET="/usr/bin/snmpget" CMD_SNMPWALK="/usr/bin/snmpwalk" CMD_GREP="/bin/grep" CMD_AWK="/bin/awk" CMD_EXPR="/usr/bin/expr" # Script name SCRIPTNAME=`$CMD_BASENAME $0` # Version VERSION="1.0" # Plugin return codes STATE_OK=0 STATE_WARNING=1 STATE_CRITICAL=2 STATE_UNKNOWN=3 # Default OID (Printer-MIB) OID_NAME=".1.3.6.1.2.1.43.11.1.1.6.1" OID_TOTAL=".1.3.6.1.2.1.43.11.1.1.8.1" OID_STATUS=".1.3.6.1.2.1.43.11.1.1.9.1" OID_NAME_OTHER=".1.3.6.1.2.1.43.12.1.1.4.1" OID_TOTAL_OTHER=".1.3.6.1.2.1.43.10.2.1.9.1" OID_STATUS_OTHER=".1.3.6.1.2.1.43.10.2.1.10.1" OID_PAGE=".1.3.6.1.2.1.43.10.2.1.4.1.1" # Default variables DESCRIPTION="Unknown" STATE=$STATE_UNKNOWN # Default options COMMUNITY="public" HOSTNAME="127.0.0.1" TYPE="page" CONSUMMABLE="black" WARNING=0 CRITICAL=0 # Option processing print_usage() { echo "Usage: ./check_snmp_printer -H 127.0.0.1 -C public -t consummable -o black -w 85 -c 90" echo " $SCRIPTNAME -H ADDRESS" echo " $SCRIPTNAME -C STRING" echo " $SCRIPTNAME -t STRING" echo " $SCRIPTNAME -w INTEGER" echo " $SCRIPTNAME -c INTEGER" echo " $SCRIPTNAME -h" echo " $SCRIPTNAME -V" } print_version() { echo $SCRIPTNAME version $VERSION echo "" echo "The nagios plugins come with ABSOLUTELY NO WARRANTY." echo "You may redistribute copies of the plugins under the terms of the GNU General Public License v2." } print_help() { print_version echo "" print_usage echo "" echo "Check the status of the printer" echo "" echo "-H ADDRESS" echo " Name or IP address of host (default: 127.0.0.1)" echo "-C STRING" echo " Community name for the host's SNMP agent (default: public)" echo "-t STRING" echo " Check type (consummable, page) (default: page)" echo "-o STRING" echo " Consummable (BL,CY,MG,YE,WT,BD,CD,MD,YD,FU,AM) (default: black)" echo "-w INTEGER" echo " Warning level for consummable in percent (default: 0)" echo "-c INTEGER" echo " Critical level for consummable in percent (default: 0)" echo "-h" echo " Print this help screen" echo "-V" echo " Print version and license information" echo "" echo "" echo "This plugin uses the 'snmpget' command and 'snmpwalk' command included with the NET-SNMP package." echo "This plugin support performance data output." echo "If the percentage of the warning level and the critical level are 0, then the script returns a state OK." } while getopts H:C:t:o:w:c:hV OPT do case $OPT in H) HOSTNAME="$OPTARG" ;; C) COMMUNITY="$OPTARG" ;; t) TYPE="$OPTARG" ;; o) CONSUMMABLE="$OPTARG" ;; w) WARNING=$OPTARG ;; c) CRITICAL=$OPTARG ;; h) print_help exit $STATE_UNKNOWN ;; V) print_version exit $STATE_UNKNOWN ;; esac done # Plugin processing if [ $TYPE = "consummable" ]; then # Check the consummable of the printer (Usage : ./check_snmp_printer -H 127.0.0.1 -C public -t consummable -o BL -w 85 -c 90) CONSUMMABLE_NAME=$CONSUMMABLE if [ $CONSUMMABLE = "black" ]; then CONSUMMABLE_NAME="black|cartouche|toner" fi if [ $CONSUMMABLE = "BL" ]; then CONSUMMABLE_ID="1" fi if [ $CONSUMMABLE = "CY" ]; then CONSUMMABLE_ID="2" fi if [ $CONSUMMABLE = "MG" ]; then CONSUMMABLE_ID="3" fi if [ $CONSUMMABLE = "YE" ]; then CONSUMMABLE_ID="4" fi if [ $CONSUMMABLE = "WT" ]; then CONSUMMABLE_ID="5" fi if [ $CONSUMMABLE = "BD" ]; then CONSUMMABLE_ID="6" fi if [ $CONSUMMABLE = "CD" ]; then CONSUMMABLE_ID="7" fi if [ $CONSUMMABLE = "MD" ]; then CONSUMMABLE_ID="8" fi if [ $CONSUMMABLE = "YD" ]; then CONSUMMABLE_ID="9" fi if [ $CONSUMMABLE = "FU" ]; then CONSUMMABLE_ID="10" fi if [ $CONSUMMABLE = "AM" ]; then CONSUMMABLE_ID="11" fi if [ -n "$CONSUMMABLE_ID" ]; then CONSUMMABLE_TOTAL=`$CMD_SNMPGET -t 2 -r 2 -v 1 -c $COMMUNITY -Ovq $HOSTNAME ${OID_TOTAL}.${CONSUMMABLE_ID}` CONSUMMABLE_STATUS=`$CMD_SNMPGET -t 2 -r 2 -v 1 -c $COMMUNITY -Ovq $HOSTNAME ${OID_STATUS}.${CONSUMMABLE_ID}` if [ ${CONSUMMABLE_TOTAL: 0:1} = "-" ]; then CONSUMMABLE_TOTAL=`$CMD_SNMPGET -t 2 -r 2 -v 1 -c $COMMUNITY -Ovq $HOSTNAME ${OID_TOTAL_OTHER}.${CONSUMMABLE_ID}` CONSUMMABLE_STATUS=`$CMD_SNMPGET -t 2 -r 2 -v 1 -c $COMMUNITY -Ovq $HOSTNAME ${OID_STATUS_OTHER}.${CONSUMMABLE_ID}` fi if [ -n "$CONSUMMABLE_TOTAL" ] && [ -n "$CONSUMMABLE_STATUS" ]; then CONSUMMABLE_POURCENT=`$CMD_EXPR ( $CONSUMMABLE_STATUS * 100 ) / ( $CONSUMMABLE_TOTAL )` CONSUMMABLE_USED_POURCENT=`$CMD_EXPR 100 - $CONSUMMABLE_POURCENT` if [ $WARNING != 0 ] || [ $CRITICAL != 0 ]; then if [ $CONSUMMABLE_USED_POURCENT -gt $CRITICAL ] && [ $CRITICAL != 0 ]; then STATE=$STATE_CRITICAL elif [ $CONSUMMABLE_USED_POURCENT -gt $WARNING ] && [ $WARNING != 0 ]; then STATE=$STATE_WARNING else STATE=$STATE_OK fi else STATE=$STATE_OK fi case "$CONSUMMABLE" in black) CONSUMMABLE_NAME="of the black cartridge" ;; cyan) CONSUMMABLE_NAME="of the cyan cartridge" ;; magenta) CONSUMMABLE_NAME="of the magenta cartridge" ;; yellow) CONSUMMABLE_NAME="of the yellow cartridge" ;; drum) CONSUMMABLE_NAME="of the printing device" ;; *) CONSUMMABLE_NAME="of the consummable" esac DESCRIPTION="Utilisation $CONSUMMABLE_NAME : ${CONSUMMABLE_USED_POURCENT}% | cons_used=${CONSUMMABLE_USED_POURCENT};$WARNING;$CRITICAL;0" else DESCRIPTION="Printer is waiting" fi fi elif [ $TYPE = "page" ]; then # Check page number of the printer (Usage : ./check_snmp_printer -H 127.0.0.1 -C public -t page) PAGES=`$CMD_SNMPGET -t 2 -r 2 -v 1 -c $COMMUNITY -Ovq $HOSTNAME $OID_PAGE` if [ -n "$PAGES" ]; then DESCRIPTION="Page number : $PAGES | pages=$PAGES;0;0;0" STATE=$STATE_OK fi fi echo $DESCRIPTION exit $STATE
After the instalation in a debian nagios server. Some problem appeared. 1) line 60: Syntax Error: "(" unexpected... You need to change the First line to #!/bin/bash 2) Some of problem with the consumable. Ie when you say ./check_snmp_printer 172.16.146.14 public CONSUM noir you have : Error OID not found,maybe your Printer does not support checking this device, call me with Option CONSUM TEST or see help. The part for consumable code begin at the line 180. the ID is not correct you need to change -f8 with -f13 3) I have one consumable with 10% and that cause an error. you need to change the condition in the if. -lt with -le for example : if [ "$STATUS" -le "30" ] and if [ "$STATUS" -le "10" ] You may not have these errors but me I had. Sorry for my bad english. I will say, I have never develop with bash before.
Perfect with HP LaserJet 4250!
I got this error and the clue was: bdispatcher@laptop:~/file printers.ini printers.ini.original: ASCII text, with CRLF line terminators So the solution is to convert it with fromdos, unix2dos, or something like that. Hope it helps you
line 60: Syntax Error: "(" unexpected...
This was the perfect plugin for our environment when starting out with Nagios. It was the only one that used universal OIDs, and we have many different brand printers. I also liked how the options allowed you to control the information that was output. If you like this plugin, but need more features, please check out my revised version: http://exchange.nagios.org/directory/Plugins/Hardware/Printers/SNMP-Printer-Check/details
I did find I had to change it from /bin/sh to /bin/bash but other than that it worked perfectly on a range of printers.
After downloading I needed to make a few small changes, but most of it works pretty well. And quite clearly a lot of work has gone into putting this script together. Well worth it. I will submit a couple of enhancement recommendations to the author.
You must be logged in to submit a review.
To:
From: