Home Directory Plugins Hardware Printers SNMP Printer Check

SNMP Printer Check Popular

Bookmark and Share

Rating
23 votes
Favoured:
2
Current Version
3.141592
Last Release Date
2011-10-12
Compatible With
  • Nagios 3.x
E-mail
License
GPL
Hits
256511
Files:
FileDescription
check_snmp_printerVersion 3.141592 Script
check_snmp_printer.shVersion 2.1 Script
check_snmp_printer_args.shVersion 2.1 POSIX args with custom thresholds
check_snmp_printer_versions.txtVersion History
SNMP Printer Check
Universal printer check. Check for specific consumables or report on all. Query model/serial #, event messages, tray status and much more!

Originally based on Monitoring Solutions' check_snmp_printer, this provides friendly output, quick execution and thorough pre-flight checking.
*** NOW COMPATIBLE WITH UBUNTU ***

I liked the original plugin but wanted to be able to report the status of all consumables. For some devices this output can get huge. When only 1 component is empty, it becomes a challenge to find what needs to be replaced in the output. So this script was born.

I added checks for user input and better feedback for improper parameters. The same goes for SNMP status - before any code is executed, this is tested.

Usage is as follows:
check_snmp_printer -H {HOSTADDRESS} -C {COMMUNITY} -x "{CHECK}" -w {WARNING} -c {CRITICAL} -S {separator string} | -V | -h

{CHECK} can be one of the following:
CONSUM {"string" | TEST | ALL}
DEVICE
DISPLAY
MESSAGES
MODEL
PAGECOUNT
STATUS
TRAY {number(s) | TEST | ALL}
VERSION

If you want the output for consumables to contain multiple lines, pass the following argument:
-S "n"

Then you need to edit your service notifications. Just after the $SERVICEOUTPUT$ macro, you will need to add "n$LONGSERVICEOUTPUT$". E-mails will finally contain lines 2 and up of the output.

The CONSUM option gives results for all consumable names that match the string passed. For instance, you can pass "CONSUM Toner" and see all toner levels (no staple cartridges or imaging units). Similarly, "CONSUM Black" will show you the Black imaging unit and Black toner levels all at once. The ALL option gives all consumable status at once, and TEST will show you which CONSUMABLES can be monitored.

CONSUMX reports on consumables that match the eXact string passed to it. This helps alleviate problems when a "unique" string is not possible. For example, "CONSUMX Black Toner" would give an error unless the FULL description of the consumable (from a CONSUM TEST) is "Black Toner". Any consumable named "Black Toner1" or "Black Toner Cartridge" would be overlooked.

TRAY can be passed a number or list of numbers (comma-separated) as a parameter. The ALL parameter reports all tray statuses and TEST lets you know which trays the device has. In addition to generic status, the tray function tries to calculate paper remaining as a % of capacity (if possible), although this only works as good as the sensors on the device (and often only returns values at fixed intervals, such as 25%, 50%, 75%, etc.)

DEVICE, DISPLAY, MESSAGES, MODEL and STATUS report information about the printer's hardware devices, physical display, event log messages, model/serial or overall status (respectively).

If looking to add this to a new configuration, your command descriptions should look something like the following:

define service{
use generic-service
service_description Toner Supply
check_command check_snmp_printer!public!"CONSUM Toners"!20!10
}

define service{
use generic-service
service_description Printer Model
check_command check_snmp_printer!public!"MODEL"
}

...etc.

define command{
command_name check_printers
command_line $USER1$/check_snmp_printer -H $HOSTADDRESS -C $ARG1$ -x $ARG2 -w $ARG3$ -c $ARG4$
}
Reviews (17)
bydceola, April 28, 2011
1 of 1 people found this review helpful
Any chance someone can share their service definition and command definition lines for this? I'm having trouble configuring them correctly.
Owner's reply

Your command definition should look like this:

define command {
command_name check_printer
command_line $USER1$/check_printer $HOSTADDRESS$ $ARG1$ $ARG2$
}

