Overview
Paea LePendu, a Programmer Analyst for Whitman's Academic Technology,
wrote a program in 2002 that essentially asks printers, "What is
your current pagecount?" Every night at 5:00pm, a list of printers is fed into
the program and each printer's pagecount is stored in a log. The paper tracker
website uses Cold Fusion to generate graphs dynamically using the information
stored in the logs.
Technical Details
Below is the code that literally asks the printer, "What is your pagecount now?"
It saves the current time and the answer the printer gives in a file.
The program was written in Perl (requires the BER and SNMP_session Perl modules);
feel free to use this code (at your own risk.)
if ($session = SNMP_Session->open ($printer_IPaddress, "public", "161")) {
$oid1 = encode_oid (1,3,6,1,2,1,43,10,2,1,4,1,1);
if ($session->get_request_response ($oid1)) {
($bindings) = $session->decode_get_response ($session->{pdu_buffer});
while ($bindings ne '') {
($binding,$bindings) = &decode_sequence ($bindings);
($oid,$pagecount) = &decode_by_template ($binding, "%O%@");
if (open (APPENDDATA, ">>$logfilename")) {
print APPENDDATA $timestamp, "\t", &pretty_print ($pagecount), "\n";
close (APPENDDATA);
}
else { print "Couldn't open file $logfilename"; }
}
}
}
This code is the key to making this system work, everything else is just dressing.
It uses SNMP (Simple Network Management Protocol) which
is essentially a language every networked device talks these days. The trick is
knowing exactly what to ask the device for, and the secret is in knowing the
exact
OID (object id) to request. You can think of an object id as a post
office box number. In that post office box is a single piece of information. There
are literally millions of these object ids, so knowing the exact one is not as
easy as it seems. To let you in on the big secret, for most printers these days
the object id that stores the current pagecount is this
long series of numbers:
1,3,6,1,2,1,43,10,2,1,4,1,1.