def __init__(self, targets): self.requests = [] self.targets = targets self.results = [] self.community_string = get_config('snmp')['COMM_STRING'] self.timeout = get_config('snmp')['TIMEOUT'] self.snmpEngine = SnmpEngine() self.mibBuilder = self.snmpEngine.getMibBuilder() self.mibViewController = view.MibViewController(self.mibBuilder) self.loop = asyncio.get_event_loop()
def test_config_oids(): config = conf.get_config('oids') assert type(config) is defaultdict for equipment in config.items(): assert type(equipment) is tuple
def test_targets_config(): config = conf.get_config('targets') for target in config: for equipment in config[target]['equipment']: assert 'ip' in equipment assert 'type' in equipment
def test_oids_config(): config = conf.get_config('oids') for equipment in config: for oid_entry in config[equipment]: for label in oid_entry: assert label
def test_build_equipment(): targets_blob = config.get_config('targets') snmp_targets = build.racks(targets_blob) for target in snmp_targets: assert type(target) is Rack for equipment in target.contains: assert type(equipment) is Equipment for oid in equipment.oid_array: assert type(oid) is Oid
def __init__(self): logger.info('opening stream..') stream_config = get_config('stream') host = stream_config['STREAM_HOST'] password = stream_config['STREAM_PASS'] stream = stream_config['STREAM_ID'] self.packet_size = stream_config['STREAM_PACKET'] db = Database( host=host, port=6379, password=password, db=0 ) self.stream = db.Stream(stream)
def racks(): logger.info('building rack table..') targets_blob = get_config('targets') snmp_targets = [] rack_id = 0 # getting individual equipment profile, row from config for snmp_target_label, snmp_target in targets_blob.items(): rack_id += 1 equipment = snmp_target['equipment'] row = snmp_target['row'] logger.info('rack ' + row + str(rack_id) + ' initialized') snmp_targets.append(Rack(rack_id, equipment, row)) return snmp_targets
def build_oids(self): oid_array = get_config('oids')[self.equipment_type] for oid_entry in oid_array: type = list(oid_entry.keys())[0] # handling layered dictionary and lists from config oid_entry = oid_entry.popitem()[1] value = oid_entry['value'] divisor = oid_entry['divisor'] # sensor check if self.sensor: value = str(value) + '.' + str(self.sensor) oid_obj = Oid(value, divisor, type) self.oid_obj_array.append(oid_obj)
def test_snmp_enqueue(): engine = snmp.SNMPEngine(build.racks(conf.get_config('targets'))) engine.enqueue_requests() assert engine.requests
def test_snmp_constructor(): engine = snmp.SNMPEngine(build.racks(conf.get_config('targets'))) assert engine
def test_config_targets(): config = conf.get_config('targets') assert type(config) is defaultdict
def wait(start): interval = get_config('chron')['COLL_INTERVAL'] logger.info('waiting {0} seconds'.format(interval-(time()-start))) while time() - start < interval: sleep(.1)