bySchillo, October 8, 2010
1 of 1 people found this review helpful
Great Plugin.
I added 3 little Functions - maybe you wanne add them to the Script:
Display Message
Printer Status
Device Status

#################################################
#########################################################
### check_display function ###
#########################################################
function check_display(){
DISPLAY=`snmpget -v1 -On -c $COMMUNITY $HOSTNAME 1.3.6.1.2.1.43.16.5.1.2.1.1 | cut -d " " -f4-`

printf "Displaytext: $DISPLAY
"
exit 0
}
#########################################################
### check_printer_status function ###
#########################################################
function check_printer_status(){
PRSTATUS=`snmpget -v1 -On -c $COMMUNITY $HOSTNAME 1.3.6.1.2.1.25.3.5.1.1.1 | cut -d " " -f4-`
EXITSTRING="Drucker Status = "
EXITCODE=0
case "$PRSTATUS" in
"other(1)")
EXITSTRING="$EXITSTRING$PRSTATUS - STATUS: CRITICAL!"
EXITCODE=2
;;
"idle(3)")
EXITSTRING="$EXITSTRING$PRSTATUS - STATUS: OK!"
EXITCODE=0
;;
"printing(4)")
EXITSTRING="$EXITSTRING$PRSTATUS - STATUS: OK!"
EXITCODE=0
;;
"warmup(5)")
EXITSTRING="$EXITSTRING$PRSTATUS - STATUS: OK!"
EXITCODE=0
;;
*)
EXITSTRING="$EXITSTRING$PRSTATUS - STATUS: WARNING!"
EXITCODE=1
;;
esac
printf "$EXITSTRING|$PRSTATUS;;;
"
exit $EXITCODE
}
#########################################################
### check_device_status function ###
#########################################################
function check_device_status(){
DEVSTATUS=`snmpget -v1 -On -c $COMMUNITY $HOSTNAME 1.3.6.1.2.1.25.3.2.1.5.1 | cut -d " " -f4-`

EXITSTRING = "Geraet Status = "
EXITCODE=0
case "$DEVSTATUS" in
"unknown(1)")
EXITSTRING="$EXITSTRING$DEVSTATUS - STATUS: WARNING!"
EXITCODE=1
;;
"running(2)")
EXITSTRING="$EXITSTRING$DEVSTATUS - STATUS: OK!"
EXITCODE=0
;;
"warning(3)")
EXITSTRING="$EXITSTRING$DEVSTATUS - STATUS: WARNING!"
EXITCODE=1
;;
"testing(4)")
EXITSTRING="$EXITSTRING$DEVSTATUS - STATUS: OK!"
EXITCODE=0
;;
"down(5)")
EXITSTRING="$EXITSTRING$DEVSTATUS - STATUS: CRITICAL!"
EXITCODE=2
;;
*)
EXITSTRING="$EXITSTRING$DEVSTATUS - STATUS: WARNING!"
EXITCODE=1
;;
esac
printf "$EXITSTRING|$DEVSTATUS;;;
"
exit $EXITCODE
}
bytocri, May 27, 2010
1 of 1 people found this review helpful
The script give the error "bad interpreter" at the beginning.
To solve it make a "dos2unix" command.

After this problem, the script works very well.
Thanks a lot
Owner's reply

Thanks for pointing out you had this problem. While my files worked fine in either Windows or CentOS, it could be that WinSCP was converting the file for me without realizing it.

The file that is uploaded NOW has been converted to UTF-8 format first, so please download to get the latest fixes!

byDI, April 29, 2010
0 of 2 people found this review helpful
I tried it on 4 Linux based PC, 2 gentoo64, 1 Sabayon 64, and 1 Centos, it simply does not work at all.
Each time I try to launch it, i've got several errors, unknown command, at line 158,159,163,164.
I edited the file and remove the help() function, and tried again to make it work. It failed, cannot find function, syntax error in check_snmp_printer, unknown ^M... It seems the file has been created under windows... If so, please mention it.
Owner's reply

