SNMP::NPAdmin - high-level API to query printers via SNMP
# object-oriented $p= SNMP::NPAdmin->new( printer => 'porky', community => 'corpslp' ); printf "Your printer, %s, does%s support PCL.\n", $printer, ( $p->pcl() ? "" : " not"); # procedural $p= npa_connect( printer => 'porky', community => 'corpslp' ); printf "Your printer, %s, does%s support PCL.\n", $printer, ( npa_pcl( $p) ? "" : " not");
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.
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
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
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 key is required; the constructor will fail without it.
$P= SNMP::NPAdmin->new( printer => 'mega-print', community => 'myhouse', );
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.
$P= npa_connect( printer => 'mega-print', community => 'myhouse', );
This method returns the version of SNMP::NPAdmin that is being used.
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 MIB queries determine whether or not the queried printer supports the MIB in question. Currently, SNMP::NPAdmin only asks about the Printer-MIB and the Host-Resources-MIB.
Answers the question, "Does the printer support the Printer-MIB?"
Answers the question, "Does the printer support the Host-Resources-MIB?"
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
Retrieves contact and location information as contained in
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).
The configuration source or method is determined as given by the HP private MIB OID
Attempts to determine the status of the printer from the Host-Resources-MID OID
Attempts to determine the amount memory in the printer from the Host-Resources-MID OID
Attempts to determine the network configuration of the printer from these MIB-2 OIDs:
Attempts to number of pages printed by the printer from the Printer-MIB OIDs
Attempts to determine the number of colors supported by the printer from the Printer-MIB OID
This returns the values for the Printer-MIB OIDs
??? I am not sure what they mean.
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
Determines the maximum speed that one of the media-paths provides from the Printer-MIB OID
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
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
The next set of queries merely return the contents of the Printer-MIB tables. Just for brevity, I will only list the method/subroutine names and the respective table OIDs.
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).
supports PJL printer language?
supports PCL printer language?
supports HPGL printer language?
supports PSPRINT printer language?
supports Postscript printer language?
automatically selects the appropriate language?
supports duplex printing?
supports letter papersize?
supports legal papersize?
supports executive papersize?
supports tabloid papersize?
supports a3 papersize?
supports a4 papersize?
supports b4 papersize?
supports b5 papersize?
supports Appletalk protocol?
supports LPD protocol?
supports Netware protocol?
supports port 9100 bidirectional connections?
Robert Lehr, firstname.lastname@example.org
I certainly would appreciate any feedback from people that use it, including complaints, suggestions or patches. Even people that don't use it are welcome to send comments.
Copyright (c) 2001 Robert Lehr. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Caveat emptor. Use this module at your own risk. I will accept no responsibility for any loss of any kind that is the direct or indirect result of the use of this module.
the SNMP module v3.1.0; the UCD SNMP library v4.2.0 at http://www.net-snmp.org/; RFC 1759 - The Printer MIB