#!/usr/bin/python from easysnmp import Session community = 'public' with open('zyxeldslam.txt') as ipfile: for sr_no, line in enumerate(ipfile, start=1): ip = line.strip() try: # Create an SNMP session to be used for all our requests session = Session(hostname=ip, community=community, version=2) # You may retrieve an individual OID using an SNMP GET fan_oids_templ = '1.3.6.1.4.1.890.1.5.13.1.2.1.1.2.0.{}' temp_oids_templ = '1.3.6.1.4.1.890.1.5.13.1.2.3.1.2.0.0.{}' fans_oids = [fan_oids_templ.format(i) for i in range(1,4)] temps_oids = [temp_oids_templ.format(i) for i in range(1,4)] fans_status = ['Fail' if int(fan.value) < 2000 else 'Ok' for fan in session.get_bulk(fans_oids)] temp_status = [temp.value for value in session.get_bulk(temps_oids)] print('{} {} {} {} {} {} {} {}'.format(sr_no, ip, *fans_status, *temp_status)) except Exception as excp: print('Something went wrong!') print(excp)conversion to int -
int(fan.value)
may not be required if returned values is actually an integer - INTEGER: 4333.I assume it is still str, so I convert it.
some of the above can be done a bit different, e.g. there could be better way to construct oids, but I'm not familiar with the module - just reading the docs