def main(): aci_cookie = get_aci_token(credentials["username"], credentials["password"], credentials["apic_ip"]) get_audit_details_result = get_audit_details(aci_cookie, credentials["apic_ip"]) # print(get_audit_details_result) get_data = get_processed_data(get_audit_details_result) # print(get_data) main_operations_list = [ 'Exit', 'Print Faults details on screen', 'Save data to CSV' ] while True: for index, main_items in enumerate(main_operations_list, 0): print(f"{index}: {main_items}") main_operation = input( '\nChoose number to select type of operation : ') if main_operation == '0': break elif main_operation == '1': sub_operations1_list = [ 'Exit', 'All results', 'Filter by user', 'Filter by time', 'Filter by Action Performed', 'Filter by description', 'Filter by affected object', 'Filter by ID', 'Filter by DN', ] while True: for index, sub_menu_items in enumerate(sub_operations1_list, 0): print(f"{index}: {sub_menu_items}") subops1 = input( '\nChoose number to select type of operation : ') if subops1 == '0': break elif subops1 == '1': print_results(get_data) elif subops1 == '2': filter_value1 = input("\nEnter usnername: ") filter_type1 = 'user' get_filtered_data_func(filter_value1, filter_type1, get_data) elif subops1 == '3': filter_value1 = input("\nCreation time (HH:MM:SS): ") filter_type1 = 'creation_time' get_filtered_data_func(filter_value1, filter_type1, get_data) elif subops1 == '4': filter_value1 = input( "\nEnter string to search in Action Performed: ") filter_type1 = 'actionPerformed' get_filtered_data_func(filter_value1, filter_type1, get_data) elif subops1 == '5': filter_value1 = input( "\nEnter string to search in description: ") filter_type1 = 'description' get_filtered_data_func(filter_value1, filter_type1, get_data) elif subops1 == '6': filter_value1 = input( "\nEnter string to search in affected object: ") filter_type1 = 'affectedObject' get_filtered_data_func(filter_value1, filter_type1, get_data) elif subops1 == '7': filter_value1 = input("\nEnter id: ") filter_type1 = 'id' get_filtered_data_func(filter_value1, filter_type1, get_data) elif subops1 == '8': filter_value1 = input("\nEnter string to search in DN: ") filter_type1 = 'dn' get_filtered_data_func(filter_value1, filter_type1, get_data) elif main_operation == '2': save_to_csv(get_data)
def main(): aci_cookie = get_aci_token(credentials["username"], credentials["password"], credentials["apic_ip"]) get_crc_details_result = get_crc_details(aci_cookie, credentials["apic_ip"]) # print(get_crc_details_result) get_data = get_processed_data(get_crc_details_result) # print(get_data) main_operations_list = [ 'Exit', 'Print crcs details on screen', 'Live CRC erros', 'Save data to CSV' ] while True: for index, main_items in enumerate(main_operations_list, 0): print(f"{index}: {main_items}") main_operation = input( '\nChoose number to select type of operation : ') if main_operation == '0': break elif main_operation == '1': sub_operations1_list = [ 'Exit', 'All results', 'Filter by node', 'Filter by Interface', ] while True: for index, sub_menu_items in enumerate(sub_operations1_list, 0): print(f"{index}: {sub_menu_items}") subops1 = input( '\nChoose number to select type of operation : ') if subops1 == '0': break elif subops1 == '1': print_results(get_data) elif subops1 == '2': filter_value1 = input("\nEnter Node Number: ") filter_type1 = 'leaf' get_filtered_data_func(filter_value1, filter_type1, get_data) elif subops1 == '3': filter_value1 = input("\nEnter Interface Number: ") filter_type1 = 'interface' get_filtered_data_func(filter_value1, filter_type1, get_data) elif main_operation == '2': while True: try: aci_cookie1 = get_aci_token(credentials["username"], credentials["password"], credentials["apic_ip"]) get_crc_details_result = get_crc_details( aci_cookie, credentials["apic_ip"]) # print(get_crc_details_result) get_data = get_processed_data(get_crc_details_result) print( f"{datetime.now()} ===> Checking live CRC errors every 30 seconds" ) live_results = list() for each in get_data: if each['fcsCum'] != '0': live_results.append(each) print_results(live_results) time.sleep(30) # check every after 60 seconds except KeyboardInterrupt: print("closed live monitoring gracefully") break elif main_operation == '3': save_to_csv(get_data)
def main(req_date): if not req_date: exit() aci_cookie = get_aci_token( credentials["username"], credentials["password"], credentials["apic_ip"]) get_events_details_result = get_events_details(aci_cookie, credentials["apic_ip"],req_date) # pprint(get_events_details_result) get_data = get_processed_data(get_events_details_result) main_operations_list = ['Exit', 'Print events details on screen', 'Save data to CSV'] while True: for index,main_items in enumerate(main_operations_list,0): print(f"{index}: {main_items}") main_operation = input('\nChoose number to select type of operation : ') if main_operation == '0': break elif main_operation == '1': sub_operations1_list = ['Exit', 'All results', 'Filter by severity', 'Filter by time', 'Filter by cause', 'Filter by description', 'Filter by affected object', 'Filter by events code', ] while True: for index,sub_menu_items in enumerate(sub_operations1_list,0): print(f"{index}: {sub_menu_items}") subops1 = input('\nChoose number to select type of operation : ') if subops1 == '0': break elif subops1 == '1': print_results(get_data) elif subops1 == '2': filter_value1 = input("\nEnter Severity(critical,major,minor,warning): ") filter_type1='severity' get_filtered_data_func(filter_value1,filter_type1,get_data) elif subops1 == '3': filter_value1 = input("\nCreation time (HH:MM:SS): ") filter_type1='creation_time' get_filtered_data_func(filter_value1,filter_type1,get_data) elif subops1 == '4': filter_value1 = input("\nEnter string to search in cause: ") filter_type1='cause' get_filtered_data_func(filter_value1,filter_type1,get_data) elif subops1 == '5': filter_value1 = input("\nEnter string to search in description: ") filter_type1='description' get_filtered_data_func(filter_value1,filter_type1,get_data) elif subops1 == '6': filter_value1 = input("\nEnter string to search in affected object: ") filter_type1='affected' get_filtered_data_func(filter_value1,filter_type1,get_data) elif subops1 == '7': filter_value1 = input("\nEnter events code: ") filter_type1='events_code' get_filtered_data_func(filter_value1,filter_type1,get_data) elif main_operation == '2': save_to_csv(get_data)
def main(): aci_cookie = get_aci_token( credentials["username"], credentials["password"], credentials["apic_ip"]) # pprint(get_data) main_operations_list = ['Exit', 'Print Rogue EP details on screen', 'Clear Rogue EP from Leafs', 'Rogue EP Global Configs', 'Automatically detect and clear Rogue EP', 'Save data to CSV'] while True: for index,main_items in enumerate(main_operations_list,0): print(f"{index}: {main_items}") main_operation = input('\nChoose number to select type of operation : ') if main_operation == '0': break elif main_operation == '1': get_rogue_details_result = get_rogue_details(aci_cookie, credentials["apic_ip"]) get_data = get_processed_data(get_rogue_details_result) sub_operations1_list = ['Exit', 'All results', 'Filter by mac address', 'Filter by creation date & time', ] while True: for index,sub_menu_items in enumerate(sub_operations1_list,0): print(f"{index}: {sub_menu_items}") subops1 = input('\nChoose number to select type of operation : ') if subops1 == '0': break elif subops1 == '1': print_results(get_data) elif subops1 == '2': filter_value = input("Enter MAC Address: ").upper() filter_type='mac' get_filtered_data_func(filter_value,filter_type,get_data) elif subops1 == '3': filter_value1 = input("\nCreation date (YYYY-MM-DD): ") filter_type1='creation_date' filter_value2 = input("\nCreation time (HH:MM:SS): ") filter_type2='creation_time' get_filtered_data_func(filter_value1,filter_type1,get_data,filter_value2,filter_type2) elif main_operation == '2': nodeId = input("Enter Node ID to clear Rogue EP or 'q' quit: ") if nodeId: if nodeId == 'q' or int(nodeId) < 100 : break response = clearRogueEp(aci_cookie, credentials["apic_ip"],nodeId) print(f"\n{response}\n") else: break elif main_operation == '3': sub_operations1_list = ['Exit', 'Display current configs', 'Enable Rogue EP configs globally', 'Disable Rogue EP configs globally', ] while True: for index,sub_menu_items in enumerate(sub_operations1_list,0): print(f"{index}: {sub_menu_items}") subops1 = input('\nChoose number to select type of operation : ') if subops1 == '0': break elif subops1 == '1': config_response = get_rogue_configs(aci_cookie, credentials["apic_ip"]) print(f"\nGlobal EP cofigures are {config_response['imdata'][0]['epControlP']['attributes']['adminSt']} now\n") elif subops1 == '2': configureRogueEpSetting(aci_cookie, credentials["apic_ip"],"enabled") elif subops1 == '3': configureRogueEpSetting(aci_cookie, credentials["apic_ip"],"disabled") elif main_operation == '4': get_rogue_details_result = get_rogue_details(aci_cookie, credentials["apic_ip"]) get_data = get_processed_data(get_rogue_details_result) sub_operations1_list = ['Exit', 'Clear REPs from all affected nodes', 'Monitor & clear specific REP from leafs after 10 seconds interval or ctrl-c to exit', 'Clear manually specific REP from all affected nodes', ] while True: for index,sub_menu_items in enumerate(sub_operations1_list,0): print(f"{index}: {sub_menu_items}") subops1 = input('\nChoose number to select type of operation : ') if subops1 == '0': break elif subops1 == '1': for each in get_data: print(each['node_id'] , each['mac'] ) response = clearRogueEp(aci_cookie, credentials["apic_ip"],each['node_id']) print(f"\n{response}\n") print("\n") elif subops1 == '2': while True: try: aci_cookie1 = get_aci_token(credentials["username"], credentials["password"], credentials["apic_ip"]) get_rogue_details_result = get_rogue_details(aci_cookie1, credentials["apic_ip"]) get_data = get_processed_data(get_rogue_details_result) print(f"{datetime.now()} ===> Checking if FW MAC {FW_MAC1} and {FW_MAC2} addresss are REP") for each in get_data: if (FW_MAC1 in each['mac'] or FW_MAC2 in each['mac']): response = f"{datetime.now()} {each['node_id']} , {each['mac']} detected\n" print(response) response = clearRogueEp(aci_cookie1, credentials["apic_ip"],each['node_id']) print(f"\n{response}\n") result = f"{datetime.now()} Cleared REP {each['mac']} \n" print(result) with open('rep_logs.txt','a') as file: file.write(str(response)) file.write(result) time.sleep(60) # check every after 60 seconds except KeyboardInterrupt: print("closed live monitoring gracefully") break elif subops1 == '3': for each in get_data: if (FW_MAC1 in each['mac'] or FW_MAC2 in each['mac']): print(each['node_id'] , each['mac'] ) response = clearRogueEp(aci_cookie, credentials["apic_ip"],each['node_id']) print(f"\n{response}\n") print("\n") elif main_operation == '5': get_rogue_details_result = get_rogue_details(aci_cookie, credentials["apic_ip"]) get_data = get_processed_data(get_rogue_details_result) save_to_csv(get_data)
def main(): aci_cookie = get_aci_token( credentials["username"], credentials["password"], credentials["apic_ip"]) get_ep_details_result = get_ep_details(aci_cookie, credentials["apic_ip"]) get_data = get_processed_data(get_ep_details_result) main_operations_list = ['Exit', 'Print Endpoint details on screen', 'Save data to CSV'] while True: for index,main_items in enumerate(main_operations_list,0): print(f"{index}: {main_items}") main_operation = input('\nChoose number to select type of operation : ') if main_operation == '0': break elif main_operation == '1': sub_operations1_list = ['Exit', 'All results', 'Filter by Node ID', 'Filter by EPG', 'Filter by VLAN ID', 'Filter by Interface Name', 'Filter by Tenant Name', 'Filter by MAC Address', ] while True: for index,sub_menu_items in enumerate(sub_operations1_list,0): print(f"{index}: {sub_menu_items}") subops1 = input('\nChoose number to select type of operation : ') if subops1 == '0': break elif subops1 == '1': print_details_onscreen(get_data) elif subops1 =='2': filter_value = input("Enter Node ID: ") filter_type='switch' if len(filter_value) != 3: print('Wrong Node ID! try again') continue get_filtered_data_func(filter_value,filter_type,get_data) elif subops1 =='3': filter_value = input("Enter EPG: ") filter_type='epg' get_filtered_data_func(filter_value,filter_type,get_data) elif subops1 =='4': filter_value = input("Enter VLAN ID: ") filter_type='vlan' get_filtered_data_func(filter_value,filter_type,get_data) elif subops1 =='5': filter_value = input("Enter Interface ID: ") filter_type='interface' get_filtered_data_func(filter_value,filter_type,get_data) elif subops1 =='6': filter_value = input("Enter Tenant Name: ") filter_type='tenant' get_filtered_data_func(filter_value,filter_type,get_data) elif subops1 =='7': filter_value = input("Enter MAC Address: ").upper() filter_type='mac_address' get_filtered_data_func(filter_value,filter_type,get_data) elif main_operation == '2': save_to_csv(get_data)
def main(): aci_cookie = get_aci_token(credentials["username"], credentials["password"], credentials["apic_ip"]) main_operations_list = ['Exit', 'Tenant Operations', 'Save data to CSV'] while True: for index, main_items in enumerate(main_operations_list, 0): print(f"{index}: {main_items}") main_operation = input( '\nChoose number to select type of operation : ') if main_operation == '0': break elif main_operation == '1': sub_operations1_list = [ 'Exit', 'Display tenants', 'Create tenants', 'Remove tenants', ] while True: for index, sub_menu_items in enumerate(sub_operations1_list, 0): print(f"{index}: {sub_menu_items}") subops1 = input( '\nChoose number to select type of operation : ') if subops1 == '0': break elif subops1 == '1': gPd = load_tenants(aci_cookie, credentials["apic_ip"]) print_details_onscreen(gPd) elif subops1 == '2': tName = input("Tenant name : ") tDescr = input("Enter Tenant Description : ") response = create_tenant(aci_cookie, credentials["apic_ip"], tName, tDescr) if response: print( "\n !!! Tenant created successfully !!!!!\n" ) elif subops1 == '3': tName = input("Tenant name : ") response = delete_tenant(aci_cookie, credentials["apic_ip"], tName) try: if response['imdata'][0]['error']['attributes'][ 'text']: print( f"\n{response['imdata'][0]['error']['attributes']['text']}\n" ) except: print("\n Deleted\n") elif main_operation == '2': get_data1 = load_tenants(aci_cookie, credentials["apic_ip"]) save_to_csv(get_data1)
def main(): aci_cookie = get_aci_token(credentials["username"], credentials["password"], credentials["apic_ip"]) # pprint(get_data) main_operations_list = [ 'Exit', 'Print Rogue EP details on screen', 'Clear Rogue EP from Leafs', 'Rogue EP Global Configs', 'Save data to CSV' ] while True: for index, main_items in enumerate(main_operations_list, 0): print(f"{index}: {main_items}") main_operation = input( '\nChoose number to select type of operation : ') if main_operation == '0': break elif main_operation == '1': get_rogue_details_result = get_rogue_details( aci_cookie, credentials["apic_ip"]) get_data = get_processed_data(get_rogue_details_result) sub_operations1_list = [ 'Exit', 'All results', 'Filter by mac address', 'Filter by creation date & time', ] while True: for index, sub_menu_items in enumerate(sub_operations1_list, 0): print(f"{index}: {sub_menu_items}") subops1 = input( '\nChoose number to select type of operation : ') if subops1 == '0': break elif subops1 == '1': print_results(get_data) elif subops1 == '2': filter_value = input("Enter MAC Address: ").upper() filter_type = 'mac' get_filtered_data_func(filter_value, filter_type, get_data) elif subops1 == '3': filter_value1 = input("\nCreation date (YYYY-MM-DD): ") filter_type1 = 'creation_date' filter_value2 = input("\nCreation time (HH:MM:SS): ") filter_type2 = 'creation_time' get_filtered_data_func(filter_value1, filter_type1, get_data, filter_value2, filter_type2) elif main_operation == '2': nodeId = input("Enter Node ID to clear Rogue EP : ") response = clearRogueEp(aci_cookie, credentials["apic_ip"], nodeId) print(f"\n{response}\n") elif main_operation == '3': sub_operations1_list = [ 'Exit', 'Display current configs', 'Enable Rogue EP configs globally', 'Disable Rogue EP configs globally', ] while True: for index, sub_menu_items in enumerate(sub_operations1_list, 0): print(f"{index}: {sub_menu_items}") subops1 = input( '\nChoose number to select type of operation : ') if subops1 == '0': break elif subops1 == '1': config_response = get_rogue_configs( aci_cookie, credentials["apic_ip"]) print( f"\nGlobal EP cofigures are {config_response['imdata'][0]['epControlP']['attributes']['adminSt']} now\n" ) elif subops1 == '2': configureRogueEpSetting(aci_cookie, credentials["apic_ip"], "enabled") elif subops1 == '3': configureRogueEpSetting(aci_cookie, credentials["apic_ip"], "disabled") elif main_operation == '4': save_to_csv(get_data)
def main(): aci_cookie = get_aci_token(credentials["username"], credentials["password"], credentials["apic_ip"]) get_sfp_details_result = get_ep_details(aci_cookie, credentials["apic_ip"]) get_data = get_processed_data(get_sfp_details_result) main_operations_list = [ 'Exit', 'Print SFP details on screen', 'Save data to CSV' ] while True: for index, main_items in enumerate(main_operations_list, 0): print(f"{index}: {main_items}") main_operation = input( '\nChoose number to select type of operation : ') if main_operation == '0': break elif main_operation == '1': sub_operations1_list = [ 'Exit', 'All results', 'Filter by switch', 'Filter by Type', 'Filter by SFP name', 'Filter by SFP part number', 'Filter by SFP serial', 'Filter by SFP state', 'Filter by switch interface', ] while True: for index, sub_menu_items in enumerate(sub_operations1_list, 0): print(f"{index}: {sub_menu_items}") subops1 = input( '\nChoose number to select type of operation : ') if subops1 == '0': break elif subops1 == '1': print_details_onscreen(get_data) elif subops1 == '2': filter_value = input("Enter Node ID: ") filter_type = 'switch' if len(filter_value) != 3: print('Wrong Node ID! try again') continue get_filtered_data_func(filter_value, filter_type, get_data) elif subops1 == '3': filter_value = input("Enter Type: ") filter_type = 'type' get_filtered_data_func(filter_value, filter_type, get_data) elif subops1 == '4': filter_value = input("Enter SFP Name: ") filter_type = 'sfpname' get_filtered_data_func(filter_value, filter_type, get_data) elif subops1 == '5': filter_value = input("Enter SFP Part Number: ") filter_type = 'partnumber' get_filtered_data_func(filter_value, filter_type, get_data) elif subops1 == '6': filter_value = input("Enter SFP Serial Number: ") filter_type = 'serialnumber' get_filtered_data_func(filter_value, filter_type, get_data) elif subops1 == '7': filter_value = input("Enter SFP state: ") filter_type = 'state' get_filtered_data_func(filter_value, filter_type, get_data) elif subops1 == '8': filter_value = input("Enter SFP interface: ").upper() filter_type = 'interface' get_filtered_data_func(filter_value, filter_type, get_data) elif main_operation == '2': save_to_csv(get_data)
def main(): aci_cookie = get_aci_token( credentials["username"], credentials["password"], credentials["apic_ip"]) get_fault_details_result = get_fault_details(aci_cookie, credentials["apic_ip"]) get_data = get_processed_data(get_fault_details_result) # pprint(get_data) main_operations_list = ['Exit', 'Print Faults details on screen', 'Recent faults by creation date', 'Recent faults by last transaction date', 'Save data to CSV'] while True: for index,main_items in enumerate(main_operations_list,0): print(f"{index}: {main_items}") main_operation = input('\nChoose number to select type of operation : ') if main_operation == '0': break elif main_operation == '1': sub_operations1_list = ['Exit', 'All results', 'Filter by severity', 'Filter by creation date & time', 'Filter by last transition date & time', 'Filter by description', 'Filter by affected object', 'Filter by fault code', ] while True: for index,sub_menu_items in enumerate(sub_operations1_list,0): print(f"{index}: {sub_menu_items}") subops1 = input('\nChoose number to select type of operation : ') if subops1 == '0': break elif subops1 == '1': print_results(get_data) elif subops1 == '2': filter_value1 = input("\nEnter Severity(critical,major,minor,warning): ") filter_type1='severity' get_filtered_data_func(filter_value1,filter_type1,get_data) elif subops1 == '3': filter_value1 = input("\nCreation date (YYYY-MM-DD): ") filter_type1='creation_date' filter_value2 = input("\nCreation time (HH:MM:SS): ") filter_type2='creation_time' get_filtered_data_func(filter_value1,filter_type1,get_data,filter_value2,filter_type2) elif subops1 == '4': filter_value1 = input("\nLast transition date (YYYY-MM-DD): ") filter_type1='last_transition_date' filter_value2 = input("\nLast transition time (HH:MM:SS): ") filter_type2='last_transition_time' get_filtered_data_func(filter_value1,filter_type1,get_data,filter_value2,filter_type2) elif subops1 == '5': filter_value1 = input("\nEnter string to search in description: ") filter_type1='description' get_filtered_data_func(filter_value1,filter_type1,get_data) elif subops1 == '6': filter_value1 = input("\nEnter string to search in affected object: ") filter_type1='DN' get_filtered_data_func(filter_value1,filter_type1,get_data) elif subops1 == '7': filter_value1 = input("\nEnter fault code: ") filter_type1='fault_code' get_filtered_data_func(filter_value1,filter_type1,get_data) elif main_operation == '2': filter_value1 = TODAYS_DATE filter_type1='creation_date' get_filtered_data_func(filter_value1,filter_type1,get_data) elif main_operation == '3': filter_value1 = TODAYS_DATE filter_type1='last_transition_date' get_filtered_data_func(filter_value1,filter_type1,get_data) elif main_operation == '4': save_to_csv(get_data)