snmpsharpnet

Dealing with an incrementing SNMP OID?


I'm trying to use SNMP to get data from a printer. If I turn the printer off and on, the OID that I need to get is .1.3.6.1.2.1.43.18.1.1.8.1.1. Each time the printer has an "event", such as getting paused, running out of paper or having a paper jam, the OIDfor the data I want increments.

For example, I turn the printer on and query .1.3.6.1.2.1.43.18.1.1.8.1.1. and I get "paused" as the value. I unpause the printer and remove all of the paper from the printer, and to get the "add paper" message I have to query .1.3.6.1.2.1.43.18.1.1.8.1.2.

I don't know if this is normal SNMP behavior but I wonder what people suggest I do in these cases to be able to programatically get the printer state?


Solution

  • Yes it's normal you are retreiving rows from an alert table :

    Just have a look to the mib :

    enter image description here

    The corresponding text part of the mib is (from RFC 1759):

    prtAlertTable OBJECT-TYPE
        SYNTAX     SEQUENCE OF PrtAlertEntry
        MAX-ACCESS not-accessible
        STATUS     current
        DESCRIPTION
            ""
        ::= { prtAlert 1 }
    
    prtAlertEntry OBJECT-TYPE
        SYNTAX     PrtAlertEntry
        MAX-ACCESS not-accessible
        STATUS     current
        DESCRIPTION
            "Entries may exist in the table for each device
            index who's device type is `printer'."
        INDEX  { hrDeviceIndex, prtAlertIndex }
        ::= { prtAlertTable 1 }
    
    PrtAlertEntry ::= SEQUENCE {
        prtAlertIndex               Integer32,
        prtAlertSeverityLevel       INTEGER,
        prtAlertTrainingLevel       INTEGER,
        prtAlertGroup               INTEGER,
        prtAlertGroupIndex          Integer32,
        prtAlertLocation            Integer32,
        prtAlertCode                INTEGER,
        prtAlertDescription         OCTET STRING,
        prtAlertTime                TimeTicks
    }
    

    So the way SNMP works is to is to suffix the OID entry of the MIB by the index of the row. You can get the whole table by a Get-Bulk, but I think that the first thing for you is to understand how to retreive an SNMP table.

    In your exact case : 1.3.6.1.2.1.43.18.1.1.8.1.1 you have to read it as :

    1.3.6.1.2.1.43.18.1.1.8 : prtAlertDescription followed by

    1 : the hrDeviceIndex followed by

    1 : the prtAlertIndex which is the row.

    An Advice you can find an assembly called snmpsharpnet which is very helpful to play with SNMP on the top of .NET.