It appears you have little understanding of SNMP in general. The hrPrinterDetectedErrorState object is defined in RFC1759 (the RFC is more readable at this link).

I presume you wish to poll printer information using SNMP.

I assume that

You want to poll two objects. From the RFC:

prtCoverEntry OBJECT-TYPE SYNTAX PrtCoverEntry MAX-ACCESS not-accessible STATUS current DESCRIPTION "Information about a cover or interlock. Entries may exist in the table for each device index whose device type is `printer'." INDEX { hrDeviceIndex, prtCoverIndex } ::= { prtCoverTable 1 } prtCoverDescription OBJECT-TYPE SYNTAX OCTET STRING (SIZE(0..255)) MAX-ACCESS read-only STATUS current DESCRIPTION "The manufacturer provided cover sub-mechanism name in the localization specified by prtGeneralCurrentLocalization." ::= { prtCoverEntry 2 } prtCoverStatus OBJECT-TYPE -- This value is a type 2 enumeration SYNTAX INTEGER { other(1), doorOpen(3), doorClosed(4), interlockOpen(5), interlockClosed(6) } MAX-ACCESS read-only STATUS current DESCRIPTION "The status of this cover sub-unit." ::= { prtCoverEntry 3 }

This is a table, indexed by two integers.

To read this table I would do the following:

use Net::SNMP; use strict; my %oid = ( prtCoverStatus => '1.3.6.1.2.1.43.6.1.1.3', prtCoverDescription => '1.3.6.1.2.1.43.6.1.1.2', ); my %prtCoverStatusEnum = ( 1 => 'other(1)', 3 => 'doorOpen(3)', 4 => 'doorClosed(4)', 5 => 'interlockOpen(5)', 6 => 'interlockClosed(6)', ); sub query_printer( $ ) { my ( $printer_ip ) = @_; my ( $session, $error ) = Net::SNMP->session( -hostname => $printer_ip, -community => 'public', -version => 1, ); die( "Could not create session: $error" ) if ( ! $session ); my $index = "0"; while ( 1 ) { my @oidlist = ( $oid{prtCoverStatus} . ".$index" ); my $result = $session->get_next_request( -varbindlist => \@oidlist, ); if ( ! $result ) { last; # maybe there are no more objects } # we expect just one key to be returned my $prtCoverStatus = undef; foreach ( keys %{$result} ) { if ( $_ =~ m/^\Q$oid{prtCoverStatus}\E\.([^.])\.([^.])+$/ ) { my $hrDeviceIndex = $1; my $prtCoverIndex = $2; $index = "$hrDeviceIndex.$prtCoverIndex"; $prtCoverStatus = $result->{$_}; last; } } if ( ! $prtCoverStatus ) { last; # we've probably come to the end of the table } # now get other objects from the SAME TABLE @oidlist = ( $oid{prtCoverDescription} . ".$index" ); $result = $session->get_request( -varbindlist => \@oidlist, ); if ( ! $result ) { die( "Error getting object with index $index: " . $session->error() ); } my $prtCoverDescription = $result->{$oidlist[0]}; if ( exists( $prtCoverStatusEnum{$prtCoverStatus} ) ) { $prtCoverStatus = $prtCoverStatusEnum{$prtCoverStatus}; } print( "Cover description: $prtCoverDescription\n" ); print( " status: $prtCoverStatus\n" ); print( "\n" ); } # while there are rows in the SNMP cover table $session->close(); } # query_printer foreach ( "10.0.0.11", "10.0.0.12" ) { print( "QUERYING PRINTER $_\n" ); query_printer( $_ ); }

The output I get when querying the printer on my local LAN is:

C:\temp>perl -w checkprintercover.pl Cover description: Copier cover status: doorClosed(4) Cover description: Finisher cover status: doorClosed(4)

In reply to Re^3: Where is the bug in this Net::SNMP code? by monarch
in thread Where is the bug in this Net::SNMP code? by tolyan77

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.