The original file was indeed created in Windows. It appears WinSCP may be converting files for me when transferring to my CentOS box. You should see the errors go away if you convert the file using dos2unix or similar programs. I use Notepad++ as an editor and it easily converts between UTF and ANSI formats as well.

Please download my latest version, 1.6, which has some bugfixes and was converted to UTF-8 before uploading. I really hope you will try my script again and adjust your rating after you can get it working.

byzoemu, October 12, 2011
0 of 1 people found this review helpful
Owner's reply

Please provide comments with your rating so I can know how to help you or what might be wrong with the plugin.

I wrote a little change in check_page_count function:

function check_page_count(){
local PAGE_EXIT_CODE=0
PAGE_COUNT=$(snmpget -v1 -Ovq -c $COMMUNITY $HOST_NAME 1.3.6.1.2.1.43.10.2.1.4.1.1 2>/dev/null)

if [ "$PAGE_COUNT" -lt "$WARNING" ]; then
EXIT_STRING="Pagecount is $PAGE_COUNT - OK!$SEPARATOR"
else
if [ "$PAGE_COUNT" -ge "$WARNING" ] && [ "$PAGE_COUNT" -lt "$CRITICAL" ]; then
EXIT_STRING="Pagecount is $PAGE_COUNT - WARNING!$SEPARATOR"
PAGE_EXIT_CODE=1
else
if [ "$PAGE_COUNT" -ge "$CRITICAL" ]; then
EXIT_STRING="Pagecount is $PAGE_COUNT - CRITICAL!$SEPARATOR"
PAGE_EXIT_CODE=2
fi
fi
fi

PERFDAT="Pages;Warning;Critical=$PAGE_COUNT;$WARNING;$CRITICAL;"
return $PAGE_EXIT_CODE

}
So far so good. The only issue i'm running into is with the STATUS check. I setup services for three of my printers and i'm getting weird results. Nagios is giving me the following:

WARNING: Printer status is idle

When i do an SNMPwalk on 1.3.6.1.2.1.25.3.5.1.1.1 2 of that printer i get the following:

INTEGER: idle(3)

Looking at the script it appears i should be getting an OK: but i'm getting a WARNING: instead.

Here is my check command definition:

define command {
command_name check_snmp_printer
command_line $USER1$/check_snmp_printer -H $HOSTADDRESS$ -C $ARG1$ -x $ARG2$ -w $ARG3$ -c $ARG4$
}

And my service command:

define service {
service_description Status
check_command check_snmp_printer!public!STATUS!!
host_name media-stats-printer
event_handler_enabled 0
use generic-service
contact_groups +admins
}


Any advice would be greatly appreciated.

Thanks!
I really like this plugin! But could you first check if the printer reports a maximum capacity before dividing through it? On our Sharp MX-2300N there is no such value, therefore the script tries to divide by 0 for a few times.
bygarazh317, December 19, 2011
Hi! I tried to use this plugin on freesd 7.4 but i have that error UNKNOWN: check_snmp_printer: No usable 'xxd' binary in '/sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/sbin:/usr/local/bin:/root/bin'
bystijns, November 18, 2011
very nice plugin. However, there is a small bug: When a unknown tray or consumable is requested, the status information shows an error ("UNKNOWN - OID not found! Your printer may not support checking this consumable. Use the CONSUM TEST option to determine which consumables may be monitored.")
but: the status itself is "OK".

and 2 suggestions / feature requests:
-Can you refer to a tray or consumable by it's index in addition to it's name? I have a Brother B/W printer that returns 2 times a "black toner cartridge", one that is empty and another one with the correct information. But I can't point to the right one because they are named the same. And of course, the faulty one is the first one so that's the one CONSUMX returns.

