Comments (9)
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.
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.
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.
Thanks @vincentbernat
from snimpy.
@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.
The Unsigned64
type should behave just like an int. However, you can coerce it as int with int(ifHCInOctets)
.
from snimpy.
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.
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.
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)
- PMPP support? HOT 4
- snimpy/manager.py broken in Python 3.7
- how do I get an OID from a MIB node ? HOT 5
- How to get KEEPALIVED-MIB::vrrpSyncGroupState HOT 8
- print(mgr.fgVpnTunEntPhase1Name.items()) produces "snimpy.snmp.SNMPNoSuchInstance: No such instance exists" HOT 3
- BGP4-V2-MIB-JUNIPER, take 2
- Use the native Python ipaddress types HOT 4
- SNMP Community Strings greater than 32 characters crash HOT 2
- Confusing example in documentation HOT 1
- Return the pretty name from a referenced OID HOT 5
- Deprecation warning: snimpy not compatible with upcoming Python 3.10 HOT 2
- use unittest.mock instead of mock HOT 1
- Installation snimpy error on AlmaLinux 8.6 HOT 11
- Add how to add an new MIB path into the documentation HOT 1
- Migrate from unsupported pysnmp to pysnmp-lexstudio
- Publish a new release HOT 1
- testMultipleThreads failed HOT 2
- TestMain::test_loadfile gets stuck in 2038 HOT 4
- [HOW TO] walk over multiple node with manager?
- Occasional stucks with snimpy 1.0.2, working with 1.0.0 HOT 14
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from snimpy.