Пример #1
0
def reg_reboot():
    data_list = db.fetchdata()
    for row in data_list:
        # row[2] - switch type, row[4] - uptime
        if row[4]:
            if row[2] in (5,4,7) and row[4] > UPTIME:    # looking for 'SNR' devices
                try:
                    ssh_reboot.ssh_reboot_snr(row[0], row[3], DEBUG=DEBUG) # trying to reboot with ssh
                except Exception as e:
                    if DEBUG:
                        print("{} reported error: {}".format(row[0], e))
                    # if exception, trying ssh_reboot with new password
                    try:
                        ssh_reboot.ssh_reboot_snr(row[0], row[3],
                                              password=secure.ssh_password,
                                              DEBUG=DEBUG) 
                    except Exception as e:
                        if DEBUG:
                            print("{} reported another error: {}".format(row[0], e))
            elif row[2] == 2 and row[4] > UPTIME:      # looking for '3com'
                reboot_3com(row[0], row[3])
            elif row[2] == 1 and row[4] > UPTIME:      # looking for 'Allied'
                reboot_telesyn(row[0], row[3])
            elif row[2] == 3 and row[4] > UPTIME:      # looking for 'Cisco'
                reboot_cisco(row[0], row[3])
            elif row[2] == 8 and row[4] > UPTIME:
                ssh_reboot.ssh_reboot_dlink(row[0], row[3],
                                            password=secure.ssh_password)
Пример #2
0
def get_switches():
    '''Function for parsing switches from the database.
        None -> List of Tuples (ip, uplink, switch_type)

       switch_type is for special cisco port numbering, to
       filter those switches
    '''

    raw_switch_list = db.fetchdata()
    switch_list = []
    for switch in raw_switch_list:
        if switch[1]:
            switch_list.append((switch[0],switch[7],switch[2]))
    return switch_list
Пример #3
0
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()
Пример #4
0
# helper function for queue, limiting threads count to MAX_THREADS
def worker():
    all_done = 0
    while not all_done:
        try:
            item = q.get(0)
            check_uptime(item[6], item[0],)
            # q.task_done()
        except queue.Empty:
            all_done = 1


if __name__=='__main__':
    q = queue.Queue()
    data_list = db.fetchdata()
    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):