The SNMP::NPAdmin package is a complete port of a SNMP/printer utility called npadmin that provides a high-level interface to query printers via SNMP without specific knowledge of SNMP MIBs or the printer's vendor-specific configuration.

The original npadmin was written in C++ by Ben Woodard who continues to maintain it on SourceForge.

The primary objective in this port is to have a maintainable and extensible version of the same functionality that the original npadmin provides.

It is not optimized for performance at all; it is optimized for extensibility and maintainability. The original npadmin is very much extremely performance, the idea being to query many printers very quickly, especially since SNMP can be quite slow.

To be fair, SNMP::NPAdmin might even be slow by Perl standards due to the extensive use of run-time compilation through the AUTOLOAD subroutine. I don't necessarily believe this since a programmer/sys-admin frequently will not use all of the available methods/subroutines which would typically be compiled during startup; given that only a few methods/subroutines will be called, then only a few will be compiled during the process's lifetime. Probably the difference in speed due to this will be insignificant either way.

The design was chosen in order to get as much information into a maintainable table format and make the logic as generic as possible; not for speed.

So this is your choice. If you have some unsupported printers and you want to be able to modify the code to support them then use SNMP::NPAdmin. If you need to support a lot of printers continuously with this kind of utility then you should use Ben Woodard's npadmin.

The SNMP::NPAdmin package is composed of a module, SNMP::NPAdmin, and a script, npadmin.pl. The heart of this package is the SNMP::NPAdmin module. Everything happens in the module. All that the script does is parse command-line arguments, call the SNMP::NPAdmin module and report the results. Actually, two modules are provided; but only one is publicly available. I will not even tell you its name; you can find it yourself if you're so curious.

The script is provide for two reasons. The first is to fulfill the original objective of writing a Perl-version of npadmin which is a command-line utility. The second is to provide an example script.

While writing this module, I received a lot a negative feedback about using OO techniques. Therefore I decided to ensure that it could be used by using both OO and procedural techniques.

It is probably true that most modules/classes are similarly Janus-faced since Perl always passes the object-reference (or class name) as the first argument. That is not so different from the way many procedural libraries work, particularly those that establish some kind of state such as network connections: initiate a connection and pass the returned struct to future library calls as the first argument.

NOTE!NOTE!NOTE!NOTE!NOTE!

The procedural API is not been fully implemented yet. But it is the current task and should be complete soon.

This is the constructor (duh!). It returns an SNMP::NPAdmin object which can then be queried with the object methods that are described below. For arguments, a hash is used which can include values for five keys: printer, community, port, timeout and retries. The printer key is required; the constructor will fail without it.

This is the procedural call to start a SNMP::NPAdmin session for a specific printer. It accepts the same arguments and returns the same results as the constructor. I didn't bother not blessing the reference just for a procedural call. It will still work when it is passed to the query subroutines.

This method toggles the 'verbose' flag for the entire class. All objects will verbosely report its progress during execution of any methods. The previous value of the 'verbose' flag is returned. Currently, the 'verbose' flag is ineffectual.

This method toggles the 'debug' flag for the entire class. All objects will report in painful detail everything that is happening during a SNMP::NPAdmin method call. The previous value of the 'debug' flag is returned. Currently, the 'debug' flag is ineffectual.

This method toggles the 'debugsnmp' flag for all objects/sessions. All objects will report in excruciating detail everything that happens during all actual SNMP transactions. This flag is actually used by the underlying SNMP module. It does work and very well.

The information queries provide information that requires additional processing in addition to merely querying the printer for data. For most of these, this does involve simply querying the printer and reporting the results. The ones that do require this kind of heuristics are vendor(), model(), netconfig(), enginespeed(), maxpapersize(), minpapersize().

Attempts to determine the vendor/manufacturer of the printer. Currently, only a few vendors can be reliably detected: HP, Tektronix, Lexmark, IBM, Xerox, EFI, Fuji and QMS. If a device can be determined to not be a printer then 'not_a_printer' is returned. If the vendor cannot be determined then 'unknown is returned. If you are able to determine an unsupported vendor then please send the information to me (see below).

Attempts to determine the model of the printer. The vendor is determined as the first step. So, this will only work for printers that are supported by the vendor() method. Even then, the module only guarantees its best-effort. If you are able to determine an unsupported model then please send the information to me (see below).

This really should be just margin since it is determined from the prtMarkerTable and most printers in use only have one marker. Nonetheless, this merely returns the margins for all of the markers in the printer from the Printer-MIB OIDs prtMarkerNorthMargin, prtMarkerSouthMargin, prtMarkerEastMargin and prtMarkerWestMargin.

Determines the largest paper-size that is supported by the printer. This does not reflect the largest size paper that is actually in the printer. By "largest" and "max", we mean the paper-size with the most area, as determined from the Printer-MIB OIDs prtMediaPathMaxMediaFeedDir and prtMediaPathMaxMediaXFeedDir.

Determines the smallest paper-size that is supported by the printer. This does not reflect the smallest size paper that is actually in the printer. By "smallest" and "min", we mean the paper-size with the least area, as determined from the Printer-MIB OIDs prtMediaPathMinMediaFeedDir and prtMediaPathMinMediaXFeedDir.

The truth queries answer a "Yes or No" question about the capabilities of the printer. The questions fall into one of several categories: languages (prtInterpreter), paper-size (prtMediaPath) or protocol (prtChannel).