Home Directory Plugins Hardware Printers SNMP Printer Check

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

SNMP Printer Check Popular

Network Monitoring Software - Download Nagios XI
Log Management Software - Nagios Log Server - Download
Netflow Analysis Software - Nagios Network Analyzer - Download
Rating
52 votes
Favoured:
9
Current Version
4.0
Last Release Date
2016-06-09
Compatible With
  • Nagios 3.x
  • Nagios 4.x
E-mail
License
GPL
Hits
1084981
Files:
FileDescription
check_snmp_printerVersion 3.141592 Script
check_snmp_printerVersion 4.0 Script
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.
*** LATEST CHANGES: SNMP v3 checking supported, with improvements to code and error handling. Also simplified output some and added ability to pass long style options (--).

---> IMPORTANT NOTE: Because snmp v3 checking uses -x for selecting a privacy protocol, -x is no longer the option for passing a check type. Instead, I've changed it to the more sensible -t option. This means your service command definitions need to be updated before you can use this plugin!!!

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 for SNMP v1/2c:
check-snmp_printer -H {host/IP} -t {type of check} [-C {SNMP community}] [-S] [-w] [-c]

Usage for SNMP v3:
check-snmp_printer -v 3 -H {host/IP} -t {type of check} -u {user} -x {protocol} -X {password} -a {protocol} -A {password} -l {security mode} [-S] [-w] [-c]

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

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 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.


Reviews (39)
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
}
bylehab, February 6, 2016
1 of 1 people found this review helpful
Works great!

Attention! There is two "$" signs missing in section "define command". Be attentive. It must be "define command{
command_name check_printers
command_line $USER1$/check_snmp_printer -H $HOSTADDRESS$ -C $ARG1$ -x $ARG2$ -w $ARG3$ -c $ARG4$
} "
bymammuthus, February 4, 2016
Guys, what's wrong?

error: Invalid check specified by -x parameter.

but from terminal is okay:
/etc/nagios-plugins/printer_status -H 192.168.0.197 -x "MODEL"
Samsung SCX-472x Series, Serial # Z8Z7BJDC400094K

define command:

define command{
command_name printer_status
command_line /etc/nagios-plugins/printer_status -H $HOSTADDRESS$ -C $ARG1$ -x $ARG2 -w $ARG3$ -c $ARG4$
}

service:
define service{
use generic-service
hostgroup_name printers
service_description Printer_Model
check_command printer_status!public!"MODEL"
}

I believe the wrong is check_command string. But it's the same as aytor's and autor can't lie to us.
bywizard210, January 11, 2016
I've been trying to get this to work on a Color Laserjet m451dn but each time I just recieve UNKNOW -OID not found! When I do CONSUM TEST I receive the same error. running the check from the terminal works just fine when I do it ./check_snmp_printer -H 192.168.4.50 -C public -x "CONSUM ALL" -w 20 -c 10

I'm stuck.
I don't have any luck in this. I always have this error when trying to restart the nagios service.

Could not find any host matching 'printer_groupmain' (config file '/etc/nagios3/conf.d/printers-service.cfg', starting on line 46)
Error: Could not expand hostgroups and/or hosts specified in service (config file '/etc/nagios3/conf.d/printers-service.cfg', starting on line 46)
Error processing object config files!

I have done everything correctly in command definition
define command{
command_name check_printer
command_line $USER1$/check_snmp_printer -H $HOSTADDRESS -C $ARG1$ -x $ARG2 -w $ARG3$ -c
}

It even works in the /usr/lib/nagios/plugins if i run the command manually, however i can't run it normally in /etc/nagios3/conf.d.
Appreciate anyone advice on this?

Thanks.
Good Script, Very helpful.
I only had some problems with the STATUS and PAGECOUNT.

The STATUS Problem I solved with the help of a previous review, that you had to change "idle(3)"); to "idle"). After I made that change it worked fine.

The PAGECOUNT problem wasn't really a problem but more like it was missing something. The PAGECOUNT showed me the total number of pages printed color and black together.

But I wanted to see the color PAGECOUNT and black PAGECOUNT separately,
So I had to make some changes to the script.

The original PAGECOUNT function looks like this:

function check_page_count(){
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 | sed -e :x -e 's/\([0-9][0-9]*\)\([0-9][0-9][0-9]\)/\1,\2/' -e 'tx')

