Giter VIP home page Giter VIP logo

Comments (9)

vincentbernat avatar vincentbernat commented on June 5, 2024

Since both tables use the same index, you only have to walk one:

for idx in m.ifDescr:
   print(m.ifName[idx], m.dot3StatsFCSErrors[idx])

from snimpy.

gavmckee80 avatar gavmckee80 commented on June 5, 2024
In [69]: for idx in m.ifDescr:
    ...:    print(m.ifName[idx], m.dot3StatsFCSErrors[idx])
    ...:
---------------------------------------------------------------------------
SNMPNoSuchInstance                        Traceback (most recent call last)
<ipython-input-69-ef67b7dfd542> in <module>()
      1 for idx in m.ifDescr:
----> 2    print(m.ifName[idx], m.dot3StatsFCSErrors[idx])
      3

Looks like this throws an exception

If I walk the EtherLike table on its own

In [70]: for idx in m.dot3StatsTable:
...: print m.dot3StatsFCSErrors[idx], m.dot3StatsDuplexStatus[idx]
...:
0 fullDuplex(3)
0 fullDuplex(3)
0 fullDuplex(3)

from snimpy.

vincentbernat avatar vincentbernat commented on June 5, 2024

Just catch the exception and continue the loop. Or walk m.dot3StatsTable instead of m.ifDescr.

for idx in m.dot3StatsTable:
    print m.dot3StatsFCSErrors[idx], m.dot3StatsDuplexStatus[idx], m.ifName[idx]

from snimpy.

gavmckee80 avatar gavmckee80 commented on June 5, 2024

Thanks @vincentbernat

from snimpy.

gavmckee80 avatar gavmckee80 commented on June 5, 2024

@vincentbernat - a final quick question
I'm building a document to submit to elastic / influx or any other backend DB

In [150]:
     ...: for idx in m.ifDescr:
     ...:     try:
     ...:         if m.ifAdminStatus[idx] == "up" and m.ifOperStatus[idx] == "up":
     ...:             ifHCInOctets = m.ifHCInOctets[idx]
     ...:             ifHCOutOctets = m.ifHCOutOctets[idx]
     ...:             ifHCInMulticastPkts = m.ifHCInMulticastPkts[idx]
     ...:             ifLastChange = m.ifLastChange[idx]
     ...:
     ...:             {'measurement': '<measurement_name>',
     ...:             'tags':{'hostname':'<hostname>','interface':m.ifName[idx]},
     ...:             'fields':{
     ...:             }
     ...:             }
     ...:             print {'test':ifHCInOctets}
     ...:             #print("{} {} {} {} {}".format(m.ifName[idx],m.ifAlias[idx],m.ifHCInOctets[idx],m.dot3StatsFCSErrors[idx],m.ifLastChange[idx]))
     ...:     except Exception as e:
     ...:         print e
     ...:         #print m.ifName[idx], m.ifHCInOctets[idx], m.ifLastChange[idx]
     ...:
{'test': <Unsigned64: 5520318006>}
{'test': <Unsigned64: 757231301>}
{'test': <Unsigned64: 726847832>}
{'test': <Unsigned64: 1040544110>}

How do i get the value instead of the Unsigned64 object being added to the dict?

from snimpy.

vincentbernat avatar vincentbernat commented on June 5, 2024

The Unsigned64 type should behave just like an int. However, you can coerce it as int with int(ifHCInOctets).

from snimpy.

cbueche avatar cbueche commented on June 5, 2024

A little bit related to your issue: not all interface tables indexed by idx are the same length or contain values for each idx, this is why you sometimes get exceptions. So you may want to check InterfaceAPI / get() in https://github.com/cbueche/Agent-Jones/blob/master/aj/aj.py
I collect all tables (descr, name, status, etc) independently using bulk-get, and then join them together starting at line 727.

Not an example of good coding, but the idea works well.

from snimpy.

gavmckee80 avatar gavmckee80 commented on June 5, 2024

thanks @vincentbernat
@cbueche - thanks for sharing , this is a very interesting approach. Most open source projects (telegraf) are really hard to scale. I want to collect data from around 1500 devices , mostly Cisco N3K, some 5K/7K, Arista and L1 switches.

from snimpy.

cbueche avatar cbueche commented on June 5, 2024

Agent-Jones works since 2-3 years for a network service provider, with mostly Cisco IOS and XE. Nexus isn't really tested, especially redundant-connected fabric extenders are problematic (most likely in every NMS anyway). Please note Agent-Jones is built for device identification/inventory a few times per day, and not for rapid interface polling. This would be better done using some async.

from snimpy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.