-Can you exclude a certain tray or consumable together with the ALL statement? The manual paper tray is usually empty so will always return Critical. Excluding one is easier than specifying all but one tray.
byoricalco, November 15, 2011
thanks! your plug-in is just what I was searching for, but still I wanted to ask if you could please put the service definition for TRAY? it would be really useful. Also, are the service definitions you put for toner and model compatible with the 2.1 POSIX version or just the with the 3.14159 version?
if I have ubuntu is it recommendable to update or does the service definitions work either way? sorry if I'm making obvious questions its just that I am both an ubuntu and nagios noob and there is just too much I don't understand...
byzavisha, November 13, 2011
Looks great but i've got one problem with this.
printer.cfg
define service{
use generic-service
host_name hp1536dnf
service_description Toner Supply
check_command check_snmp_printer!192.168.115.70!public!CONSUM!20!10
normal_check_interval 10
retry_check_interval 1
}

commands.cfg
define command{
command_name check_snmp_printer
command_line $USER1$/check_snmp_printer -H $HOSTADDRESS -C $ARG1$ -x $ARG2 -w $ARG3$ -c $ARG4$
}

Nagios shows "WARNING: No SNMP response from -C! Make sure host is up and SNMP is configured properly."

Please, help
byHuerres, August 18, 2011
First of all give you many thanks for this excellent plugin. It is valid for many items of our printers.

I have a little problem. My commands.cfg I add:
#'check_printer' command definition
define command{
command_name check_printer
command_line $USER1$/check_printer -H $HOSTADDRESS$ -p $ARG1$ $ARG2$ $ARG3$
}
After this I add this to my printers.cfg:
define service{
use generic-service
host_name ljpm1217nfwmfp
service_description PS
check_command check_printer!-H 192.168.220.11 -C public -x "STATUS" -w WARNING -x CRITICAL -S / |-V|-h
normal_check_interval 1
retry_check_interval 1
}

But the Nagios webpage return me a "null". Can you help me please?

Thanks a lot,
Alex.
Owner's reply

As I noted in our e-mail correspondence, your syntax for running the command is incorrect. Please consult the documentation for more help, but the commands I provided you in e-mail should work.

Works well for 3 different brand network printers.
I had to make the following changes to get the plugin to run:
1. dos2unix
2. set bash as shell
3.put quotes around MARKER_COLOR to eliminate grep error messages
4.new line after here doc terminator

$ diff -b ../../Downloads/firefox/check_snmp_printer_args.sh /usr/lib/nagios/plugins/check_snmp_printer_args.sh
1c1
#!/bin/bash
495a496
> CURRENT_STATUS=0
561c562
if $(echo "$MARKER_NAME" | grep -vqi "$MARKER_COLOR"); then
1022c1023,1024
all_required_binaries
> )
Owner's reply

#1 should not be needed with the latest versions of the plugin, but yes I have received a few complaints about dos2unix before. That's what happens when I don't have a Linux workstation at my company :)

#2 is needed for Ubuntu machines, yes. All other distros use BASH or an interpreter that works with the plugin.

#3 should be fixed already in the latest version of the plugin.

I will have to investigate #4 but have not heard other complains about this.

by3mwhite, February 4, 2011
Any chance on us getting the config commands?

define service{
use generic-service
host_name SharpAr-m257
service_description PING
check_command check_ping!3000.0,80%!5000.0,100%
normal_check_interval 10
retry_check_interval 1
}


define command{
command_name check_local_users
command_line $USER1$/check_users -w $ARG1$ -c $ARG2$
}
bye314, November 29, 2010
Nice script, very useful.
byydduj, October 28, 2010
I tried to use 'iconv' to convert from UTF-8 to ASCII with no success.

Try: 'strings check_snmp_printer.sh > check_snmp_printer-ASCII.sh'

'file' now reports:
check_snmp_printer-ASCII.sh: POSIX shell script text executable
Owner's reply

Thanks for the note, is UTF format a problem for Linux? My CentOS server has never had a problem with it.

Unfortunately, I do most of my work, including file upload, on a Windows box. I do not have a Linux workstation at work and do no get to work on the plugin outside of work.