#!/usr/common/bin/perl #use diagnostics; use strict; use lib qw(. /usr/local/netprint/lib); use npparams; use npstatlib; use SNMP_mib; use SNMP_Session; use BER; #system("scp1 page2.cit.cornell.edu:/var/netprint/spool/PRTCFG /tmp/PRTCFG.tmp"); $PRTCFG = "/tmp/PRTCFG.tmp"; # non-exported but global to the package: use vars qw{ $PSTAT_SERVICE_REQ $PSTAT_OFFLINE $PSTAT_PAPER_JAM $PSTAT_DOOR_OPEN $PSTAT_TONER_OUT $PSTAT_TONER_LOW $PSTAT_PAPER_OUT $PSTAT_PAPER_LOW $PSTAT_IDLE $PSTAT_PRINTING $PSTAT_WARMING_UP $PSTAT_UNREACHABLE $PSTAT_MAX %statmsg %prtstatmsg }; # Note: The bit definitions for the first 8 of the items below are taken # from the description of the values for hrPrinterDetectedErrorState in # RFC1759. BEGIN { $PSTAT_SERVICE_REQ = 1; $PSTAT_OFFLINE = 2; $PSTAT_PAPER_JAM = 4; $PSTAT_DOOR_OPEN = 8; $PSTAT_TONER_OUT = 16; $PSTAT_TONER_LOW = 32; $PSTAT_PAPER_OUT = 64; $PSTAT_PAPER_LOW = 128; $PSTAT_IDLE = 256; $PSTAT_PRINTING = 512; $PSTAT_WARMING_UP = 1024; $PSTAT_UNREACHABLE = 2048; $PSTAT_MAX = 2048; %statmsg = ( $PSTAT_SERVICE_REQ, 'Service Requested', $PSTAT_OFFLINE, 'Offline', $PSTAT_PAPER_JAM, 'Paper Jam', $PSTAT_DOOR_OPEN, 'Door Open', $PSTAT_TONER_OUT, 'Toner Out', $PSTAT_TONER_LOW, 'Toner Low', $PSTAT_PAPER_OUT, 'Paper Out', $PSTAT_PAPER_LOW, 'Paper Low', $PSTAT_IDLE, 'Idle', $PSTAT_PRINTING, 'Printing', $PSTAT_WARMING_UP, 'Warming Up', $PSTAT_UNREACHABLE, 'DISCONNECTED, OFFLINE, OR NOT RESPONDING', ); %prtstatmsg = ( 3, $PSTAT_IDLE, 4, $PSTAT_PRINTING, 5, $PSTAT_WARMING_UP, ); } my(%pinfo); my(@printers); my($status, $printer); $| = 1; if ( $#ARGV < 0 ) { if ( ! defined(%pinfo = get_allprinterinfo()) ) { print "get_allprinterinfo returned an error\n"; } @printers = sort keys %pinfo; } else { @printers = @ARGV; } foreach ( @printers ) { print "Printer: $_\n"; if ( $#ARGV < 0 ) { $printer = $pinfo{$_}{IP}; } else { $printer = $_; } $status = get_psatus($printer); my($bits) = ''; my($i); for ( $i = 1; $i <= $PSTAT_MAX; $i <<= 1 ) { $bits = ($i & $status ? '1' : '0') . $bits; } print " Error Code: $status = $bits\n"; print " Printer Status:\n"; my(@msgs) = err2str($status); foreach ( @msgs ) { print " $_\n"; } } exit(0); ######################################################## # get_psatus($ip) # # Uses SNMP to find the status and returns an errorcode # which can be deciphered in err2str, which will return an array of # strings specifying the error(s) occuring. sub get_psatus { my($ip) = @_; my($community, $session, $type, $devstat, $prtstat, $error, $mem, $counter); $community = 'public'; # The following line can be commented out for debugging purposes. $SNMP_Session::suppress_warnings = 1; snmp_initmib(); if ( ! ($session = SNMP_Session->open ($ip, $community, 161)) ) { warn "Couldn't open SNMP session to $ip: $SNMP_Session::errmsg"; return($PSTAT_UNREACHABLE); } $session->set_retries(2); ($type, $devstat, $prtstat, $error, $mem, $counter) = snmp_get($session, qw(sysDescr.0 hrDeviceStatus.1 hrPrinterStatus.1 hrPrinterDetectedErrorState.1 hrMemorySize.0 prtMarkerLifeCount.1.1)); if ( ! defined($type) ) { return($PSTAT_UNREACHABLE); } if ( $type =~ /^HP/ or $type eq '131;he0007156;' ) { ($type) = snmp_get($session, qw(hrDeviceDescr.1)); } my($tmp) = unpack("C", $error); if ( defined($prtstatmsg{$prtstat}) ) { $tmp |= $prtstatmsg{$prtstat}; } print " Type: $type\n"; print " Memory: $mem\n"; print " Page Counter: $counter\n"; return($tmp); } .