EXIT_STRING="Pagecount is $PAGE_COUNT"
PERFDAT="Pages=$PAGE_COUNT;"
return 0
}

The long number (1.3.6.1.2.1.43.10.2.1.4.1.1 2) is a OID, an OID is object identifier and this one is used to get the PAGECOUNT Total.

But like I said I wanted to see the PAGECOUNT for color and Black separately, so I did some research of what the OID's are for this and I found them on an forum.

1.3.6.1.4.1.253.8.53.13.2.1.6.1.20.33(COLOR)
1.3.6.1.4.1.253.8.53.13.2.1.6.1.20.34(BLACK)

I think they are officially for a Xerox Printer, but I think they will also work for other printers you just have to test. I didn't have any other printers available then Xerox.

So the changes is made are this:

function check_page_count1(){
PAGE_COUNT=$(snmpget -v1 -Ovq -c $COMMUNITY $HOST_NAME 1.3.6.1.4.1.253.8.53.13.2.1.6.1.20.33 2>/dev/null | sed -e :x -e 's/\([0-9][0-9]*\)\([0-9][0-9][0-9]\)/\1,\2/' -e 'tx')
EXIT_STRING="Pagecount is $PAGE_COUNT"
PERFDAT="Pages=$PAGE_COUNT;"
return 0
}

function check_page_count2(){
PAGE_COUNT=$(snmpget -v1 -Ovq -c $COMMUNITY $HOST_NAME 1.3.6.1.4.1.253.8.53.13.2.1.6.1.20.34 2>/dev/null | sed -e :x -e 's/\([0-9][0-9]*\)\([0-9][0-9][0-9]\)/\1,\2/' -e 'tx')
EXIT_STRING="Pagecount is $PAGE_COUNT"
PERFDAT="Pages=$PAGE_COUNT;"
return 0
}
function check_page_count3(){
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 | sed -e :x -e 's/\([0-9][0-9]*\)\([0-9][0-9][0-9]\)/\1,\2/' -e 'tx')
EXIT_STRING="Pagecount is $PAGE_COUNT"
PERFDAT="Pages=$PAGE_COUNT;"
return 0
}

As you can see the commands stay the same only OID changes and the name of the function. I kept the original PAGECOUNT for the total number.

After you have done this you will need to changes the main code, you will have to add the commands to name you can use.

You will need to make the following changes around line 880:

else
STRING_TYPE=$(echo "$ALL_MARKERS" | tr -d "\n" | cut -d " " -f3)
case "$CHECK" in
"MESSAGES")
check_messages
;;
"MODEL")
check_model
;;
"CONSUM")
check_consumables "$PARAMETER"
;;
"CONSUMX")
check_exact_consumable "$PARAMETER"
;;
"TRAY")
check_paper_trays "$PARAMETER"
;;
"PAGECOUNTCOLOR")
check_page_count1
;;
"PAGECOUNTBLACK")
check_page_count2
;;
"PAGECOUNTTOTAL")
check_page_count3
;;
"DEVICES")
check_device_status
;;
"STATUS")
check_printer_status
;;
"DISPLAY")
check_display
;;
*) # no parameters were passed, or a parameter was incorrect (wrong spelling, etc.)
echo 'Invalid check specified by -x parameter.'
echo ''
print_help
;;
esac

EXIT_CODE=$?

As you can see I have added PAGECOUNTCOLOR, PAGECOUNTBLACK and PAGECOUNTTOTAL, so when you have made these changes you can also put the help function.

You will get something like this:

echo ''
echo ' PAGECOUNTTOTAL'
echo ' How many pages this printer has processed for black and color'
echo ''
echo ' PAGECOUNTBLACK'
echo ' How many pages this printer has processed for black'
echo ''
echo ' PAGECOUNTCOLOR'
echo ' How many pages this printer has processed for color'


That's all the changes I made, I just find it handy to know all the number instead of just the total one.

And I wanted to post it here so maybe more people can use it so they don't have to search for it on google.

Maybe it's a thing for in the next version.
I'm using FAN (Nagios Core 3.4.4)

/etc/nagios/objects/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$
}

/etc/nagios/objects/command-plugins.cfg

command[check_snmp_printer]=/usr/lib64/nagios/plugins/check_snmp_printer -H $HOSTADDRESS$ -C $ARG1$ -x $ARG2$ -w $ARG3$ -c $ARG4$

