Home Directory

Search Exchange

Search All Sites

Nagios Live Webinars

Let our experts show you how Nagios can help your organization.

Contact Us

Phone: 1-888-NAGIOS-1
Email: sales@nagios.com

Login

Remember Me

Directory Tree

Directory

CameronMR

Reviews(2)
SNMP Printer Check
Hi:

We have Xerox, Ricoh and HP printers at our facility and I found that the status function wasn't returning enough info for me. I needed the following:

1) If an HP printer is asleep, it should recognize that not go critical.
2) Xerox machines always complain about the bypass tray, ignore them. In fact never return a warning or critical with Xerox printers (specific to our environment)
3) If the printer does go into an error state, parse the return code and tell me what the actual problem is. Some issues in our environment should be fixed by our techs while others are handled by administrative staff so that is important to know.

I haven't programmed in BASH since the mid-90's and even then only sparingly so I apologize to the actual pro's out there if this isn't the cleanest but it works so, um, yay!

Here is the entire Status function that has been tested against Ricoh, Xerox and HP printers:

STATUS_EXIT_CODE=0
PRINTER_STATUS=$(snmpget -v1 -Ovq -c $COMMUNITY $HOST_NAME 1.3.6.1.2.1.25.3.5.1.1.1 2>/dev/null)
PRINTER_MODEL=$(snmpget -v1 -Ovq -c $COMMUNITY $HOST_NAME 1.3.6.1.2.1.25.3.2.1.3.1 2>/dev/null)
PRINTER_DETECTED_ERROR=$(snmpwalk -v1 -Ovxq -c $COMMUNITY $HOST_NAME 1.3.6.1.2.1.25.3.5.1.2 2>/dev/null)
DISPLAY=$(snmpwalk -v1 -Ovq -c $COMMUNITY $HOST_NAME 1.3.6.1.2.1.43.16.5.1.2.1 2>/dev/null | tr -d "\"")
if [ ! -z "$PRINTER_DETECTED_ERROR" ]; then

IFS=' ' read -ra ErrVals us is $PRINTER_STATUS. Printer is reporting: $PRINTER_ERROR_RESULT"
STATUS_EXIT_CODE=2
fi
if [[ "$DISPLAY" == "Sleep"* ]]; then
EXIT_STRING="OK: Printer status is $DISPLAY."
STATUS_EXIT_CODE=0
fi
;;
"idle")
EXIT_STRING="OK: Printer status is $PRINTER_STATUS"
;;
"printing")
EXIT_STRING="OK: Printer status is $PRINTER_STATUS"
;;
"warmup")
EXIT_STRING="OK: Printer status is $PRINTER_STATUS"
;;

*)
EXIT_STRING="WARNING: Printer status is $PRINTER_STATUS"
STATUS_EXIT_CODE=1
;;
esac

return $STATUS_EXIT_CODE
}
byCameronMR, April 10, 2015
Hello:

I made a change along the same lines as the comment above to allow for more exclusions to be specified. My change to the code is here:

# process any exclusions, if they have been defined
if ($the_arguments{'_arg2'}) {
# exclusion regex defined, decide if we want this row
my @excl = split(/,/,$the_arguments{'_arg2'});
foreach my $service_exclusion (@excl)
{
if ($$row{'DisplayName'}=~/$service_exclusion/ || $$row{'Name'}=~/$service_exclusion/) {
# regex matches so exclude this row
$num_excluded++;
$debug && print "---> Excluding \"$$row{'DisplayName'}\" ($$row{'Name'})\n";
$process_this_row=0;
}
}
}

Thanks for this plugin, it is great!