0
votes

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
1

1 Answers

0
votes

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

You can use e.g. 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.