/etc/nagios/objects/printer.cf

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

When I run the command manually on the server it works fine

#./check_snmp_printer -H 192.168.4.50 -C public -x "CONSUM ALL" -w 20 -c 10

Black Toner [K] Cartridge;SN1220AA80E00004A0 is at 99% - OK! Yellow Toner [Y] Cartridge;SN04156480E0000478 is at 89% - OK! Magenta Toner [M] Cartridge;SN11338080E0000479 is at 83% - OK! Cyan Toner [C] Cartridge;SN0F2DD980E000047A is at 82% - OK! Waste Toner Container is OK! Black Drum Cartridge is at 93% - OK! Yellow Drum Cartridge is at 72% - OK! Magenta Drum Cartridge is at 71% - OK! Cyan Drum Cartridge is at 72% - OK! | Black Toner [K] Cartridge;SN1220AA80E00004A0=99;20;10; Yellow Toner [Y] Cartridge;SN04156480E0000478=89;20;10; Magenta Toner [M] Cartridge;SN11338080E0000479=83;20;10; Cyan Toner [C] Cartridge;SN0F2DD980E000047A=82;20;10; Waste Toner Container=-3;20;10; Black Drum Cartridge=93;20;10; Yellow Drum Cartridge=72;20;10; Magenta Drum Cartridge=71;20;10; Cyan Drum Cartridge=72;20;10;

However it doesn't work through nagios
I get this (even when I use CONSUM TEST instead of CONSUM ALL)
UNKNOWN - OID not found! Your printer may not support checking this consumable. Use the CONSUM TEST option to determine which consumables may be monitored.

and I also got this error initially
No SNMP response from 192.168.x.x! Make sure host is up and SNMP is configured properly.
Once again works fine manually when using check_snmp_printer in a shell
byjat_nagiosexchange, February 2, 2015
I've modded this slightly to return a status of 'Unknown' rather than 'Warning' when the check gets no response from the printer. After line 860, I changed:
EXIT_CODE=1
to:
EXIT_CODE-3

We have lots of printers, and end users often like to switch them off. With the above change, it makes it much easier to see actual warnings for low toners, etc. rather than them being lost amongst lots of 'No SNMP response' type messages.

In a school with lots of different types and ages of colour printers, this plugin is incredibly useful due to its versatility and ease of use. It saves a lot of leg work!!
Hey,

While th eplugin works with my Xerox printers, i always receive:
WARNING: No SNMP response from 10.7.161.208! Make sure host is up and SNMP is configured properly.

from a Canon iR-ADV C5030. I have configured SNMP and the host is UP.
bymarcgpx, October 1, 2014
Saves me a lot of time! Great Work
byshiz0, September 24, 2014
Great script, all is working well, except for STATUS.
It kept returning WARNINGS:

# snmpget -v 1 x.x.x.x -c xxxx 1.3.6.1.2.1.25.3.5.1.1.1
HOST-RESOURCES-MIB::hrPrinterStatus.1 = INTEGER: idle(3)

# ./check_snmp_printer -H x.x.x.x -C xxxx -x "STATUS"
WARNING: Printer status is idle


It seems like the script didnt trigger the idle case (line 268),
but jumped stright to *) (line 277).

I'm not that familiar with bash scripting but I played around a bit when I changed line 268 from
"idle(3)")
to
idle)
it worked as expected and now I got:

# ./check_snmp_printer -H x.x.x.x -C xxxx -x "STATUS"
OK: Printer status is idle

I think maybe the output is different for different printers,
so I changed it again to
idle|3|"idle(3)") --> idle OR 3 OR idle(3)
and it still works like a charm (at least on our 3 DELL printers, tests on the big Xerox machine are up later).

Regards,
shiz0
Great script.

As a previous reviewer mentioned, the STATUS command is coming up as WARNING:Printer is Idle.

Any thoughts or solutions on this?
The script does very fine, I am very happy to use it. But there is still a little problem with Utax CD1120 printers (We got two in our enviroment).

The "Toner Container" is always 600 %. No percentage more or less.

