简体   繁体   中英

Parsing snmp walk output using python

Can anyone suggest a good library or a method to parse the output similar to the following snmpwalk output.

The output is from a juniper box. I want to be able to extract things like the serial numbers and associate with the relevant components

The full output can be viewed here.

SOME_DEVICE_NAME,2636.3.1.1.0 : OBJECT IDENTIFIER: .iso.org.dod.internet.private.enterprises.2636.1.1.1.1.40.0
SOME_DEVICE_NAME,2636.3.1.2.0 : OCTET STRING- (ascii):     node1 Juniper SRX650 Internet Router
SOME_DEVICE_NAME,2636.3.1.3.0 : OCTET STRING- (ascii):     AJ5113AK0055
SOME_DEVICE_NAME,2636.3.1.4.0 : OCTET STRING- (ascii):
SOME_DEVICE_NAME,2636.3.1.5.0 : Timeticks: (2147483647) 248 days, 13:13:56.47

I would recommend to use some Python SNMP library to ease parsing the output.

You can use eg Net-SNMP Python Bindings . See docs for details.

Simplified example of usage:

import netsnmp

session = netsnmp.Session(DestHost="SOME_DEVICE_NAME", Version=2, Community="public")
session.UseLongNames = 1
session.UseNumeric = 1
oid=".1.3.6.1.4.1.2636.3.1"
vars = netsnmp.VarList(oid)
session.walk(vars)

# to check errors: if len(session.ErrorStr) > 0:

# to get output values
for item in vars:
        print item.val

Then you can use some regex parsing etc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM