0

I have the following Python code:

#!/usr/bin/python

import netsnmp

session = netsnmp.Session(DestHost='_destination address_', Version=2, Community='_string_')

vars = netsnmp.VarList(netsnmp.Varbind('ifIndex',), netsnmp.Varbind('ifDescr',), netsnmp.Varbind('ifOperStatus',))

print(session.getbulk(0, 48, vars))

The results of session.getbulk are as follows:

('1', 'Vlan1', '1', '2', 'Vlan2', '2', '10101', 'GigabitEthernet0/1', '2', '10102',
'GigabitEthernet0/2', '2', '10103', 'GigabitEthernet0/3', '2', '10104', 
'GigabitEthernet0/4', '2', '10105', 'GigabitEthernet0/5', '2', '10106', 
'GigabitEthernet0/6', '2', '10107', 'GigabitEthernet0/7', '2', '10108', 
'GigabitEthernet0/8', '2', '10109', 'GigabitEthernet0/9', '2', '10110', 
'GigabitEthernet0/10', '2', '10111', 'GigabitEthernet0/11', '2', '10112',  
'GigabitEthernet0/12', '2', '10113', 'GigabitEthernet0/13', '1', '10114', 
'GigabitEthernet0/14', '1', '10115', 'GigabitEthernet0/15', '2', '10116', 
'GigabitEthernet0/16', '1', '10117', 'GigabitEthernet0/17', '2')

I would like to print the information returned by session.getbulk on a newline per each interface. If my understanding of my program is correct, I should get three values for each interface, (ifIndex, ifDescr, and ifOperStatus.)

As it stands, the results are presented in a single block of information, and it may be hard for my audience to differentiate between.

However, being totally new to programming I am having a hard time figuring out how to do this. If anybody is willing to point me toward an appropriate tutorial or documentation for this, I'd much appreciate it.

Thanks!

Darwing
  • 833
  • 1
  • 12
  • 23
jschadt
  • 3
  • 2

1 Answers1

0

If I am understanding you correctly, I think this is what you want?:

result = session.getbulk(0, 48, vars)
for i in range(0, len(result), 3):
    print "ifind: "+result[i]+" ifdesc: "+result[i+1]+" status: "+result[i+2]
arobinson
  • 136
  • 2
  • 7
  • Yes, this was precisely what I was too dense to figure out! Thank you for your reply, I understand now that I see it done how simple it was. – jschadt Sep 25 '13 at 22:22