But maybe this is not a script related problem because i did not found any toner capacity information on the web-gui too.
byfeltel, June 4, 2014
I´m using your plugin since some time to monitor consumables of our corporate printers. It works very well. We recently purchased an Brother HL-5350DN which seems to have some Bugs in its Firmware (shipped with latest available one, version 1.18; downgrade not available/possible). For the black toner cartridge (the only one in this printer) there are two states reported like this:

Black Toner Cartridge is OK! Black Toner Cartridge is at CRITICAL level! Drum Unit is at 99% - OK! | Black Toner Cartridge=-3;20;5; Black Toner Cartridge=0;20;5; Drum Unit=99;20;5;

Reason for this is, that the machine claims it has two cartridges:

~ snmpwalk -v1 -Ovq -c public MY-PRINTER-IP 1.3.6.1.2.1.43.11.1.1.6.1
"Black Toner Cartridge"
"Black Toner Cartridge"
"Drum Unit"

My question is if you could filter out duplicate consumables in some sort of way? This could work as some sort of work-around for this type of bugs.

Thanks alot.
One small issue I had is some Fuji Xerox printers return the serial number of the toner cartridge in the output, however they include a semi colon ";"

This completely breaks nagiosgraph's ability to graph them.

I added

MARKER_NAME=${MARKER_NAME//;/" "}

to check_one_consumable to replace the all semi colons with spaces to correct this
@eby: You say you ran into the no xxd error and "I'm guessing this was the problem the one star reviewer encountered. bc is in portage and the pentoo overlay has xxd. Once I installed both of these the script ran fine."

Could you elaborate on how you installed xxd? I am getting the no xxd error but haven't the slightest idea how to install xxd as I am not remotely experienced with Linux.

Thanks!
byrendicott, April 12, 2013
1 of 1 people found this review helpful
Great script!

@zarisha
To avoid the "WARNING: No SNMP response from -C! Make sure host is up and SNMP is configured properly." message make sure that you add the additional $ after "$HOSTADDRESS" in the command definition. The OP was missing it and it fixed my problem.

The following line in the OP:
command_line $USER1$/check_snmp_printer -H $HOSTADDRESS -C $ARG1$ -x $ARG2 -w $ARG3$ -c

Should be:
command_line $USER1$/check_snmp_printer -H $HOSTADDRESS$ -C $ARG1$ -x $ARG2 -w $ARG3$ -c
byfibercool, March 12, 2013
Any idea why im getting the consumables names in HEX instead in ascii format, for example like this:

Consumables you may Monitor:
42 6C 61 63 6B 20 43 61 72 74 72 69 64 67 65 20
43 45 32 35 35 41 00

I'm getting same thing with different HP models.
bymilda, January 29, 2013
Printer Oki C5700 returns same names of consumables without colour:

SNMPv2-SMI::mib-2.43.11.1.1.6.1.1 = STRING: "Toner Cartridge OKI DATA CORP"
SNMPv2-SMI::mib-2.43.11.1.1.6.1.2 = STRING: "Toner Cartridge OKI DATA CORP"
SNMPv2-SMI::mib-2.43.11.1.1.6.1.3 = STRING: "Toner Cartridge OKI DATA CORP"
SNMPv2-SMI::mib-2.43.11.1.1.6.1.4 = STRING: "Toner Cartridge OKI DATA CORP"
SNMPv2-SMI::mib-2.43.11.1.1.6.1.5 = STRING: "Image Drum Unit OKI DATA CORP"
SNMPv2-SMI::mib-2.43.11.1.1.6.1.6 = STRING: "Image Drum Unit OKI DATA CORP"
SNMPv2-SMI::mib-2.43.11.1.1.6.1.7 = STRING: "Image Drum Unit OKI DATA CORP"
SNMPv2-SMI::mib-2.43.11.1.1.6.1.8 = STRING: "Image Drum Unit OKI DATA CORP"

Colours are named in MarkerColorantTable:
SNMPv2-SMI::mib-2.43.12.1.1.4.1.1 = STRING: "black"
SNMPv2-SMI::mib-2.43.12.1.1.4.1.2 = STRING: "cyan"
SNMPv2-SMI::mib-2.43.12.1.1.4.1.3 = STRING: "magenta"
SNMPv2-SMI::mib-2.43.12.1.1.4.1.4 = STRING: "yellow"
byrdc_scase, October 8, 2012
Thank you Jason for the plugin. It is making my job alot easier!
Page 1 of 2