in reply to Where is the bug in this Net::SNMP code?

I had a look at your code. There could be many problems as you have not described what errors or symptoms you're receiving.

First, the good news. You've got lots of error checking there and die statements to protect you from bad coding. Well done, I can only encourage this!

The bad news: you do a getnext on sysName. Thus I presume you will get sysName.0 because all scalar SNMP objects (ie objects that are NOT columnar), by definition, have a trailing .0 in the object identifier.

However, assuming sysName is a columnar object, you still have problems because you're assuming that the sysName column is in the same table as the prtCoverStatus. And they clearly are NOT in the same table because their OIDs (object identifiers) are different lengths let alone in different parts of the address space.

I could be wrong, however. Maybe the sysName object is in a table with an index of type OCTET STRING. So you're trying to capture the name of a device from the table the sysName object is in and then look in the table the prtCoverStatus object is in that is presumably indexed by device name as an OCTET STRING too???

Can you see that you need to assist us by describing a) what is your objective and b) how, specifically, is this failing?


Lastly - the last line of your script closes your SNMP object after it first discovers an answer. Is this what you mean to do? Or do you mean to close the SNMP object AFTER polling ALL devices?

Replies are listed 'Best First'.
Re^2: Where is the bug in this Net::SNMP code?
by tolyan77 (Novice) on Oct 10, 2006 at 08:42 UTC
    "Lastly - the last line of your script closes your SNMP object after it first discovers an answer. Is this what you mean to do? Or do you mean to close the SNMP object AFTER polling ALL devices?"
    monarch i don't understand your question:(
Re^2: Where is the bug in this Net::SNMP code?
by tolyan77 (Novice) on Oct 10, 2006 at 10:13 UTC
    monarch
    Prompt how to take data from .1.3.6.1.2.1.25.3.5.1.2 if it OCTET STRING
    hrPrinterDetectedErrorState OBJECT-TYPE SYNTAX OCTET STRING MAX-ACCESS read-only STATUS current DESCRIPTION "This object represents any error conditions detected by the printer. The error conditions are encoded as bits in an octet string, with the following definitions: Condition Bit # lowPaper 0 noPaper 1 lowToner 2 noToner 3 doorOpen 4 jammed 5 offline 6 serviceRequested 7 inputTrayMissing 8 outputTrayMissing 9 markerSupplyMissing 10 outputNearFull 11 outputFull 12 inputTrayEmpty 13 overduePreventMaint 14 Bits are numbered starting with the most significant bit of the first byte being bit 0, the least significant bit of the first byte being bit 7, the most significant bit of the second byte being bit 8, and so on. A one bit encodes that the condition was detected, while a zero bit encodes that the condition was not detected. This object is useful for alerting an operator to specific warning or error conditions that may occur, especially those requiring human intervention." -- 1.3.6.1.2.1.25.3.5.1.2 ::= { hrPrinterEntry 2 }
    It is possible an example of a code?
    Please help me out. thanks in advance.
      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

      • the IP address you're polling is that of a printer
      • you don't need to know the name of the printer
      • you just want the information from the printer

      You want to poll two objects. From the RFC:

      This is a table, indexed by two integers.

      To read this table I would do the following:

      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)
        extracted from rfc2790.txt
        Hi all. I neew you wisdom. I'm going to pool status information from network printers. I'm using code:
        foreach my $k (@ips) { my $hostname = "10.0.0.$k"; my $password = "public"; my ( $session, $error ) = Net::SNMP->session ( Hostname => $hostname, +Community => $password , Version => 1 ); if (!defined($session)) { printf("ERROR: %s.\n", $error); next; } }
        in @ips I have last octet of IP's The problem is if one of the printer is swiched off the programm break Could you tell me what I'm doing wrong? Thanks in advance!