Translating pysnmp oids to human readable strings

Discussion in 'Python' started by SpamMePlease PleasePlease, Mar 5, 2009.

  1. Hey list,

    I was given a task, to reproduce functionality of command specified
    below by writing proper python functions to reuse in some monitoring
    script:

    rivendell# snmpwalk -Os -mALL -v1 -cgabilgathol 10.0.6.66
    ..1.3.6.1.4.1.2636.5.1.1.2
    jnxBgpM2PeerIdentifier.0.ipv4."".unknown."".0.1.38.101.87.145 =
    STRING: 66.250.1.253
    jnxBgpM2PeerIdentifier.0.ipv4.38.101.161.119.1.38.101.161.118 =
    STRING: 66.28.1.85
    jnxBgpM2PeerIdentifier.0.ipv4.64.200.59.74.1.64.200.59.73 = STRING: 64.200.68.12
    jnxBgpM2PeerIdentifier.0.ipv4.72.37.131.250.1.72.37.131.249 = STRING:
    64.235.224.240
    jnxBgpM2PeerState.0.ipv4."".unknown."".0.1.38.101.87.145 = INTEGER:
    established(6)
    jnxBgpM2PeerState.0.ipv4.38.101.161.119.1.38.101.161.118 = INTEGER:
    established(6)
    jnxBgpM2PeerState.0.ipv4.64.200.59.74.1.64.200.59.73 = INTEGER: established(6)
    jnxBgpM2PeerState.0.ipv4.72.37.131.250.1.72.37.131.249 = INTEGER: established(6)
    (more output)

    I have already found a pysnmp library to fetch the data from the
    device with a minimal amount of code:

    from pysnmp.entity.rfc3413.oneliner import cmdgen
    from pysnmp.smi import *
    import string

    cmdGen = cmdgen.CommandGenerator()
    errorIndication, errorStatus, errorIndex, varBinds =
    cmdgen.CommandGenerator().nextCmd(cmdgen.CommunityData('AmonMuil',
    'gabilgathol', 0),
    cmdgen.UdpTransportTarget(('fw-1.datacenter.gondor.net', 161)),
    (1,3,6,1,4,1,2636,5,1,1,2))

    print errorIndication, errorStatus
    for i in varBinds:
    print i

    The problem is that I have completely stuck on the result I am
    experiencing being totally human unreadable, like this:

    rivendell# python snmp.py
    None 0
    [(ObjectName('1.3.6.1.4.1.2636.5.1.1.2.1.1.1.1.0.1.0.0.0.0.1.38.101.87.145'),
    OctetString('B\xfa\x01\xfd'))]
    [(ObjectName('1.3.6.1.4.1.2636.5.1.1.2.1.1.1.1.0.1.38.101.161.119.1.38.101.161.118'),
    OctetString('B\x1c\x01U'))]
    [(ObjectName('1.3.6.1.4.1.2636.5.1.1.2.1.1.1.1.0.1.64.200.59.74.1.64.200.59.73'),
    OctetString('@\xc8D\x0c'))]
    [(ObjectName('1.3.6.1.4.1.2636.5.1.1.2.1.1.1.1.0.1.72.37.131.250.1.72.37.131.249'),
    OctetString('@\xeb\xe0\xf0'))]
    [(ObjectName('1.3.6.1.4.1.2636.5.1.1.2.1.1.1.2.0.1.0.0.0.0.1.38.101.87.145'),
    Integer32('6'))]
    [(ObjectName('1.3.6.1.4.1.2636.5.1.1.2.1.1.1.2.0.1.38.101.161.119.1.38.101.161.118'),
    Integer32('6'))]
    [(ObjectName('1.3.6.1.4.1.2636.5.1.1.2.1.1.1.2.0.1.64.200.59.74.1.64.200.59.73'),
    Integer32('6'))]
    [(ObjectName('1.3.6.1.4.1.2636.5.1.1.2.1.1.1.2.0.1.72.37.131.250.1.72.37.131.249'),
    Integer32('6'))]
    [(ObjectName('1.3.6.1.4.1.2636.5.1.1.2.1.1.1.3.0.1.0.0.0.0.1.38.101.87.145'),
    Integer32('2'))]

    Since I cant find any way to translate these numbers to the same thing
    snmpwalk produce, is there any clue on how to achieve that? Is it
    possible at all for different devices (this one happend to be Juniper
    firewall if that does matter). Also, how can I know where does this
    magic oid ends and where does additional information starts (like ip
    addresses added to oid 0 they all looks like another oid string
    numbers) ?

    Any sample of code, or hint to another lib will be very appreciated!

    --
    --------------------
    Spank The Spam!
    SpamMePlease PleasePlease, Mar 5, 2009
    #1
    1. Advertising

  2. SpamMePlease PleasePlease

    birdsong Guest

    On Mar 5, 12:32 pm, SpamMePlease PleasePlease
    <> wrote:
    > Hey list,
    >
    > I was given a task, to reproduce functionality of command specified
    > below by writing proper python functions to reuse in some monitoring
    > script:
    >
    > rivendell# snmpwalk -Os -mALL -v1 -cgabilgathol 10.0.6.66
    > .1.3.6.1.4.1.2636.5.1.1.2
    > jnxBgpM2PeerIdentifier.0.ipv4."".unknown."".0.1.38.101.87.145 =
    > STRING: 66.250.1.253
    > jnxBgpM2PeerIdentifier.0.ipv4.38.101.161.119.1.38.101.161.118 =
    > STRING: 66.28.1.85
    > jnxBgpM2PeerIdentifier.0.ipv4.64.200.59.74.1.64.200.59.73 = STRING: 64.200.68.12
    > jnxBgpM2PeerIdentifier.0.ipv4.72.37.131.250.1.72.37.131.249 = STRING:
    > 64.235.224.240
    > jnxBgpM2PeerState.0.ipv4."".unknown."".0.1.38.101.87.145 = INTEGER:
    > established(6)
    > jnxBgpM2PeerState.0.ipv4.38.101.161.119.1.38.101.161.118 = INTEGER:
    > established(6)
    > jnxBgpM2PeerState.0.ipv4.64.200.59.74.1.64.200.59.73 = INTEGER: established(6)
    > jnxBgpM2PeerState.0.ipv4.72.37.131.250.1.72.37.131.249 = INTEGER: established(6)
    > (more output)
    >
    > I have already found a pysnmp library to fetch the data from the
    > device with a minimal amount of code:
    >
    > from pysnmp.entity.rfc3413.oneliner import cmdgen
    > from pysnmp.smi import *
    > import string
    >
    > cmdGen = cmdgen.CommandGenerator()
    > errorIndication, errorStatus, errorIndex, varBinds =
    > cmdgen.CommandGenerator().nextCmd(cmdgen.CommunityData('AmonMuil',
    > 'gabilgathol', 0),
    > cmdgen.UdpTransportTarget(('fw-1.datacenter.gondor.net', 161)),
    > (1,3,6,1,4,1,2636,5,1,1,2))
    >
    > print errorIndication, errorStatus
    > for i in varBinds:
    >     print i
    >
    > The problem is that I have completely stuck on the result I am
    > experiencing being totally human unreadable, like this:
    >
    > rivendell# python snmp.py
    > None 0
    > [(ObjectName('1.3.6.1.4.1.2636.5.1.1.2.1.1.1.1.0.1.0.0.0.0.1.38.101.87.145'),
    > OctetString('B\xfa\x01\xfd'))]
    > [(ObjectName('1.3.6.1.4.1.2636.5.1.1.2.1.1.1.1.0.1.38.101.161.119.1.38.101.161.118'),
    > OctetString('B\x1c\x01U'))]
    > [(ObjectName('1.3.6.1.4.1.2636.5.1.1.2.1.1.1.1.0.1.64.200.59.74.1.64.200.59.73'),
    > OctetString('@\xc8D\x0c'))]
    > [(ObjectName('1.3.6.1.4.1.2636.5.1.1.2.1.1.1.1.0.1.72.37.131.250.1.72.37.131.249'),
    > OctetString('@\xeb\xe0\xf0'))]
    > [(ObjectName('1.3.6.1.4.1.2636.5.1.1.2.1.1.1.2.0.1.0.0.0.0.1.38.101.87.145'),
    > Integer32('6'))]
    > [(ObjectName('1.3.6.1.4.1.2636.5.1.1.2.1.1.1.2.0.1.38.101.161.119.1.38.101.161.118'),
    > Integer32('6'))]
    > [(ObjectName('1.3.6.1.4.1.2636.5.1.1.2.1.1.1.2.0.1.64.200.59.74.1.64.200.59.73'),
    > Integer32('6'))]
    > [(ObjectName('1.3.6.1.4.1.2636.5.1.1.2.1.1.1.2.0.1.72.37.131.250.1.72.37.131.249'),
    > Integer32('6'))]
    > [(ObjectName('1.3.6.1.4.1.2636.5.1.1.2.1.1.1.3.0.1.0.0.0.0.1.38.101.87.145'),
    > Integer32('2'))]
    >
    > Since I cant find any way to translate these numbers to the same thing
    > snmpwalk produce, is there any clue on how to achieve that? Is it
    > possible at all for different devices (this one happend to be Juniper
    > firewall if that does matter). Also, how can I know where does this
    > magic oid ends and where does additional information starts (like ip
    > addresses added to oid 0 they all looks like another oid string
    > numbers) ?
    >
    > Any sample of code, or hint to another lib will be very appreciated!
    >
    > --
    > --------------------
    > Spank The Spam!


    Here's an example of walk that's part of a class I wrote, hopefully
    indentation survives the paste. I borrowed heavily from example code
    on the pysnmp site.

    from pysnmp import asn1, v2c
    from pysnmp import role

    def walk(self, community_string, base_oids):

    if type(base_oids) is str: base_oids = [base_oids]
    # this this does what it says, dont bother asking for oids that
    we'll see in our walk
    base_oids = self.remove_child_oids(base_oids)
    # h_pair is just (host, port)
    client = role.manager(self.h_pair)
    client.timeout = 10
    req = v2c.GETNEXTREQUEST(community=community_string)
    rsp = v2c.GETRESPONSE()
    req['encoded_oids'] = map(asn1.OBJECTID().encode, base_oids)

    oids_values = {}
    while req['encoded_oids']:
    try:
    answer, host_tuple = client.send_and_receive(req.encode())
    except (role.NoResponse, role.NetworkError):
    return oids_values

    rsp.decode(answer)

    parsed_oids_vals = self.parse_response(rsp, base_oids)
    oids_values.update(parsed_oids_vals)

    req['request_id'] += 1
    req['encoded_oids'] = map(asn1.OBJECTID().encode,
    parsed_oids_vals.keys())

    return oids_values
    birdsong, Mar 5, 2009
    #2
    1. Advertising

  3. SpamMePlease PleasePlease

    birdsong Guest

    On Mar 5, 1:05 pm, birdsong <> wrote:
    > On Mar 5, 12:32 pm, SpamMePlease PleasePlease
    >
    >
    >
    > <> wrote:
    > > Hey list,

    >
    > > I was given a task, to reproduce functionality of command specified
    > > below by writing proper python functions to reuse in some monitoring
    > > script:

    >
    > > rivendell# snmpwalk -Os -mALL -v1 -cgabilgathol 10.0.6.66
    > > .1.3.6.1.4.1.2636.5.1.1.2
    > > jnxBgpM2PeerIdentifier.0.ipv4."".unknown."".0.1.38.101.87.145 =
    > > STRING: 66.250.1.253
    > > jnxBgpM2PeerIdentifier.0.ipv4.38.101.161.119.1.38.101.161.118 =
    > > STRING: 66.28.1.85
    > > jnxBgpM2PeerIdentifier.0.ipv4.64.200.59.74.1.64.200.59.73 = STRING: 64.200.68.12
    > > jnxBgpM2PeerIdentifier.0.ipv4.72.37.131.250.1.72.37.131.249 = STRING:
    > > 64.235.224.240
    > > jnxBgpM2PeerState.0.ipv4."".unknown."".0.1.38.101.87.145 = INTEGER:
    > > established(6)
    > > jnxBgpM2PeerState.0.ipv4.38.101.161.119.1.38.101.161.118 = INTEGER:
    > > established(6)
    > > jnxBgpM2PeerState.0.ipv4.64.200.59.74.1.64.200.59.73 = INTEGER: established(6)
    > > jnxBgpM2PeerState.0.ipv4.72.37.131.250.1.72.37.131.249 = INTEGER: established(6)
    > > (more output)

    >
    > > I have already found a pysnmp library to fetch the data from the
    > > device with a minimal amount of code:

    >
    > > from pysnmp.entity.rfc3413.oneliner import cmdgen
    > > from pysnmp.smi import *
    > > import string

    >
    > > cmdGen = cmdgen.CommandGenerator()
    > > errorIndication, errorStatus, errorIndex, varBinds =
    > > cmdgen.CommandGenerator().nextCmd(cmdgen.CommunityData('AmonMuil',
    > > 'gabilgathol', 0),
    > > cmdgen.UdpTransportTarget(('fw-1.datacenter.gondor.net', 161)),
    > > (1,3,6,1,4,1,2636,5,1,1,2))

    >
    > > print errorIndication, errorStatus
    > > for i in varBinds:
    > >     print i

    >
    > > The problem is that I have completely stuck on the result I am
    > > experiencing being totally human unreadable, like this:

    >
    > > rivendell# python snmp.py
    > > None 0
    > > [(ObjectName('1.3.6.1.4.1.2636.5.1.1.2.1.1.1.1.0.1.0.0.0.0.1.38.101.87.145'),
    > > OctetString('B\xfa\x01\xfd'))]
    > > [(ObjectName('1.3.6.1.4.1.2636.5.1.1.2.1.1.1.1.0.1.38.101.161.119.1.38.101.161.118'),
    > > OctetString('B\x1c\x01U'))]
    > > [(ObjectName('1.3.6.1.4.1.2636.5.1.1.2.1.1.1.1.0.1.64.200.59.74.1.64.200.59.73'),
    > > OctetString('@\xc8D\x0c'))]
    > > [(ObjectName('1.3.6.1.4.1.2636.5.1.1.2.1.1.1.1.0.1.72.37.131.250.1.72.37.131.249'),
    > > OctetString('@\xeb\xe0\xf0'))]
    > > [(ObjectName('1.3.6.1.4.1.2636.5.1.1.2.1.1.1.2.0.1.0.0.0.0.1.38.101.87.145'),
    > > Integer32('6'))]
    > > [(ObjectName('1.3.6.1.4.1.2636.5.1.1.2.1.1.1.2.0.1.38.101.161.119.1.38.101.161.118'),
    > > Integer32('6'))]
    > > [(ObjectName('1.3.6.1.4.1.2636.5.1.1.2.1.1.1.2.0.1.64.200.59.74.1.64.200.59.73'),
    > > Integer32('6'))]
    > > [(ObjectName('1.3.6.1.4.1.2636.5.1.1.2.1.1.1.2.0.1.72.37.131.250.1.72.37.131.249'),
    > > Integer32('6'))]
    > > [(ObjectName('1.3.6.1.4.1.2636.5.1.1.2.1.1.1.3.0.1.0.0.0.0.1.38.101.87.145'),
    > > Integer32('2'))]

    >
    > > Since I cant find any way to translate these numbers to the same thing
    > > snmpwalk produce, is there any clue on how to achieve that? Is it
    > > possible at all for different devices (this one happend to be Juniper
    > > firewall if that does matter). Also, how can I know where does this
    > > magic oid ends and where does additional information starts (like ip
    > > addresses added to oid 0 they all looks like another oid string
    > > numbers) ?

    >
    > > Any sample of code, or hint to another lib will be very appreciated!

    >
    > > --
    > > --------------------
    > > Spank The Spam!

    >
    > Here's an example of walk that's part of a class I wrote, hopefully
    > indentation survives the paste.  I borrowed heavily from example code
    > on the pysnmp site.
    >
    > from pysnmp import asn1, v2c
    > from pysnmp import role
    >
    >   def walk(self, community_string, base_oids):
    >
    >     if type(base_oids) is str: base_oids = [base_oids]
    >     # this this does what it says, dont bother asking for oids that
    > we'll see in our walk
    >     base_oids = self.remove_child_oids(base_oids)
    >     # h_pair is just (host, port)
    >     client = role.manager(self.h_pair)
    >     client.timeout = 10
    >     req = v2c.GETNEXTREQUEST(community=community_string)
    >     rsp = v2c.GETRESPONSE()
    >     req['encoded_oids'] = map(asn1.OBJECTID().encode, base_oids)
    >
    >     oids_values = {}
    >     while req['encoded_oids']:
    >       try:
    >         answer, host_tuple = client.send_and_receive(req.encode())
    >       except (role.NoResponse, role.NetworkError):
    >         return oids_values
    >
    >       rsp.decode(answer)
    >
    >       parsed_oids_vals = self.parse_response(rsp, base_oids)
    >       oids_values.update(parsed_oids_vals)
    >
    >       req['request_id'] += 1
    >       req['encoded_oids'] = map(asn1.OBJECTID().encode,
    > parsed_oids_vals.keys())
    >
    >     return oids_values


    Just realized the parse_response() is needed to makes sense of it:

    def parse_response(self, rsp, head_oids):
    # list of indices
    overshot_oids = []

    vals = map(lambda x: x[0](), map(asn1.decode, rsp
    ['encoded_vals']))
    oids = map(lambda x: asn1.OBJECTID().decode(x)[0], rsp
    ['encoded_oids'])
    oids_vals = dict(map(None, oids, vals))

    for oid in oids_vals:
    if not filter(lambda h: asn1.OBJECTID(h).isaprefix(oid),
    head_oids):
    overshot_oids.append(oid)

    map(lambda x: oids_vals.pop(x), overshot_oids)

    return oids_vals


    I welcome critique btw, I'm here to learn.
    birdsong, Mar 5, 2009
    #3
  4. On Thu, Mar 5, 2009 at 10:12 PM, birdsong <> wrote:
    > On Mar 5, 1:05 pm, birdsong <> wrote:
    >> On Mar 5, 12:32 pm, SpamMePlease PleasePlease
    >>
    >>
    >>
    >> <> wrote:
    >> > Hey list,

    >>
    >> > I was given a task, to reproduce functionality of command specified
    >> > below by writing proper python functions to reuse in some monitoring
    >> > script:

    >>
    >> > rivendell# snmpwalk -Os -mALL -v1 -cgabilgathol 10.0.6.66
    >> > .1.3.6.1.4.1.2636.5.1.1.2
    >> > jnxBgpM2PeerIdentifier.0.ipv4."".unknown."".0.1.38.101.87.145 =
    >> > STRING: 66.250.1.253
    >> > jnxBgpM2PeerIdentifier.0.ipv4.38.101.161.119.1.38.101.161.118 =
    >> > STRING: 66.28.1.85
    >> > jnxBgpM2PeerIdentifier.0.ipv4.64.200.59.74.1.64.200.59.73 = STRING: 64.200.68.12
    >> > jnxBgpM2PeerIdentifier.0.ipv4.72.37.131.250.1.72.37.131.249 = STRING:
    >> > 64.235.224.240
    >> > jnxBgpM2PeerState.0.ipv4."".unknown."".0.1.38.101.87.145 = INTEGER:
    >> > established(6)
    >> > jnxBgpM2PeerState.0.ipv4.38.101.161.119.1.38.101.161.118 = INTEGER:
    >> > established(6)
    >> > jnxBgpM2PeerState.0.ipv4.64.200.59.74.1.64.200.59.73 = INTEGER: established(6)
    >> > jnxBgpM2PeerState.0.ipv4.72.37.131.250.1.72.37.131.249 = INTEGER: established(6)
    >> > (more output)

    >>
    >> > I have already found a pysnmp library to fetch the data from the
    >> > device with a minimal amount of code:

    >>
    >> > from pysnmp.entity.rfc3413.oneliner import cmdgen
    >> > from pysnmp.smi import *
    >> > import string

    >>
    >> > cmdGen = cmdgen.CommandGenerator()
    >> > errorIndication, errorStatus, errorIndex, varBinds =
    >> > cmdgen.CommandGenerator().nextCmd(cmdgen.CommunityData('AmonMuil',
    >> > 'gabilgathol', 0),
    >> > cmdgen.UdpTransportTarget(('fw-1.datacenter.gondor.net', 161)),
    >> > (1,3,6,1,4,1,2636,5,1,1,2))

    >>
    >> > print errorIndication, errorStatus
    >> > for i in varBinds:
    >> >     print i

    >>
    >> > The problem is that I have completely stuck on the result I am
    >> > experiencing being totally human unreadable, like this:

    >>
    >> > rivendell# python snmp.py
    >> > None 0
    >> > [(ObjectName('1.3.6.1.4.1.2636.5.1.1.2.1.1.1.1.0.1.0.0.0.0.1.38.101.87..145'),
    >> > OctetString('B\xfa\x01\xfd'))]
    >> > [(ObjectName('1.3.6.1.4.1.2636.5.1.1.2.1.1.1.1.0.1.38.101.161.119.1.38..101.161.118'),
    >> > OctetString('B\x1c\x01U'))]
    >> > [(ObjectName('1.3.6.1.4.1.2636.5.1.1.2.1.1.1.1.0.1.64.200.59.74.1.64.200.59.73'),
    >> > OctetString('@\xc8D\x0c'))]
    >> > [(ObjectName('1.3.6.1.4.1.2636.5.1.1.2.1.1.1.1.0.1.72.37.131.250.1.72.37.131.249'),
    >> > OctetString('@\xeb\xe0\xf0'))]
    >> > [(ObjectName('1.3.6.1.4.1.2636.5.1.1.2.1.1.1.2.0.1.0.0.0.0.1.38.101.87..145'),
    >> > Integer32('6'))]
    >> > [(ObjectName('1.3.6.1.4.1.2636.5.1.1.2.1.1.1.2.0.1.38.101.161.119.1.38..101.161.118'),
    >> > Integer32('6'))]
    >> > [(ObjectName('1.3.6.1.4.1.2636.5.1.1.2.1.1.1.2.0.1.64.200.59.74.1.64.200.59.73'),
    >> > Integer32('6'))]
    >> > [(ObjectName('1.3.6.1.4.1.2636.5.1.1.2.1.1.1.2.0.1.72.37.131.250.1.72.37.131.249'),
    >> > Integer32('6'))]
    >> > [(ObjectName('1.3.6.1.4.1.2636.5.1.1.2.1.1.1.3.0.1.0.0.0.0.1.38.101.87..145'),
    >> > Integer32('2'))]

    >>
    >> > Since I cant find any way to translate these numbers to the same thing
    >> > snmpwalk produce, is there any clue on how to achieve that? Is it
    >> > possible at all for different devices (this one happend to be Juniper
    >> > firewall if that does matter). Also, how can I know where does this
    >> > magic oid ends and where does additional information starts (like ip
    >> > addresses added to oid 0 they all looks like another oid string
    >> > numbers) ?

    >>
    >> > Any sample of code, or hint to another lib will be very appreciated!

    >>
    >> > --
    >> > --------------------
    >> > Spank The Spam!

    >>
    >> Here's an example of walk that's part of a class I wrote, hopefully
    >> indentation survives the paste.  I borrowed heavily from example code
    >> on the pysnmp site.
    >>
    >> from pysnmp import asn1, v2c
    >> from pysnmp import role
    >>
    >>   def walk(self, community_string, base_oids):
    >>
    >>     if type(base_oids) is str: base_oids = [base_oids]
    >>     # this this does what it says, dont bother asking for oids that
    >> we'll see in our walk
    >>     base_oids = self.remove_child_oids(base_oids)
    >>     # h_pair is just (host, port)
    >>     client = role.manager(self.h_pair)
    >>     client.timeout = 10
    >>     req = v2c.GETNEXTREQUEST(community=community_string)
    >>     rsp = v2c.GETRESPONSE()
    >>     req['encoded_oids'] = map(asn1.OBJECTID().encode, base_oids)
    >>
    >>     oids_values = {}
    >>     while req['encoded_oids']:
    >>       try:
    >>         answer, host_tuple = client.send_and_receive(req.encode())
    >>       except (role.NoResponse, role.NetworkError):
    >>         return oids_values
    >>
    >>       rsp.decode(answer)
    >>
    >>       parsed_oids_vals = self.parse_response(rsp, base_oids)
    >>       oids_values.update(parsed_oids_vals)
    >>
    >>       req['request_id'] += 1
    >>       req['encoded_oids'] = map(asn1.OBJECTID().encode,
    >> parsed_oids_vals.keys())
    >>
    >>     return oids_values

    >
    > Just realized the parse_response() is needed to makes sense of it:
    >
    > def parse_response(self, rsp, head_oids):
    >    # list of indices
    >    overshot_oids = []
    >
    >    vals = map(lambda x: x[0](), map(asn1.decode, rsp
    > ['encoded_vals']))
    >    oids = map(lambda x: asn1.OBJECTID().decode(x)[0], rsp
    > ['encoded_oids'])
    >    oids_vals = dict(map(None, oids, vals))
    >
    >    for oid in oids_vals:
    >      if not filter(lambda h: asn1.OBJECTID(h).isaprefix(oid),
    > head_oids):
    >        overshot_oids.append(oid)
    >
    >    map(lambda x: oids_vals.pop(x), overshot_oids)
    >
    >    return oids_vals
    >
    >
    > I welcome critique btw, I'm here to learn.
    > --
    > http://mail.python.org/mailman/listinfo/python-list
    >


    Sorry, but I dont understand the code at all. Where does it takes the
    names for the oid numbers? Why the translation needs a 'walk' at all?
    Isnt that possible to perform an acion on given oid (my code produces
    a list of them) to translate it to human readable output like snmpwalk
    binary does?

    --
    --------------------
    Spank The Spam!
    SpamMePlease PleasePlease, Mar 5, 2009
    #4
  5. SpamMePlease PleasePlease

    birdsong Guest

    On Mar 5, 2:30 pm, SpamMePlease PleasePlease
    <> wrote:
    > On Thu, Mar 5, 2009 at 10:12 PM, birdsong <> wrote:
    > > On Mar 5, 1:05 pm, birdsong <> wrote:
    > >> On Mar 5, 12:32 pm, SpamMePlease PleasePlease

    >
    > >> <> wrote:
    > >> > Hey list,

    >
    > >> > I was given a task, to reproduce functionality of command specified
    > >> > below by writing proper python functions to reuse in some monitoring
    > >> > script:

    >
    > >> > rivendell# snmpwalk -Os -mALL -v1 -cgabilgathol 10.0.6.66
    > >> > .1.3.6.1.4.1.2636.5.1.1.2
    > >> > jnxBgpM2PeerIdentifier.0.ipv4."".unknown."".0.1.38.101.87.145 =
    > >> > STRING: 66.250.1.253
    > >> > jnxBgpM2PeerIdentifier.0.ipv4.38.101.161.119.1.38.101.161.118 =
    > >> > STRING: 66.28.1.85
    > >> > jnxBgpM2PeerIdentifier.0.ipv4.64.200.59.74.1.64.200.59.73 = STRING: 64.200.68.12
    > >> > jnxBgpM2PeerIdentifier.0.ipv4.72.37.131.250.1.72.37.131.249 = STRING:
    > >> > 64.235.224.240
    > >> > jnxBgpM2PeerState.0.ipv4."".unknown."".0.1.38.101.87.145 = INTEGER:
    > >> > established(6)
    > >> > jnxBgpM2PeerState.0.ipv4.38.101.161.119.1.38.101.161.118 = INTEGER:
    > >> > established(6)
    > >> > jnxBgpM2PeerState.0.ipv4.64.200.59.74.1.64.200.59.73 = INTEGER: established(6)
    > >> > jnxBgpM2PeerState.0.ipv4.72.37.131.250.1.72.37.131.249 = INTEGER: established(6)
    > >> > (more output)

    >
    > >> > I have already found a pysnmp library to fetch the data from the
    > >> > device with a minimal amount of code:

    >
    > >> > from pysnmp.entity.rfc3413.oneliner import cmdgen
    > >> > from pysnmp.smi import *
    > >> > import string

    >
    > >> > cmdGen = cmdgen.CommandGenerator()
    > >> > errorIndication, errorStatus, errorIndex, varBinds =
    > >> > cmdgen.CommandGenerator().nextCmd(cmdgen.CommunityData('AmonMuil',
    > >> > 'gabilgathol', 0),
    > >> > cmdgen.UdpTransportTarget(('fw-1.datacenter.gondor.net', 161)),
    > >> > (1,3,6,1,4,1,2636,5,1,1,2))

    >
    > >> > print errorIndication, errorStatus
    > >> > for i in varBinds:
    > >> >     print i

    >
    > >> > The problem is that I have completely stuck on the result I am
    > >> > experiencing being totally human unreadable, like this:

    >
    > >> > rivendell# python snmp.py
    > >> > None 0
    > >> > [(ObjectName('1.3.6.1.4.1.2636.5.1.1.2.1.1.1.1.0.1.0.0.0.0.1.38.101.87.145'),
    > >> > OctetString('B\xfa\x01\xfd'))]
    > >> > [(ObjectName('1.3.6.1.4.1.2636.5.1.1.2.1.1.1.1.0.1.38.101.161.119.1.38.101.161.118'),
    > >> > OctetString('B\x1c\x01U'))]
    > >> > [(ObjectName('1.3.6.1.4.1.2636.5.1.1.2.1.1.1.1.0.1.64.200.59.74.1.64..200.59.73'),
    > >> > OctetString('@\xc8D\x0c'))]
    > >> > [(ObjectName('1.3.6.1.4.1.2636.5.1.1.2.1.1.1.1.0.1.72.37.131.250.1.72.37.131.249'),
    > >> > OctetString('@\xeb\xe0\xf0'))]
    > >> > [(ObjectName('1.3.6.1.4.1.2636.5.1.1.2.1.1.1.2.0.1.0.0.0.0.1.38.101.87.145'),
    > >> > Integer32('6'))]
    > >> > [(ObjectName('1.3.6.1.4.1.2636.5.1.1.2.1.1.1.2.0.1.38.101.161.119.1.38.101.161.118'),
    > >> > Integer32('6'))]
    > >> > [(ObjectName('1.3.6.1.4.1.2636.5.1.1.2.1.1.1.2.0.1.64.200.59.74.1.64..200.59.73'),
    > >> > Integer32('6'))]
    > >> > [(ObjectName('1.3.6.1.4.1.2636.5.1.1.2.1.1.1.2.0.1.72.37.131.250.1.72.37.131.249'),
    > >> > Integer32('6'))]
    > >> > [(ObjectName('1.3.6.1.4.1.2636.5.1.1.2.1.1.1.3.0.1.0.0.0.0.1.38.101.87.145'),
    > >> > Integer32('2'))]

    >
    > >> > Since I cant find any way to translate these numbers to the same thing
    > >> > snmpwalk produce, is there any clue on how to achieve that? Is it
    > >> > possible at all for different devices (this one happend to be Juniper
    > >> > firewall if that does matter). Also, how can I know where does this
    > >> > magic oid ends and where does additional information starts (like ip
    > >> > addresses added to oid 0 they all looks like another oid string
    > >> > numbers) ?

    >
    > >> > Any sample of code, or hint to another lib will be very appreciated!

    >
    > >> > --
    > >> > --------------------
    > >> > Spank The Spam!

    >
    > >> Here's an example of walk that's part of a class I wrote, hopefully
    > >> indentation survives the paste.  I borrowed heavily from example code
    > >> on the pysnmp site.

    >
    > >> from pysnmp import asn1, v2c
    > >> from pysnmp import role

    >
    > >>   def walk(self, community_string, base_oids):

    >
    > >>     if type(base_oids) is str: base_oids = [base_oids]
    > >>     # this this does what it says, dont bother asking for oids that
    > >> we'll see in our walk
    > >>     base_oids = self.remove_child_oids(base_oids)
    > >>     # h_pair is just (host, port)
    > >>     client = role.manager(self.h_pair)
    > >>     client.timeout = 10
    > >>     req = v2c.GETNEXTREQUEST(community=community_string)
    > >>     rsp = v2c.GETRESPONSE()
    > >>     req['encoded_oids'] = map(asn1.OBJECTID().encode, base_oids)

    >
    > >>     oids_values = {}
    > >>     while req['encoded_oids']:
    > >>       try:
    > >>         answer, host_tuple = client.send_and_receive(req.encode())
    > >>       except (role.NoResponse, role.NetworkError):
    > >>         return oids_values

    >
    > >>       rsp.decode(answer)

    >
    > >>       parsed_oids_vals = self.parse_response(rsp, base_oids)
    > >>       oids_values.update(parsed_oids_vals)

    >
    > >>       req['request_id'] += 1
    > >>       req['encoded_oids'] = map(asn1.OBJECTID().encode,
    > >> parsed_oids_vals.keys())

    >
    > >>     return oids_values

    >
    > > Just realized the parse_response() is needed to makes sense of it:

    >
    > > def parse_response(self, rsp, head_oids):
    > >    # list of indices
    > >    overshot_oids = []

    >
    > >    vals = map(lambda x: x[0](), map(asn1.decode, rsp
    > > ['encoded_vals']))
    > >    oids = map(lambda x: asn1.OBJECTID().decode(x)[0], rsp
    > > ['encoded_oids'])
    > >    oids_vals = dict(map(None, oids, vals))

    >
    > >    for oid in oids_vals:
    > >      if not filter(lambda h: asn1.OBJECTID(h).isaprefix(oid),
    > > head_oids):
    > >        overshot_oids.append(oid)

    >
    > >    map(lambda x: oids_vals.pop(x), overshot_oids)

    >
    > >    return oids_vals

    >
    > > I welcome critique btw, I'm here to learn.
    > > --
    > >http://mail.python.org/mailman/listinfo/python-list

    >
    > Sorry, but I dont understand the code at all. Where does it takes the
    > names for the oid numbers? Why the translation needs a 'walk' at all?
    > Isnt that possible to perform an acion on given oid (my code produces
    > a list of them) to translate it to human readable output like snmpwalk
    > binary does?
    >
    > --
    > --------------------
    > Spank The Spam!


    I haven't looked at the newer version of pysnmp, but I dont know if
    there's a library that maps oids to human readable oids. Besides, I
    didn't really need to read the OIDs as a human, I wanted the values
    for injecting into data stores. Here's a link I found really helpful
    while figuring out my necessary OIDs
    http://www.oid-info.com/

    I was responding to your call for example code. I didn't get this in
    the first 2 hours I poured over pysnmp either. Experiment in the
    interpreter, you'll get it. You should be able to use my two functions
    with very minor editing to walk an oid and return values in a
    dictionary. The values will have already been decoded to something you
    should recognize.
    birdsong, Mar 6, 2009
    #5
  6. You need to parse the MIB file to get the human-readable names
    corresponding to the OIDs. The pysnmp library already provides this
    functionality. I haven't used this feature myself (I mainly use pysnmp
    to automate SNMP walk requests, like the one in your code), but the
    documentation at found the below example at
    http://pysnmp.sourceforge.net/docs/4.1.x/index.html#MIB-SERVICES.


    >>> from pysnmp.smi import builder, view
    >>>
    >>> mibBuilder = builder.MibBuilder().loadModules('SNMPv2-MIB')
    >>> mibViewController = view.MibViewController(mibBuilder)
    >>>
    >>> oid,label,suffix = mibViewController.getNodeName((1,3,6,1,2,'mib-2',1,'sysDescr'))
    >>> print oid

    (1, 3, 6, 1, 2, 1, 1, 1)
    >>> print label

    ('iso', 'org', 'dod', 'internet', 'mgmt', 'mib-2', 'system', 'sysDescr')
    >>> print suffix

    ()
    Shantanu Joshi, Mar 6, 2009
    #6
  7. On Fri, Mar 6, 2009 at 6:56 AM, Shantanu Joshi <> wrote:
    > You need to parse the MIB file to get the human-readable names
    > corresponding to the OIDs. The pysnmp library already provides this
    > functionality. I haven't used this feature myself (I mainly use pysnmp
    > to automate SNMP walk requests, like the one in your code), but the
    > documentation at found the below example at
    > http://pysnmp.sourceforge.net/docs/4.1.x/index.html#MIB-SERVICES.
    >
    >
    >>>> from pysnmp.smi import builder, view
    >>>>
    >>>> mibBuilder = builder.MibBuilder().loadModules('SNMPv2-MIB')
    >>>> mibViewController = view.MibViewController(mibBuilder)
    >>>>
    >>>> oid,label,suffix = mibViewController.getNodeName((1,3,6,1,2,'mib-2',1,'sysDescr'))
    >>>> print oid

    > (1, 3, 6, 1, 2, 1, 1, 1)
    >>>> print label

    > ('iso', 'org', 'dod', 'internet', 'mgmt', 'mib-2', 'system', 'sysDescr')
    >>>> print suffix

    > ()
    > --
    > http://mail.python.org/mailman/listinfo/python-list
    >


    Yes, I have seen that, but I cant get it working as expected (or it
    doesent to what expected at all). I cant make it return values like:
    jnxBgpM2PeerIdentifier.0.ipv4.38.101.161.119.1.38.101.161.118 (the one
    of many I got from snmpwalk) but instead I am getting bunch of words
    like iso, internet, mgmt, which is no way close to desired effect.
    Still no luck - anybody with a clue?

    --
    --------------------
    Spank The Spam!
    SpamMePlease PleasePlease, Mar 6, 2009
    #7
  8. On Fri, Mar 6, 2009 at 1:10 AM, birdsong <> wrote:
    > On Mar 5, 2:30 pm, SpamMePlease PleasePlease
    > <> wrote:
    >> On Thu, Mar 5, 2009 at 10:12 PM, birdsong <> wrote:
    >> > On Mar 5, 1:05 pm, birdsong <> wrote:
    >> >> On Mar 5, 12:32 pm, SpamMePlease PleasePlease

    >>
    >> >> <> wrote:
    >> >> > Hey list,

    >>
    >> >> > I was given a task, to reproduce functionality of command specified
    >> >> > below by writing proper python functions to reuse in some monitoring
    >> >> > script:

    >>
    >> >> > rivendell# snmpwalk -Os -mALL -v1 -cgabilgathol 10.0.6.66
    >> >> > .1.3.6.1.4.1.2636.5.1.1.2
    >> >> > jnxBgpM2PeerIdentifier.0.ipv4."".unknown."".0.1.38.101.87.145 =
    >> >> > STRING: 66.250.1.253
    >> >> > jnxBgpM2PeerIdentifier.0.ipv4.38.101.161.119.1.38.101.161.118 =
    >> >> > STRING: 66.28.1.85
    >> >> > jnxBgpM2PeerIdentifier.0.ipv4.64.200.59.74.1.64.200.59.73 = STRING: 64.200.68.12
    >> >> > jnxBgpM2PeerIdentifier.0.ipv4.72.37.131.250.1.72.37.131.249 = STRING:
    >> >> > 64.235.224.240
    >> >> > jnxBgpM2PeerState.0.ipv4."".unknown."".0.1.38.101.87.145 = INTEGER:
    >> >> > established(6)
    >> >> > jnxBgpM2PeerState.0.ipv4.38.101.161.119.1.38.101.161.118 = INTEGER:
    >> >> > established(6)
    >> >> > jnxBgpM2PeerState.0.ipv4.64.200.59.74.1.64.200.59.73 = INTEGER: established(6)
    >> >> > jnxBgpM2PeerState.0.ipv4.72.37.131.250.1.72.37.131.249 = INTEGER: established(6)
    >> >> > (more output)

    >>
    >> >> > I have already found a pysnmp library to fetch the data from the
    >> >> > device with a minimal amount of code:

    >>
    >> >> > from pysnmp.entity.rfc3413.oneliner import cmdgen
    >> >> > from pysnmp.smi import *
    >> >> > import string

    >>
    >> >> > cmdGen = cmdgen.CommandGenerator()
    >> >> > errorIndication, errorStatus, errorIndex, varBinds =
    >> >> > cmdgen.CommandGenerator().nextCmd(cmdgen.CommunityData('AmonMuil',
    >> >> > 'gabilgathol', 0),
    >> >> > cmdgen.UdpTransportTarget(('fw-1.datacenter.gondor.net', 161)),
    >> >> > (1,3,6,1,4,1,2636,5,1,1,2))

    >>
    >> >> > print errorIndication, errorStatus
    >> >> > for i in varBinds:
    >> >> >     print i

    >>
    >> >> > The problem is that I have completely stuck on the result I am
    >> >> > experiencing being totally human unreadable, like this:

    >>
    >> >> > rivendell# python snmp.py
    >> >> > None 0
    >> >> > [(ObjectName('1.3.6.1.4.1.2636.5.1.1.2.1.1.1.1.0.1.0.0.0.0.1.38.101..87.145'),
    >> >> > OctetString('B\xfa\x01\xfd'))]
    >> >> > [(ObjectName('1.3.6.1.4.1.2636.5.1.1.2.1.1.1.1.0.1.38.101.161.119.1..38.101.161.118'),
    >> >> > OctetString('B\x1c\x01U'))]
    >> >> > [(ObjectName('1.3.6.1.4.1.2636.5.1.1.2.1.1.1.1.0.1.64.200.59.74.1.64.200.59.73'),
    >> >> > OctetString('@\xc8D\x0c'))]
    >> >> > [(ObjectName('1.3.6.1.4.1.2636.5.1.1.2.1.1.1.1.0.1.72.37.131.250.1.72.37.131.249'),
    >> >> > OctetString('@\xeb\xe0\xf0'))]
    >> >> > [(ObjectName('1.3.6.1.4.1.2636.5.1.1.2.1.1.1.2.0.1.0.0.0.0.1.38.101..87.145'),
    >> >> > Integer32('6'))]
    >> >> > [(ObjectName('1.3.6.1.4.1.2636.5.1.1.2.1.1.1.2.0.1.38.101.161.119.1..38.101.161.118'),
    >> >> > Integer32('6'))]
    >> >> > [(ObjectName('1.3.6.1.4.1.2636.5.1.1.2.1.1.1.2.0.1.64.200.59.74.1.64.200.59.73'),
    >> >> > Integer32('6'))]
    >> >> > [(ObjectName('1.3.6.1.4.1.2636.5.1.1.2.1.1.1.2.0.1.72.37.131.250.1.72.37.131.249'),
    >> >> > Integer32('6'))]
    >> >> > [(ObjectName('1.3.6.1.4.1.2636.5.1.1.2.1.1.1.3.0.1.0.0.0.0.1.38.101..87.145'),
    >> >> > Integer32('2'))]

    >>
    >> >> > Since I cant find any way to translate these numbers to the same thing
    >> >> > snmpwalk produce, is there any clue on how to achieve that? Is it
    >> >> > possible at all for different devices (this one happend to be Juniper
    >> >> > firewall if that does matter). Also, how can I know where does this
    >> >> > magic oid ends and where does additional information starts (like ip
    >> >> > addresses added to oid 0 they all looks like another oid string
    >> >> > numbers) ?

    >>
    >> >> > Any sample of code, or hint to another lib will be very appreciated!

    >>
    >> >> > --
    >> >> > --------------------
    >> >> > Spank The Spam!

    >>
    >> >> Here's an example of walk that's part of a class I wrote, hopefully
    >> >> indentation survives the paste.  I borrowed heavily from example code
    >> >> on the pysnmp site.

    >>
    >> >> from pysnmp import asn1, v2c
    >> >> from pysnmp import role

    >>
    >> >>   def walk(self, community_string, base_oids):

    >>
    >> >>     if type(base_oids) is str: base_oids = [base_oids]
    >> >>     # this this does what it says, dont bother asking for oids that
    >> >> we'll see in our walk
    >> >>     base_oids = self.remove_child_oids(base_oids)
    >> >>     # h_pair is just (host, port)
    >> >>     client = role.manager(self.h_pair)
    >> >>     client.timeout = 10
    >> >>     req = v2c.GETNEXTREQUEST(community=community_string)
    >> >>     rsp = v2c.GETRESPONSE()
    >> >>     req['encoded_oids'] = map(asn1.OBJECTID().encode, base_oids)

    >>
    >> >>     oids_values = {}
    >> >>     while req['encoded_oids']:
    >> >>       try:
    >> >>         answer, host_tuple = client.send_and_receive(req.encode())
    >> >>       except (role.NoResponse, role.NetworkError):
    >> >>         return oids_values

    >>
    >> >>       rsp.decode(answer)

    >>
    >> >>       parsed_oids_vals = self.parse_response(rsp, base_oids)
    >> >>       oids_values.update(parsed_oids_vals)

    >>
    >> >>       req['request_id'] += 1
    >> >>       req['encoded_oids'] = map(asn1.OBJECTID().encode,
    >> >> parsed_oids_vals.keys())

    >>
    >> >>     return oids_values

    >>
    >> > Just realized the parse_response() is needed to makes sense of it:

    >>
    >> > def parse_response(self, rsp, head_oids):
    >> >    # list of indices
    >> >    overshot_oids = []

    >>
    >> >    vals = map(lambda x: x[0](), map(asn1.decode, rsp
    >> > ['encoded_vals']))
    >> >    oids = map(lambda x: asn1.OBJECTID().decode(x)[0], rsp
    >> > ['encoded_oids'])
    >> >    oids_vals = dict(map(None, oids, vals))

    >>
    >> >    for oid in oids_vals:
    >> >      if not filter(lambda h: asn1.OBJECTID(h).isaprefix(oid),
    >> > head_oids):
    >> >        overshot_oids.append(oid)

    >>
    >> >    map(lambda x: oids_vals.pop(x), overshot_oids)

    >>
    >> >    return oids_vals

    >>
    >> > I welcome critique btw, I'm here to learn.
    >> > --
    >> >http://mail.python.org/mailman/listinfo/python-list

    >>
    >> Sorry, but I dont understand the code at all. Where does it takes the
    >> names for the oid numbers? Why the translation needs a 'walk' at all?
    >> Isnt that possible to perform an acion on given oid (my code produces
    >> a list of them) to translate it to human readable output like snmpwalk
    >> binary does?
    >>
    >> --
    >> --------------------
    >> Spank The Spam!

    >
    > I haven't looked at the newer version of pysnmp, but I dont know if
    > there's a library that maps oids to human readable oids.  Besides, I
    > didn't really need to read the OIDs as a human, I wanted the values
    > for injecting into data stores.  Here's a link I found really helpful
    > while figuring out my necessary OIDs
    > http://www.oid-info.com/


    Well, lucky you. Unfortunately I do need this oids in human readable
    form, as I need to present them (output of my code) to humans.

    > I was responding to your call for example code.  I didn't get this in
    > the first 2 hours I poured over pysnmp either. Experiment in the
    > interpreter, you'll get it. You should be able to use my two functions
    > with very minor editing to walk an oid and return values in a
    > dictionary. The values will have already been decoded to something you
    > should recognize.
    > --
    > http://mail.python.org/mailman/listinfo/python-list
    >


    My call for example code was for code that actually translates
    "1.3.6.1.4.1.2636.5.1.1.2.1.1.1.1.0.1.0.0.0.0.1.38.101.87.145" to
    "jnxBgpM2PeerIdentifier.0.ipv4.38.101.161.119.1.38.101.161.118" so the
    second one could be read by human to make some decisions. I dont
    really need to walk oids, as my small code already gives me even more
    than I need, now I just have to translate them to the same form as
    snmpwalk binary does. And I have no idea how to do so.


    --
    --------------------
    Spank The Spam!
    SpamMePlease PleasePlease, Mar 6, 2009
    #8
  9. SpamMePlease PleasePlease <> writes:

    > On Fri, Mar 6, 2009 at 6:56 AM, Shantanu Joshi <> wrote:
    >> You need to parse the MIB file to get the human-readable names
    >> corresponding to the OIDs. The pysnmp library already provides this
    >> functionality. I haven't used this feature myself (I mainly use pysnmp
    >> to automate SNMP walk requests, like the one in your code), but the
    >> documentation at found the below example at
    >> http://pysnmp.sourceforge.net/docs/4.1.x/index.html#MIB-SERVICES.
    >>
    >>
    >>>>> from pysnmp.smi import builder, view
    >>>>>
    >>>>> mibBuilder = builder.MibBuilder().loadModules('SNMPv2-MIB')
    >>>>> mibViewController = view.MibViewController(mibBuilder)
    >>>>>
    >>>>> oid,label,suffix = mibViewController.getNodeName((1,3,6,1,2,'mib-2',1,'sysDescr'))
    >>>>> print oid

    >> (1, 3, 6, 1, 2, 1, 1, 1)
    >>>>> print label

    >> ('iso', 'org', 'dod', 'internet', 'mgmt', 'mib-2', 'system', 'sysDescr')
    >>>>> print suffix

    >> ()
    >> --
    >> http://mail.python.org/mailman/listinfo/python-list
    >>

    >
    > Yes, I have seen that, but I cant get it working as expected (or it
    > doesent to what expected at all). I cant make it return values like:
    > jnxBgpM2PeerIdentifier.0.ipv4.38.101.161.119.1.38.101.161.118 (the one
    > of many I got from snmpwalk) but instead I am getting bunch of words
    > like iso, internet, mgmt, which is no way close to desired effect.
    > Still no luck - anybody with a clue?



    Every node in a MIB file is rooted at iso.org.dod.internet.
    jnxBgpM2PeerIdentifier has OID .1.3.6.1.4.1.2636.5.1.1.2.1.1.1.1
    (if I've got the right MIB, I searched for jnxBgpM2PeerIdentifier on
    Google and got the BGP4-V2-MIB-JUNIPER MIB file). The .1.3.6.1.4.1
    corresponds to iso.org.dod.internet.private.enterprises, so you can
    safely skip that part. The next value 2636, is uniquely assigned to
    Juniper, and the rest is up to whatever scheme Juniper uses to prepare
    mibs.

    The pysnmp library doesn't know anything about BGP4-V2-MIB-JUNIPER MIB,
    since it is not one of the standard MIBS, so it will parse everything up
    to what is defined in the standard mibs and return the rest in numeric
    form. There was a paragraph on the page I linked which described how to
    prepare MIB files for consumption by pysnmp. Did you try that?
    Shantanu Joshi, Mar 6, 2009
    #9
  10. SpamMePlease PleasePlease

    birdsong Guest

    On Mar 5, 11:22 pm, SpamMePlease PleasePlease
    <> wrote:
    > On Fri, Mar 6, 2009 at 1:10 AM, birdsong <> wrote:
    > > On Mar 5, 2:30 pm, SpamMePlease PleasePlease
    > > <> wrote:
    > >> On Thu, Mar 5, 2009 at 10:12 PM, birdsong <> wrote:
    > >> > On Mar 5, 1:05 pm, birdsong <> wrote:
    > >> >> On Mar 5, 12:32 pm, SpamMePlease PleasePlease

    >
    > >> >> <> wrote:
    > >> >> > Hey list,

    >
    > >> >> > I was given a task, to reproduce functionality of command specified
    > >> >> > below by writing proper python functions to reuse in some monitoring
    > >> >> > script:

    >
    > >> >> > rivendell# snmpwalk -Os -mALL -v1 -cgabilgathol 10.0.6.66
    > >> >> > .1.3.6.1.4.1.2636.5.1.1.2
    > >> >> > jnxBgpM2PeerIdentifier.0.ipv4."".unknown."".0.1.38.101.87.145 =
    > >> >> > STRING: 66.250.1.253
    > >> >> > jnxBgpM2PeerIdentifier.0.ipv4.38.101.161.119.1.38.101.161.118 =
    > >> >> > STRING: 66.28.1.85
    > >> >> > jnxBgpM2PeerIdentifier.0.ipv4.64.200.59.74.1.64.200.59.73 = STRING: 64.200.68.12
    > >> >> > jnxBgpM2PeerIdentifier.0.ipv4.72.37.131.250.1.72.37.131.249 = STRING:
    > >> >> > 64.235.224.240
    > >> >> > jnxBgpM2PeerState.0.ipv4."".unknown."".0.1.38.101.87.145 = INTEGER:
    > >> >> > established(6)
    > >> >> > jnxBgpM2PeerState.0.ipv4.38.101.161.119.1.38.101.161.118 = INTEGER:
    > >> >> > established(6)
    > >> >> > jnxBgpM2PeerState.0.ipv4.64.200.59.74.1.64.200.59.73 = INTEGER: established(6)
    > >> >> > jnxBgpM2PeerState.0.ipv4.72.37.131.250.1.72.37.131.249 = INTEGER: established(6)
    > >> >> > (more output)

    >
    > >> >> > I have already found a pysnmp library to fetch the data from the
    > >> >> > device with a minimal amount of code:

    >
    > >> >> > from pysnmp.entity.rfc3413.oneliner import cmdgen
    > >> >> > from pysnmp.smi import *
    > >> >> > import string

    >
    > >> >> > cmdGen = cmdgen.CommandGenerator()
    > >> >> > errorIndication, errorStatus, errorIndex, varBinds =
    > >> >> > cmdgen.CommandGenerator().nextCmd(cmdgen.CommunityData('AmonMuil',
    > >> >> > 'gabilgathol', 0),
    > >> >> > cmdgen.UdpTransportTarget(('fw-1.datacenter.gondor.net', 161)),
    > >> >> > (1,3,6,1,4,1,2636,5,1,1,2))

    >
    > >> >> > print errorIndication, errorStatus
    > >> >> > for i in varBinds:
    > >> >> >     print i

    >
    > >> >> > The problem is that I have completely stuck on the result I am
    > >> >> > experiencing being totally human unreadable, like this:

    >
    > >> >> > rivendell# python snmp.py
    > >> >> > None 0
    > >> >> > [(ObjectName('1.3.6.1.4.1.2636.5.1.1.2.1.1.1.1.0.1.0.0.0.0.1.38.101.87.145'),
    > >> >> > OctetString('B\xfa\x01\xfd'))]
    > >> >> > [(ObjectName('1.3.6.1.4.1.2636.5.1.1.2.1.1.1.1.0.1.38.101.161.119..1.38.101.161.118'),
    > >> >> > OctetString('B\x1c\x01U'))]
    > >> >> > [(ObjectName('1.3.6.1.4.1.2636.5.1.1.2.1.1.1.1.0.1.64.200.59.74.1..64.200.59.73'),
    > >> >> > OctetString('@\xc8D\x0c'))]
    > >> >> > [(ObjectName('1.3.6.1.4.1.2636.5.1.1.2.1.1.1.1.0.1.72.37.131.250.1.72.37.131.249'),
    > >> >> > OctetString('@\xeb\xe0\xf0'))]
    > >> >> > [(ObjectName('1.3.6.1.4.1.2636.5.1.1.2.1.1.1.2.0.1.0.0.0.0.1.38.101.87.145'),
    > >> >> > Integer32('6'))]
    > >> >> > [(ObjectName('1.3.6.1.4.1.2636.5.1.1.2.1.1.1.2.0.1.38.101.161.119..1.38.101.161.118'),
    > >> >> > Integer32('6'))]
    > >> >> > [(ObjectName('1.3.6.1.4.1.2636.5.1.1.2.1.1.1.2.0.1.64.200.59.74.1..64.200.59.73'),
    > >> >> > Integer32('6'))]
    > >> >> > [(ObjectName('1.3.6.1.4.1.2636.5.1.1.2.1.1.1.2.0.1.72.37.131.250.1.72.37.131.249'),
    > >> >> > Integer32('6'))]
    > >> >> > [(ObjectName('1.3.6.1.4.1.2636.5.1.1.2.1.1.1.3.0.1.0.0.0.0.1.38.101.87.145'),
    > >> >> > Integer32('2'))]

    >
    > >> >> > Since I cant find any way to translate these numbers to the same thing
    > >> >> > snmpwalk produce, is there any clue on how to achieve that? Is it
    > >> >> > possible at all for different devices (this one happend to be Juniper
    > >> >> > firewall if that does matter). Also, how can I know where does this
    > >> >> > magic oid ends and where does additional information starts (like ip
    > >> >> > addresses added to oid 0 they all looks like another oid string
    > >> >> > numbers) ?

    >
    > >> >> > Any sample of code, or hint to another lib will be very appreciated!

    >
    > >> >> > --
    > >> >> > --------------------
    > >> >> > Spank The Spam!

    >
    > >> >> Here's an example of walk that's part of a class I wrote, hopefully
    > >> >> indentation survives the paste.  I borrowed heavily from example code
    > >> >> on the pysnmp site.

    >
    > >> >> from pysnmp import asn1, v2c
    > >> >> from pysnmp import role

    >
    > >> >>   def walk(self, community_string, base_oids):

    >
    > >> >>     if type(base_oids) is str: base_oids = [base_oids]
    > >> >>     # this this does what it says, dont bother asking for oids that
    > >> >> we'll see in our walk
    > >> >>     base_oids = self.remove_child_oids(base_oids)
    > >> >>     # h_pair is just (host, port)
    > >> >>     client = role.manager(self.h_pair)
    > >> >>     client.timeout = 10
    > >> >>     req = v2c.GETNEXTREQUEST(community=community_string)
    > >> >>     rsp = v2c.GETRESPONSE()
    > >> >>     req['encoded_oids'] = map(asn1.OBJECTID().encode, base_oids)

    >
    > >> >>     oids_values = {}
    > >> >>     while req['encoded_oids']:
    > >> >>       try:
    > >> >>         answer, host_tuple = client.send_and_receive(req.encode())
    > >> >>       except (role.NoResponse, role.NetworkError):
    > >> >>         return oids_values

    >
    > >> >>       rsp.decode(answer)

    >
    > >> >>       parsed_oids_vals = self.parse_response(rsp, base_oids)
    > >> >>       oids_values.update(parsed_oids_vals)

    >
    > >> >>       req['request_id'] += 1
    > >> >>       req['encoded_oids'] = map(asn1.OBJECTID().encode,
    > >> >> parsed_oids_vals.keys())

    >
    > >> >>     return oids_values

    >
    > >> > Just realized the parse_response() is needed to makes sense of it:

    >
    > >> > def parse_response(self, rsp, head_oids):
    > >> >    # list of indices
    > >> >    overshot_oids = []

    >
    > >> >    vals = map(lambda x: x[0](), map(asn1.decode, rsp
    > >> > ['encoded_vals']))
    > >> >    oids = map(lambda x: asn1.OBJECTID().decode(x)[0], rsp
    > >> > ['encoded_oids'])
    > >> >    oids_vals = dict(map(None, oids, vals))

    >
    > >> >    for oid in oids_vals:
    > >> >      if not filter(lambda h: asn1.OBJECTID(h).isaprefix(oid),
    > >> > head_oids):
    > >> >        overshot_oids.append(oid)

    >
    > >> >    map(lambda x: oids_vals.pop(x), overshot_oids)

    >
    > >> >    return oids_vals

    >
    > >> > I welcome critique btw, I'm here to learn.
    > >> > --
    > >> >http://mail.python.org/mailman/listinfo/python-list

    >
    > >> Sorry, but I dont understand the code at all. Where does it takes the
    > >> names for the oid numbers? Why the translation needs a 'walk' at all?
    > >> Isnt that possible to perform an acion on given oid (my code produces
    > >> a list of them) to translate it to human readable output like snmpwalk
    > >> binary does?

    >
    > >> --
    > >> --------------------
    > >> Spank The Spam!

    >
    > > I haven't looked at the newer version of pysnmp, but I dont know if
    > > there's a library that maps oids to human readable oids.  Besides, I
    > > didn't really need to read the OIDs as a human, I wanted the values
    > > for injecting into data stores.  Here's a link I found really helpful
    > > while figuring out my necessary OIDs
    > >http://www.oid-info.com/

    >
    > Well, lucky you. Unfortunately I do need this oids in human readable
    > form, as I need to present them (output of my code) to humans.
    >
    > > I was responding to your call for example code.  I didn't get this in
    > > the first 2 hours I poured over pysnmp either. Experiment in the
    > > interpreter, you'll get it. You should be able to use my two functions
    > > with very minor editing to walk an oid and return values in a
    > > dictionary. The values will have already been decoded to something you
    > > should recognize.
    > > --
    > >http://mail.python.org/mailman/listinfo/python-list

    >
    > My call for example code was for code that actually translates
    > "1.3.6.1.4.1.2636.5.1.1.2.1.1.1.1.0.1.0.0.0.0.1.38.101.87.145" to
    > "jnxBgpM2PeerIdentifier.0.ipv4.38.101.161.119.1.38.101.161.118" so the
    > second one could be read by human to make some decisions. I dont
    > really need to walk oids, as my small code already gives me even more
    > than I need, now I just have to translate them to the same form as
    > snmpwalk binary does. And I have no idea how to do so.
    >
    > --
    > --------------------
    > Spank The Spam!


    Words like iso, internet, mgmt ? Who'da thunk?

    One from one guy who doesn't have a 'clue' to another of the same,
    best of luck in your python snmp endeavors.
    birdsong, Mar 6, 2009
    #10
  11. On Fri, Mar 6, 2009 at 9:03 AM, Shantanu Joshi <> wrote:
    >
    > SpamMePlease PleasePlease <> writes:
    >
    >> On Fri, Mar 6, 2009 at 6:56 AM, Shantanu Joshi <> wrote:
    >>> You need to parse the MIB file to get the human-readable names
    >>> corresponding to the OIDs. The pysnmp library already provides this
    >>> functionality. I haven't used this feature myself (I mainly use pysnmp
    >>> to automate SNMP walk requests, like the one in your code), but the
    >>> documentation at found the below example at
    >>> http://pysnmp.sourceforge.net/docs/4.1.x/index.html#MIB-SERVICES.
    >>>
    >>>
    >>>>>> from pysnmp.smi import builder, view
    >>>>>>
    >>>>>> mibBuilder = builder.MibBuilder().loadModules('SNMPv2-MIB')
    >>>>>> mibViewController = view.MibViewController(mibBuilder)
    >>>>>>
    >>>>>> oid,label,suffix = mibViewController.getNodeName((1,3,6,1,2,'mib-2',1,'sysDescr'))
    >>>>>> print oid
    >>> (1, 3, 6, 1, 2, 1, 1, 1)
    >>>>>> print label
    >>> ('iso', 'org', 'dod', 'internet', 'mgmt', 'mib-2', 'system', 'sysDescr')
    >>>>>> print suffix
    >>> ()
    >>> --
    >>> http://mail.python.org/mailman/listinfo/python-list
    >>>

    >>
    >> Yes, I have seen that, but I cant get it working as expected (or it
    >> doesent to what expected at all). I cant make it return values like:
    >> jnxBgpM2PeerIdentifier.0.ipv4.38.101.161.119.1.38.101.161.118 (the one
    >> of many I got from snmpwalk) but instead I am getting bunch of words
    >> like iso, internet, mgmt, which is no way close to desired effect.
    >> Still no luck - anybody with a clue?

    >
    >
    > Every node in a MIB file is rooted at iso.org.dod.internet.
    > jnxBgpM2PeerIdentifier has OID .1.3.6.1.4.1.2636.5.1.1.2.1.1.1.1
    > (if I've got the right MIB, I searched for jnxBgpM2PeerIdentifier on
    > Google and got the BGP4-V2-MIB-JUNIPER MIB file). The .1.3.6.1.4.1
    > corresponds to iso.org.dod.internet.private.enterprises, so you can
    > safely skip that part. The next value 2636, is uniquely assigned to
    > Juniper, and the rest is up to whatever scheme Juniper uses to prepare
    > mibs.
    >
    > The pysnmp library doesn't know anything about BGP4-V2-MIB-JUNIPER MIB,
    > since it is not one of the standard MIBS, so it will parse everything up
    > to what is defined in the standard mibs and return the rest in numeric
    > form. There was a paragraph on the page I linked which described how to
    > prepare MIB files for consumption by pysnmp. Did you try that?
    >
    >
    > --
    > http://mail.python.org/mailman/listinfo/python-list
    >


    Thats a good one, sir! I managed to create jnx-bgpmib2.py out from
    /usr/share/snmp/mibs/jnx-bgpmib2.txt that contains the mibs snmpwalk
    found for me. Now, in what way can I 'feed' the pysnmp with this new
    file and how to ask it kindly to convert these number strings into
    nice readable strings?

    --
    --------------------
    Spank The Spam!
    SpamMePlease PleasePlease, Mar 6, 2009
    #11
  12. SpamMePlease PleasePlease <> writes:

    >
    > I actually tried to load the new file with following code:
    >
    > print builder.MibBuilder().getMibPath()
    > mibBuilder = builder.MibBuilder().loadModules('jnx-bgpmib2')
    >
    > but I am experiencing the error:
    >
    > rivendell # python snmp.py
    > ('/usr/lib/python2.4/site-packages/pysnmp/v4/smi/mibs/instances',
    > '/usr/lib/python2.4/site-packages/pysnmp/v4/smi/mibs')
    > Traceback (most recent call last):
    > File "snmp.py", line 7, in ?
    > mibBuilder = builder.MibBuilder().loadModules('jnx-bgpmib2')
    > File "//usr/lib/python2.4/site-packages/pysnmp/v4/smi/builder.py",
    > line 82, in loadModules
    > raise error.SmiError(
    > pysnmp.smi.error.SmiError: MIB module
    > "/usr/lib/python2.4/site-packages/pysnmp/v4/smi/mibs/instances/jnx-bgpmib2.py"
    > load error: MIB file ".py" not found in search path
    > rivendell# ls -lA
    > /usr/lib/python2.4/site-packages/pysnmp/v4/smi/mibs/instances/jnx-bgpmib2.py
    > -rw-r--r-- 1 root root 2687 Mar 6 06:50
    > /usr/lib/python2.4/site-packages/pysnmp/v4/smi/mibs/instances/jnx-bgpmib2.py
    >
    > Any clue what about is done wrong?


    The pysnmp library is not able to find your generated file. Either copy
    your generated file to /usr/lib/python2.4/site-packages/pysnmp/v4/smi/mibs/instances
    or call setMibPath on the mibBuilder instance before calling loadModules
    to add the current directory (or whatever directory holds your generated
    file).
    Shantanu Joshi, Mar 6, 2009
    #12
  13. On Fri, Mar 6, 2009 at 2:14 PM, Shantanu Joshi <> wrote:
    >
    > SpamMePlease PleasePlease <> writes:
    >
    >>
    >> I actually tried to load the new file with following code:
    >>
    >> print builder.MibBuilder().getMibPath()
    >> mibBuilder = builder.MibBuilder().loadModules('jnx-bgpmib2')
    >>
    >> but I am experiencing the error:
    >>
    >> rivendell # python snmp.py
    >> ('/usr/lib/python2.4/site-packages/pysnmp/v4/smi/mibs/instances',
    >> '/usr/lib/python2.4/site-packages/pysnmp/v4/smi/mibs')
    >> Traceback (most recent call last):
    >>   File "snmp.py", line 7, in ?
    >>     mibBuilder = builder.MibBuilder().loadModules('jnx-bgpmib2')
    >>   File "//usr/lib/python2.4/site-packages/pysnmp/v4/smi/builder.py",
    >> line 82, in loadModules
    >>     raise error.SmiError(
    >> pysnmp.smi.error.SmiError: MIB module
    >> "/usr/lib/python2.4/site-packages/pysnmp/v4/smi/mibs/instances/jnx-bgpmib2.py"
    >> load error: MIB file ".py" not found in search path
    >> rivendell# ls -lA
    >> /usr/lib/python2.4/site-packages/pysnmp/v4/smi/mibs/instances/jnx-bgpmib2.py
    >> -rw-r--r-- 1 root root 2687 Mar  6 06:50
    >> /usr/lib/python2.4/site-packages/pysnmp/v4/smi/mibs/instances/jnx-bgpmib2.py
    >>
    >> Any clue what about is done wrong?

    >
    > The pysnmp library is not able to find your generated file. Either copy
    > your generated file to /usr/lib/python2.4/site-packages/pysnmp/v4/smi/mibs/instances
    > or call setMibPath on the mibBuilder instance before calling loadModules
    > to add the current directory (or whatever directory holds your generated
    > file).
    > --
    > http://mail.python.org/mailman/listinfo/python-list
    >


    The thing is that I have copied the file (as you may see, I did 'ls
    -lA' on it. If the file wasnt there, the error message was different.
    Also, the setMibPath doesent seem to work, as I tried to set up it to
    any value, and right after that I was performing getMibPath which was
    giving me unchanged default paths. Keep in mind, that whole path setu
    up code has executed without any error.
    So, what is correct and working way to supply my code with that
    converted mib file?

    --
    --------------------
    Spank The Spam!
    SpamMePlease PleasePlease, Mar 7, 2009
    #13
  14. SpamMePlease PleasePlease

    Guest

    SpamMePlease PleasePlease <> wrote:
    > On Fri, Mar 6, 2009 at 2:14 PM, Shantanu Joshi <> wrote:
    > >
    > > SpamMePlease PleasePlease <> writes:
    > >
    > >> I actually tried to load the new file with following code:
    > >>
    > >> print builder.MibBuilder().getMibPath()
    > >> mibBuilder = builder.MibBuilder().loadModules('jnx-bgpmib2')
    > >>
    > >> but I am experiencing the error:
    > >>
    > >> rivendell # python snmp.py
    > >> ('/usr/lib/python2.4/site-packages/pysnmp/v4/smi/mibs/instances',
    > >> '/usr/lib/python2.4/site-packages/pysnmp/v4/smi/mibs')
    > >> Traceback (most recent call last):
    > >>   File "snmp.py", line 7, in ?
    > >>     mibBuilder = builder.MibBuilder().loadModules('jnx-bgpmib2')
    > >>   File "//usr/lib/python2.4/site-packages/pysnmp/v4/smi/builder.py",
    > >> line 82, in loadModules
    > >>     raise error.SmiError(
    > >> pysnmp.smi.error.SmiError: MIB module
    > >> "/usr/lib/python2.4/site-packages/pysnmp/v4/smi/mibs/instances/jnx-bgpmib2.py"
    > >> load error: MIB file ".py" not found in search path
    > >> rivendell# ls -lA
    > >> /usr/lib/python2.4/site-packages/pysnmp/v4/smi/mibs/instances/jnx-bgpmib2.py
    > >> -rw-r--r-- 1 root root 2687 Mar  6 06:50
    > >> /usr/lib/python2.4/site-packages/pysnmp/v4/smi/mibs/instances/jnx-bgpmib2.py
    > >>
    > >> Any clue what about is done wrong?

    > >
    > > The pysnmp library is not able to find your generated file. Either copy
    > > your generated file to /usr/lib/python2.4/site-packages/pysnmp/v4/smi/mibs/instances
    > > or call setMibPath on the mibBuilder instance before calling loadModules
    > > to add the current directory (or whatever directory holds your generated
    > > file).
    > > --
    > > http://mail.python.org/mailman/listinfo/python-list
    > >

    >
    > The thing is that I have copied the file (as you may see, I did 'ls
    > -lA' on it. If the file wasnt there, the error message was different.
    > Also, the setMibPath doesent seem to work, as I tried to set up it to
    > any value, and right after that I was performing getMibPath which was
    > giving me unchanged default paths. Keep in mind, that whole path setu
    > up code has executed without any error.
    > So, what is correct and working way to supply my code with that
    > converted mib file?


    I have absolutely no knowledge of pysnmp, but from reading the error
    message I'd guess that you have a '.py' somewhere where you shouldn't.
    Either the filename shouldn't have a .py, or you are referring to
    the thing to be loaded with a '.py' on the end of the name when you
    should be omitting it.

    But like I said, I'm speaking out of my hat here, since I've never
    worked with pysnmp.

    --RDM
    , Mar 7, 2009
    #14
  15. On Sat, Mar 7, 2009 at 8:33 PM, <> wrote:
    > SpamMePlease PleasePlease <> wrote:
    >> On Fri, Mar 6, 2009 at 2:14 PM, Shantanu Joshi <> wrote:
    >> >
    >> > SpamMePlease PleasePlease <> writes:
    >> >
    >> >> I actually tried to load the new file with following code:
    >> >>
    >> >> print builder.MibBuilder().getMibPath()
    >> >> mibBuilder = builder.MibBuilder().loadModules('jnx-bgpmib2')
    >> >>
    >> >> but I am experiencing the error:
    >> >>
    >> >> rivendell # python snmp.py
    >> >> ('/usr/lib/python2.4/site-packages/pysnmp/v4/smi/mibs/instances',
    >> >> '/usr/lib/python2.4/site-packages/pysnmp/v4/smi/mibs')
    >> >> Traceback (most recent call last):
    >> >>   File "snmp.py", line 7, in ?
    >> >>     mibBuilder = builder.MibBuilder().loadModules('jnx-bgpmib2')
    >> >>   File "//usr/lib/python2.4/site-packages/pysnmp/v4/smi/builder.py",
    >> >> line 82, in loadModules
    >> >>     raise error.SmiError(
    >> >> pysnmp.smi.error.SmiError: MIB module
    >> >> "/usr/lib/python2.4/site-packages/pysnmp/v4/smi/mibs/instances/jnx-bgpmib2.py"
    >> >> load error: MIB file ".py" not found in search path
    >> >> rivendell# ls -lA
    >> >> /usr/lib/python2.4/site-packages/pysnmp/v4/smi/mibs/instances/jnx-bgpmib2.py
    >> >> -rw-r--r-- 1 root root 2687 Mar  6 06:50
    >> >> /usr/lib/python2.4/site-packages/pysnmp/v4/smi/mibs/instances/jnx-bgpmib2.py
    >> >>
    >> >> Any clue what about is done wrong?
    >> >
    >> > The pysnmp library is not able to find your generated file. Either copy
    >> > your generated file to /usr/lib/python2.4/site-packages/pysnmp/v4/smi/mibs/instances
    >> > or call setMibPath on the mibBuilder instance before calling loadModules
    >> > to add the current directory (or whatever directory holds your generated
    >> > file).
    >> > --
    >> > http://mail.python.org/mailman/listinfo/python-list
    >> >

    >>
    >> The thing is that I have copied the file (as you may see, I did 'ls
    >> -lA' on it. If the file wasnt there, the error message was different.
    >> Also, the setMibPath doesent seem to work, as I tried to set up it to
    >> any value, and right after that I was performing getMibPath which was
    >> giving me unchanged default paths. Keep in mind, that whole path setu
    >> up code has executed without any error.
    >> So, what is correct and working way to supply my code with that
    >> converted mib file?

    >
    > I have absolutely no knowledge of pysnmp, but from reading the error
    > message I'd guess that you have a '.py' somewhere where you shouldn't.
    > Either the filename shouldn't have a .py, or you are referring to
    > the thing to be loaded with a '.py' on the end of the name when you
    > should be omitting it.
    >
    > But like I said, I'm speaking out of my hat here, since I've never
    > worked with pysnmp.
    >
    > --RDM
    >
    > --
    > http://mail.python.org/mailman/listinfo/python-list
    >


    All modules in mentioned by pysnmp directory have .py in name, and
    while invoked in the code, they dont. But I also tried some
    combinations, with no luck.

    --
    --------------------
    Spank The Spam!
    SpamMePlease PleasePlease, Mar 7, 2009
    #15
  16. SpamMePlease PleasePlease <> writes:

    > On Fri, Mar 6, 2009 at 2:14 PM, Shantanu Joshi <> wrote:
    >>
    >> SpamMePlease PleasePlease <> writes:
    >>

    > .. snip
    >
    > The thing is that I have copied the file (as you may see, I did 'ls
    > -lA' on it. If the file wasnt there, the error message was different.
    > Also, the setMibPath doesent seem to work, as I tried to set up it to
    > any value, and right after that I was performing getMibPath which was
    > giving me unchanged default paths. Keep in mind, that whole path setu
    > up code has executed without any error.
    > So, what is correct and working way to supply my code with that
    > converted mib file?


    Works for me.

    > [shantanu@tiamat:~/Documents/snmp]$ ls
    > AV-AES-MIB.mib
    > [shantanu@tiamat:~/Documents/snmp]$ smidump AV-AES-MIB.mib -k > AV-AES-MIB.txt
    > smidump: module `AV-AES-MIB.mib' contains errors, expect flawed output
    > [shantanu@tiamat:~/Documents/snmp]$ build-pysnmp-mib AV-AES-MIB.txt > AV-AES-MIB.py
    > [shantanu@tiamat:~/Documents/snmp]$ ls
    > AV-AES-MIB.mib AV-AES-MIB.txt AV-AES-MIB.py
    > [shantanu@tiamat:~/Documents/snmp]$ sudo cp AV-AES.py /usr/lib/python2.5/site-packages/pysnmp/v4/smi/mibs/instances
    > [shantanu@tiamat:~/Documents/snmp]$ ls /usr/lib/python2.5/site-packages/pysnmp/v4/smi/mibs/instances
    > AV-AES-MIB.py __SNMP-FRAMEWORK-MIB.py __SNMP-MPD-MIB.pyc __SNMP-USER-BASED-SM-MIB.py __SNMP-VIEW-BASED-ACM-MIB.pyc __init__.py
    > __PYSNMP-USM-MIB.py __SNMP-FRAMEWORK-MIB.pyc __SNMP-TARGET-MIB.py __SNMP-USER-BASED-SM-MIB.pyc __SNMPv2-MIB.py __init__.pyc
    > __PYSNMP-USM-MIB.pyc __SNMP-MPD-MIB.py __SNMP-TARGET-MIB.pyc __SNMP-VIEW-BASED-ACM-MIB.py __SNMPv2-MIB.pyc
    > [shantanu@tiamat:~/Documents/snmp]$
    > [shantanu@tiamat:~/Documents/snmp]$ ipython
    > Python 2.5.2 (r252:60911, Sep 30 2008, 15:41:38)
    > Type "copyright", "credits" or "license" for more information.
    >
    > IPython 0.8.4 -- An enhanced Interactive Python.
    > ? -> Introduction and overview of IPython's features.
    > %quickref -> Quick reference.
    > help -> Python's own help system.
    > object? -> Details about 'object'. ?object also works, ?? prints more.
    >
    > In [1]: from pysnmp.smi import builder, view
    >
    > In [2]: mibBuilder = builder.MibBuilder().loadModules('AV-AES-MIB')
    >
    > In [3]: mibViewController = view.MibViewController(mibBuilder)
    >
    > In [4]: oid, label, suffix = mibViewController.getNodeName((1,3,6,1,4,1,6889,2,27,2,2,2))
    >
    > In [5]: print oid
    > (1, 3, 6, 1, 4, 1, 6889, 2, 27, 2, 2)
    >
    > In [6]: print label
    > ('iso', 'org', 'dod', 'internet', 'private', 'enterprises', [...])
    >
    > In [7]: print suffix
    > (2,)
    >
    > In [8]:


    I think you should check that the file you are generating is correct,
    and can be read properly. If that doesn't help, you should try on the
    pysnmp-users mailing list at http://sourceforge.net/mail/?group_id=14735.
    Shantanu Joshi, Mar 9, 2009
    #16
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Konstantin Shemyak

    Human-readable storage for types (with no pointers)?

    Konstantin Shemyak, Sep 9, 2003, in forum: C Programming
    Replies:
    4
    Views:
    362
    Ben Pfaff
    Sep 12, 2003
  2. Maxim Khesin

    lightweight human-readable config?

    Maxim Khesin, Oct 29, 2003, in forum: Python
    Replies:
    13
    Views:
    631
    Larry Bates
    Oct 31, 2003
  3. Jonah Bossewitch

    human readable IPTC field names

    Jonah Bossewitch, Jan 12, 2005, in forum: Python
    Replies:
    0
    Views:
    387
    Jonah Bossewitch
    Jan 12, 2005
  4. Alex Willmer

    Human readable number formatting

    Alex Willmer, Sep 28, 2005, in forum: Python
    Replies:
    9
    Views:
    634
  5. Ulf Meinhardt
    Replies:
    0
    Views:
    478
    Ulf Meinhardt
    Sep 13, 2009
Loading...

Share This Page