Oct-18-2019, 10:19 AM
Hi All,
something is going wrong and not able to understand. below code is polling lag interface details. I am not able to print using namedtuple.
something is going wrong and not able to understand. below code is polling lag interface details. I am not able to print using namedtuple.
tLagOperationEntry_list = [] for host in my_devices: try: session = Session(hostname=host, community='cacti', version=2) except easysnmp.EasySNMPConnectionError as e: print('Error:- {}'.format(e)) sys.exit(1) try: tLagIfIndex,tLagConfigLastChange,tLagLACPPrimaryPort\ = (list(session.bulkwalk('1.3.6.1.4.1.6527.3.1.2.15.3.1.'+c, \ non_repeaters=0, max_repetitions=50))for c in ('1','2','5')) except easysnmp.EasySNMPNoSuchInstanceError as e: print('Error:- {}'.format(e)) finally: tLagOperationEntry = namedtuple('tLagOperationEntry','LagIfIndex LagConfigLastChange LagLACPPrimaryPort') LagOperationEntry_inters = [tLagOperationEntry(*uple) for uple in zip(*[tLagIfIndex,tLagConfigLastChange,tLagLACPPrimaryPort])] for OperationEntry in LagOperationEntry_inters: tLagOperationEntry = {} tLagOperationEntry['host'] = host tLagOperationEntry['interface_index'] = OperationEntry.LagIfIndex.value tLagOperationEntry['LagConfigLastChange'] = OperationEntry.LagConfigLastChange.value tLagOperationEntry['LagLACPPrimaryPort'] = OperationEntry.LagLACPPrimaryPort.value tLagOperationEntry_list.append(tLags) for data in tLagOperationEntry_list: print(data['host'],data['interface_index'],data['LagConfigLastChange'],data['LagLACPPrimaryPort'])this code showing blank output, however I am able to print individual lists.
Output:[<SNMPVariable value='1342177330' (oid='enterprises.6527.3.1.2.15.3.1.1.50', oid_index='', snmp_type='INTEGER')>, <SNMPVariable value='1342177331' (oid='enterprises.6527.3.1.2.15.3.1.1.51', oid_index='', snmp_type='INTEGER')>, <SNMPVariable value='1342177332' (oid='enterprises.6527.3.1.2.15.3.1.1.52', oid_index='', snmp_type='INTEGER')>]