SNMP Printer Check Authored by Jason Leonard E-mail: jason_leonard@yahoo.com Version History =============== 4.0 The main purpose of this release was to support SNMP v3 checking. Along the way, I discovered some much cleaner ways to code: passing SNMP checks off to a function, handling output more with snmpcmd, and having OID's as global variables. Some of these tricks come from Daniel DueƱas' check_ups_snmp plugin, others just from what I've learned the last few years. Also, I made argument passing more flexible, as I now can handle -- arguments and relaxed the need for parameters to be in ALL CAPS. Finally, after actually having USED perfdata for years now, I took the handling of perfdata more seriously and made the plugin report PERFDATA more cleanly. *** THE MOST IMPORTANT NOTE IS THIS ***: 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!!! ----------------------------------------------------------------- 3.141592 A minor update to the variable for handling the CONSUM ALL exit code. Apparently, assigning them as local did not keep the variable from getting confused with the one for the function that just checks one consumable. ----------------------------------------------------------------- 3.14159 A few fixes to code logic that I had not seen previously; mostly had to do with exit codes and strings ----------------------------------------------------------------- 3.1415 Restored snmp checking to version 1, as some printers (both old and new in our environment) did not seem to support it. ----------------------------------------------------------------- 3.14 Made code compatible with Ubuntu. Minor bug fixes were done on the STATUS check and reading in of POSIX parameters. All snmp checking is done with version 2c as well for (slightly) added security) The plugin is only available with xargs for now, as I'd like to keep it compliant to Nagios plugin development standards. ----------------------------------------------------------------- 2.1 The first big upgrade for 2.0 includes POSIX and Nagios compliant parameter passing (optional, if you down- loaded that version), many new checks, and a slight revision of code for handling consumables. As Martin Soltis informed me, some manufacturers do not put in the color of the consumable with the string used for my MARKER_NAME variable. However, other OIDs are still populated to provided this color. The plugin now checks these strings, and if necessary, adds them to the toner names. The new checks are DISPLAY, DEVICES and STATUS. The DISPLAY check will basically report back what is on the printer's display screen. The DEVICES check will show status of the printer's devices (hard drives, ethernet ports, drucker, etc.) Lastly, the STATUS check reports a basic status for the printer. For example, sometimes the printer could be responding to host checks, but the internal system is down for maintenance, idle, etc. This, along with the DEVICE check, should help you better assess your printer's true health. Thanks to user Schillo at the Nagios Exchange site for suggesting to add the new functions and providing a shell of the code. If you are trying to use the new parameters, or considering it, they are basically as such: -V display plugin version -h display help -H set IP of host to check -C SNMP community to check -x "" CONSUM,TRAY,MODEL, etc. -w warning (% consum. remain) -c critical (% consum. remain) BE SURE to include " around your check if you are using the CONSUM, CONSUMX or TRAY checks! ----------------------------------------------------------------- 2.0 Another huge update!!! First is a few basic code improvements. My conditional logic was updated in a few places where ifs were used in combination with case statements. A few changes were made to handle wrong user input in some areas. Added a global variable to control what character separates consumables on output, so strings returned to Nagios can still be to Nagios plugin development guidelines, or to my desired format. (a new line for each individual consumable) Second, I gave the TRAY status check a *HUGE* update. The dimension units were not queried right, and non-positive consumable values were not accounted for. It should not only work now but be faster - I stopped querying OIDs for info. if they weren't used in the final output! Most importantly, though, you can now pass a list of trays to the function (comma- separated), OR use "ALL"/"TEST" parameters that work like the consumable checks. And I was smart enough to treat these as loops on a "check_one" function! Yay! Of course, most devices have a manual tray that will always return CRITICAL, so be careful with the "ALL" parameter. That's why I allow a list to be passed - so you can check all trays but the manual. To give an example, on a basic HP printer with the 2nd 500-sheet tray, you can report on trays 2 and 3 in one swoop, but ignore manual tray 1. Your parameter would be like follows: TRAY 2,3 With lessons learned from the tray function, I re-coded the consumables to loop on a single check function also. Also, I realized I goofed in my programming skills again. In haste and frustration handling hex strings last version, I overlooked logic with the CONSUMX option. It allowed substrings ("Black" and not "Black Cartridge 1") to match and still work. It wasn't a bank breaker if the plugin was used right, but the logic was poor anyway. I made a mess trying to keep from looping through all consumables (and work faster), but the end results weren't as accurate as they should have been. So I rewrote the exact string matching to loop through all consummables. Last, but not least, a VERSION parameter was added so you can easily determine what plugin version you have if I need to update again. If you've used the plugin before, I'm sorry I have updated so much. I have had much work to do to get it to this point, and have resisted being more thorough with my code testing. I tested functions I use and didn't try all possible scenarios/inputs. However, I have been getting feedback from others using the plugin and I believe things are right now! ----------------------------------------------------------------- 1.9 Two major fixes for this release. Phew! I hope everyone using my plugin will update! First, our company bought a new HP printer, and when setup with this plugin, I noticed output I did not expect - hex bytes as strings for the consumables! Since the OIDs used are universal, I didn't expect this at all! But a bit of snmp-walking confirmed the consumable strings are Hex-STRINGS for this printer (and likely many other newer printers). So I re-wrote the plugin to check SNMP tables first and see if the strings are Hex. If so, the appropriate conv- ersions are done. This also meant rewriting the functions that matched any consumable strings. What a pain that become! I learned more about awk and bash expressions than I ever wanted! Second, while updating this plugin I discovered something I hadn't planned on. When I updated the plugin for the -On parameter of snmpwalk, I forgot it changes the of .'s in shell output! So my output manipulation for string-matching was mostly broken! I have adjusted for this and all should be okay. I tested all of the options for the plugin, using diff. inputs, and this plugin should be solid! All that said, I encourage anyone with better ideas, commands or algorithms to use, please let me know! I now realize how limited my Bash knowledge is, and at the same time just how versatile it is! I'm almost certain there are better solutions! ----------------------------------------------------------------- 1.6 Thanks to Martin Henja for pointing out a potential problem with handling of OIDs. Apparently this plugin would not work if the printer MIBs are on the system, as the snmp commands don't report numeric values (which throws off positioning and calculation of text strings) All snmp commands are updated to force a numeric return so my plugin can work consistently on any platform. ----------------------------------------------------------------- 1.5 It was brought to my attention that my comparisons to critical and warning levels were not INCLUSIVE of those levels. So, when toner level was reaching 5 or 20, the plugin was behaving oddly. This has been corrected now, and the plugin uses variables for WARNING and CRITICAL so the levels can be changed more easily. I plan to implement passing those levels to the plugin soon. ----------------------------------------------------------------- 1.4 After rewriting my string matching, it was brought to my attention that some consumables are not always repres- ented by a unique string, so exact matching on a string (the original intended purpose of the CONSUM option) was still needed. As a result, I added the new CONSUMX option. Essentially, CONSUMX looks for a consumable to have an EXACT match to the string passed to it. This allows the plugin to have the original functionality intended and the added functionality of output on all matches to a substring. ----------------------------------------------------------------- 1.3 I again rewrote the string matching for consumable checks. Now, it functions more like the CONSUM ALL check, except it loops on all matching strings. For example, on certain copiers, "CONSUM Yellow" will now report values for Yellow Toner, Yellow Imaging Unit and Yellow Drum. In a more handy use, CONSUM Toner would just report all toner levels, etc. This was done after I had to acknowl- edge that there is not always a unique string to match amongst consumables. ----------------------------------------------------------------- 1.2 Fixed a bug with handling the string matching on indiv- idual consumable checks. I was passing the string variable without "s, so the script was not parsing the string properly. Many thanks to Tobias Balle-Petersen for bringing this to my attention. ----------------------------------------------------------------- 1.1 Rewrote paper tray handling function. Now plugin uses 1 function instead of 3, with code to handle any paper tray. The function also calculates tray capacity as % to get more accurate status codes. The old plugin only looked for a -3 value, but many printers do use positive values to indicate number of pages, and would return errors before. I also updated the MESSAGES option to be able to handle null returns from printers that don't use this OID. Lastly, some code cleanup was in order with SNMP checks and other similar items. ----------------------------------------------------------------- 1.0 Initial release. Primarily rewrote multiple IF-THENs to be represented as CASE statements. -----------------------------------------------------------------