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

Directory Tree

SNMP Printer Check Popular

Rating
64 votes
Favoured:
13
Current Version
4.0
Last Release Date
2016-06-09
Compatible With
  • Nagios 3.x
  • Nagios 4.x
License
GPL
Hits
1236753
Files:
FileDescription
check_snmp_printerVersion 3.141592 Script
check_snmp_printerVersion 4.0 Script
check_snmp_printer_versions.txtVersion History
Network Monitoring Software - Download Nagios XI
Log Management Software - Nagios Log Server - Download
Netflow Analysis Software - Nagios Network Analyzer - Download
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 (50)
byjpcozar, August 10, 2022
It is a very complete plugin, working in 2022 with Nagios Core 4.4.6.
Most of options were working except for partial searchings like "CONSUM ". I was getting no output.

I had to change line 670 from:
for MARKER_ID in $(echo "$MARKERS_MATCHED" | awk -F. '{print $8}' | awk -F= '{print $1}')

to:
for MARKER_ID in $(echo $MARKERS_MATCHED|sed 's/Printer/\nPrinter/g'|sed '/^$/d'|awk -F= '{print $1}'|awk -F. '{print $NF}')

So I got the MARKER_IDs and got the match.

Congrats!
byj03man, October 20, 2021
Works great! I just finished setting it up for 2 Konica Minolta C458.
I have the following check set up:
$USER1$/check_snmp_printer -H $HOSTADDRESS$ -C public -w 10 -c 5 -t "CONSUM ALL"

For most printers it's fine. But for one it returns:
UNKNOWN - OID not found! Your printer may not support checking this consumable. Use the CONSUM TEST option to determine which consumables may be monitored.Tray 1 Roller Kit HP Z7Y88A is at 99% - OK!,Tray 2 Roller Kit HP Z9M01A is at 99% - OK!, 'Tray 1 Roller Kit HP Z7Y88A'=99;10;5 'Tray 2 Roller Kit HP Z9M01A'=99;10;5

Is there a way to filter out that unknown OID responses without having to define the checks each individual printer accepts? All printers are quite new HP printers. The one causing this problem is an HP E87640
by42bios, April 24, 2019
1 of 1 people found this review helpful
For working Perfdata for Page Counter, I changed the following lines:

297: PERFDATA="'Pages'=$PAGE_COUNT [c]"
298: PAGE_COUNT=$(echo $PAGE_COUNT | sed -e :x -e 's/\([0-9][0-9]*\)\([0-9][0-9][0-9]\)/\1.\2/' -e 'tx')

->in use with HP and Xerox printers.
byimarkovic, February 12, 2019
Hello Nagios team,

Salut to everyone and thanks for this plugin, espetially Mr Leonard as a creator.
I write because I have some struggling with snmp v. 3 from past day. snmp v. 1/2 is working great, but I need to use v.3 with hp M527 enterprise printer. I know this is not support section, but I need just something to go on if it`s ok.
As I said, snmp 2 is ok and its working with Nagios Core 4 - CentOS 7.

When I type from command:
./check_snmp_printer -H 192.168.2.10 -t MODEL -u user -x DES -X password -a MD5 -A password -l authPriv

I only get "Plugin check_snmp_printer failure - snmpwalk command error.
This must be working in order to go on and implement it on Nagios monitoring.

Thanks,
cheers!
tried to implement the plugin into Icinga2 but didnt work. Worked fine on Nagios Core 4
Not sure if its because I'm using Icinga2 or something else. via command line everything works great, but get via icingaweb2 i see permission denied errors on all my 3rd party mibs
bylangejunior, April 25, 2017
1 of 1 people found this review helpful
Hi, if you try to use --community instead of -C in the command you get an error, because in

while test -n "$1"; do
case "$1" in
...
--comunity|-C)
COMMUNITY=$2
shift
;;

change it to --community and it will work :-)
byrnicksic, February 23, 2017
1 of 1 people found this review helpful
I had to add the parameter for CONTEXT (-n) in order to use SNMP v3 with Konica-Minolta bizhub C284 printers.

--- /home/rnicksic/check_snmp_printer 2017-02-23 10:08:16.821478951 -0600
+++ check_snmp_printer 2017-02-23 11:53:04.914467280 -0600
@@ -890,7 +890,7 @@ walk_snmp(){
fi

if [[ $SNMPVERSION = 3 ]]; then
- RESULT_TEXT=`snmpwalk -v $SNMPVERSION $OUTPUT_OPTIONS -u $SNMPUSER -l $PRIVILEGELEVEL -x $PRIVACYPROTOCOL -X $PRIVACYPASSWORD -a $AUTHPROTOCOL -A $AUTHPASSWORD $HOST_NAME $1`
+ RESULT_TEXT=`snmpwalk -v $SNMPVERSION $OUTPUT_OPTIONS -u $SNMPUSER -n $CONTEXT -l $PRIVILEGELEVEL -x $PRIVACYPROTOCOL -X $PRIVACYPASSWORD -a $AUTHPROTOCOL -A $AUTHPASSWORD $HOST_NAME $1`
RESULT_CODE=$?
else
# Check if community was also set
@@ -989,6 +989,10 @@ while test -n "$1"; do
PRIVACYPASSWORD=$2
shift
;;
+ --context|-n)
+ CONTEXT=$2
+ shift
+ ;;
--type|-t) # Assign check to perform
CHECK_TYPE=$(echo "$2" | cut -d " " -f1)
PARAMETER=$(echo "$2" | cut -d " " -f2-)
byandrebo, January 30, 2017
Hello,

Does the plugin work for HP Color Laserjet CP2025dn?

I am giving the command below and it is giving error

Root @ srvnagios: / usr / local / nagios / libexec # ./check_snmp_printer -H 192.168.0.199 -C public -t "CONSUM Black Cartridge" -w 30 -c 10
Timeout: No Response from 192.168.0.199
Plugin check_snmp_printer failure - snmpwalk command error.
bybpb21, November 14, 2016
Looks like an awesome plugin and would save a lot of time, but I can't figure out how to set up checks that require more than one word. Specifically, checking CONSUM ALL and TRAY ALL from the command line works excellently. I can't get them configured correctly in the Nagios config files. They invariably return errors such as "UNKNOWN: No valid check type specified to -t parameter". I don't know how to add anything with a space (single and double quotes return errors). But, the single word checks work fine!
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.
Page 1 of 3