def add_uplink_ports(): '''Use only once, to automaticaly add all uplinks, where default gateway mac-address is listed. ''' gateway_mac = '00:25:90:69:ED:EA' switches_query(gateway_mac) db.setdata(data_dic=IP_PORT_DICT, data='uplink')
def main(): data_list = db.fetchdata() threads = [] for item in data_list: # checking if tests are enabled for device if item[1]: t = Thread(target=ping_st, args=(item[0], item[5], item[6],)) threads.append(t) # if disable, setting None else: PING_DIC[item[6]] = {} PING_DIC[item[6]]['ping'] = None PING_DIC[item[6]]['old_ping'] = None for thread in threads: thread.start() for thread in threads: # waiting all threads to finish thread.join() lock.acquire() db.setdata(PING_DIC, 'ping') lock.release() # Create event record in dic if switch is not responding for id in PING_DIC: if PING_DIC[id]['old_ping'] and not PING_DIC[id]['ping']: EVENT_DIC[id] = {} EVENT_DIC[id]['ev_type'] = "err" EVENT_DIC[id]['ev_event'] = "Switch is not responding" EVENT_DIC[id]['ev_comment'] = "" elif not PING_DIC[id]['old_ping'] and PING_DIC[id]['ping']: EVENT_DIC[id] = {} EVENT_DIC[id]['ev_type'] = "info" EVENT_DIC[id]['ev_event'] = "Switch is up and running" EVENT_DIC[id]['ev_comment'] = "" # If at least one record, updating database if len(EVENT_DIC) > 0: lock.acquire() db.setdata(EVENT_DIC, data='event') lock.release()
threads = [] for item in data_list: # cheking if tests are enabled for device if item[1]: ''' t = Thread(target=check_uptime, args=(item[6], item[0],)) threads.append(t) ''' q.put(item) else: UPTIME_DIC[item[6]] = {} UPTIME_DIC[item[6]]['sw_uptime'] = None for i in range(MAX_THREADS): t = Thread(target=worker) threads.append(t) t.start() ''' for thread in threads: # starting all threads thread.start() ''' for thread in threads: # wait for all threads thread.join() # to finish # writing to database switch_ping.lock.acquire() db.setdata(UPTIME_DIC, 'uptime') switch_ping.lock.release()