my code is as below, somehow some issue
from easysnmp import Session
import time
import datetime
from math import log10
from collections import namedtuple
def conv(data):
print(data)
Record = namedtuple('Record',
"year month day hour minutes seconds deciseconds "
"direction hoursfromutc minutesfromutc")
x = data.replace(' ', '')
L = [x[0:4]] + [x[i:i+2] for i in range(4, len(x), 2)]
L = [int(s, 16) for s in L]
L[7] = chr(L[7])
manfdate = Record(*L)
manufactured_date=(str(manfdate[0])+'/'+str(manfdate[1])+'/'+str(manfdate[2]))
return manufactured_date
portOptical_details_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(3)
try:
tmnxPortOperStatus,tmnxPortTransceiverType,tmnxPortTransceiverLaserWaveLen,tmnxPortSFPConnectorCode,\
tmnxPortSFPVendorManufactureDate,tmnxPortTransceiverDiagCapable,tmnxPortSFPMedia,tmnxPortSFPVendorSerialNum,\
tmnxPortSFPVendorPartNum = (list(session.bulkwalk('1.3.6.1.4.1.6527.3.1.2.2.4.2.1.'+c, \
non_repeaters=0, max_repetitions=50))for c in ('38','25','27','30','32','28','33','45','46'))
except easysnmp.EasySNMPNoSuchInstanceError as e:
print('Error:- {}'.format(e))
finally:
portOptical = namedtuple('portOptical','PortOperStatus PortTransceiverType PortTransceiverLaserWaveLen \
PortSFPConnectorCode PortSFPVendorManufactureDate PortTransceiverDiagCapable \
PortSFPMedia PortSFPVendorSerialNum PortSFPVendorPartNum')
portOptical_inters = [portOptical(*uple) for uple in zip(*[tmnxPortOperStatus,tmnxPortTransceiverType,\
tmnxPortTransceiverLaserWaveLen,tmnxPortSFPConnectorCode,tmnxPortSFPVendorManufactureDate,\
tmnxPortTransceiverDiagCapable,tmnxPortSFPMedia,tmnxPortSFPVendorSerialNum,\
tmnxPortSFPVendorPartNum])]
for portOptical in portOptical_inters:
portOptical_details = {}
port_oid = portOptical.PortOperStatus.oid
portOptical_details['host'] = host
portOptical_details['portID'] = port_oid.split('.')[-1]
portOptical_details['interface'] = cli_interface(portOptical_details['portID'])
portOptical_details['PortOperStatus'] = get_PortOperStatus(portOptical.PortOperStatus.value)
portOptical_details['PortTransceiverType'] = get_PortTransceiverType(portOptical.PortTransceiverType.value)
portOptical_details['PortTransceiverLaserWaveLen'] = portOptical.PortTransceiverLaserWaveLen.value
portOptical_details['PortSFPConnectorCode'] = get_tmnxPortSFPConnectorCode(portOptical.PortSFPConnectorCode.value)
portOptical_details['PortSFPVendorManufactureDate'] = conv(portOptical.PortSFPVendorManufactureDate.value)
portOptical_details['PortTransceiverDiagCapable'] = get_PortTransceiverDiagCapable\
(portOptical.PortTransceiverDiagCapable.value)
portOptical_details['PortSFPMedia'] = get_tmnxPortSFPMedia(portOptical.PortSFPMedia.value)
portOptical_details['PortSFPVendorSerialNum'] = (portOptical.PortSFPVendorSerialNum.value).strip()
portOptical_details['PortSFPVendorPartNum'] = (portOptical.PortSFPVendorPartNum.value).strip()
for items in portOptical_details_list:
print(items['PortSFPVendorManufactureDate'])
Output:
Traceback (most recent call last):
File "NokiaPortOptical.py", line 179, in <module>
portOptical_details['PortSFPVendorManufactureDate'] = conv(portOptical.PortSFPVendorManufactureDate.value)
File "NokiaPortOptical.py", line 22, in conv
L = [int(s, 16) for s in L]
File "NokiaPortOptical.py", line 22, in <listcomp>
L = [int(s, 16) for s in L]
ValueError: invalid literal for int() with base 16: '\x07รข\x05\x08'