def basic_info_collector(device_list): for device in device_list: try: system_name = collect_snmp_data(device, SNMP_OID['sysName']).split('=')[1].strip() os_description = collect_snmp_data(device, SNMP_OID['sysDescr']).split('\n')[0].split('=')[1].strip() up_time = collect_snmp_data(device, SNMP_OID['sysUpTime']).split('=')[1].strip() # converting TimeTicks to hour up_time = round(int(up_time) / 360000) total_ram = 0 if 'Cisco' in os_description and 'C2900' in os_description: total_ram = Cisco_2900(device).get_total_ram() elif 'Cisco' in os_description and '3700' in os_description: total_ram = Cisco_3700(device).get_total_ram() # print('\n', system_name, '\n', os_description, '\n', up_time, '\n', total_ram) # update or insert these data to database status = execute_procedure('prc_insert_device_info', [device, system_name, os_description, up_time, total_ram]) if status != 'success': print('logging system will be added here') else: print(status) except Exception as e: # when any device is down or the application cant connect with any device # then the application can not run any check against that device print('Error: Unable to connect device {}'.format(device) + str(e))
def insert_alerts_to_db(error_df): for index, row in error_df.iterrows(): execution_status = execute_procedure('prc_insert_dashboard_alert', [ row['device_name'], row['code'], row['error_severity'], row['message'], row['date_time'] ]) if execution_status != 'success': print('prc_insert_dashboard_alert failed ' + execution_status) query = select_notification_status(row['device_name'], row['code']) notification_df = execute_query(query) notification_df.columns = ['notification_id', 'text_message', 'email'] notification_id = int(notification_df['notification_id'][0]) if row['error_severity'] == 'danger': if notification_df['text_message'][0] == 0: for each_number in MONITOR_PHONE: message_body = 'Notification from Network Manager : \nDevice- ' + row['device_name'] + \ '\nDetails: ' + row['message'] send_message(each_number, message_body) execution_status = execute_procedure( 'prc_update_message_status', [notification_id]) if execution_status != 'success': print('prc_update_message_status failed ' + execution_status) if row['error_severity'] == 'danger' or row[ 'error_severity'] == 'warning': if notification_df['email'][0] == 0: for each_email in MONITOR_EMAIL: email_subject = 'Notification from Network Manager regarding ' + row[ 'device_name'] email_body = 'Device- ' + row[ 'device_name'] + '\nDetails: ' + row['message'] send_email(each_email, email_subject, email_body) execution_status = execute_procedure( 'prc_update_email_status', [notification_id]) if execution_status != 'success': print('prc_update_email_status failed ' + execution_status)
def change_manual_connection(html_form_request, connection_id): # retrieving user response from the "resolve_alert.html" form # alert_id, comment and resolved_datetime are the form input tag local_device = html_form_request.get('local_device') local_port = html_form_request.get('local_port') remote_device = html_form_request.get('remote_device') remote_port = html_form_request.get('remote_port') interconnect_1 = html_form_request.get('interconnect_1') interconnect_2 = html_form_request.get('interconnect_2') execution_status = execute_procedure('prc_edit_manual_connection', [ connection_id, local_device, local_port, remote_device, remote_port, interconnect_1, interconnect_2 ]) return execution_status
def resolve_alert_in_db(html_form_request, user_name): # retrieving user response from the "resolve_alert.html" form # alert_id, comment and resolved_datetime are the form input tag alert_id = html_form_request.get('dashboard_id') comment = html_form_request.get('comment') resolved_date = html_form_request.get('resolved_date') resolved_date = datetime.datetime.strptime(resolved_date, "%Y-%m-%d").strftime("%d-%m-%Y") resolved_hour = html_form_request.get('resolved_hour') resolved_minute = html_form_request.get('resolved_minute') resolved_datetime = resolved_date + ' ' + resolved_hour + ':' + resolved_minute # datetime format execution_status = execute_procedure( 'prc_resolve_alert', [alert_id, comment, resolved_datetime, user_name]) return execution_status
def insert_single_connection(html_from_request): # this request object was obtained from the connection page > Insert # single connection form > submit local_device = html_from_request.get('local_device').lower() local_port = html_from_request.get('local_port').lower() remote_device = html_from_request.get('remote_device').lower() remote_port = html_from_request.get('remote_port').lower() interconnect_1 = html_from_request.get('interconnect_1').lower() interconnect_2 = html_from_request.get('interconnect_2').lower() execution_status = execute_procedure('prc_insert_manual_connection', [ local_device, local_port, remote_device, remote_port, interconnect_1, interconnect_2 ]) if execution_status != 'success': execution_status = execution_status.split(':') execution_status = execution_status[1].split('-')[0] execution_status = 'Connection Insertion Error : ' + execution_status.strip( ) return execution_status
def multiple_connection_insert(): connections_df = pd.read_csv('./required_files\connections.csv', sep=',') success_list = [] error_list = [] for index, row in connections_df.iterrows(): prc_params = [ row['Local Device'], row['Local Port'], row['Remote Device'], row['Remote Port'], row['Interconnect 1'], row['Interconnect 2'] ] execution_status = execute_procedure('prc_insert_manual_connection', prc_params) if execution_status == 'success': success_list.append(prc_params) else: error_list.append(prc_params) column_names = [ 'Local Device', 'Local Port', 'Remote Device', 'Remote Port', 'Interconnect 1', 'Interconnect 2' ] success_df = pd.DataFrame(success_list, columns=column_names) error_df = pd.DataFrame(error_list, columns=column_names) success_table = '' error_table = '' if not success_df.empty: success_table = success_df.to_html(classes=['table table-bordered'], header=True, index=False, na_rep='') if not error_df.empty: error_table = error_df.to_html(classes=['table table-bordered'], header=True, index=False, na_rep='') return success_table, error_table
def details_info_collector(device_list): for device in device_list: os_description = collect_snmp_data(device, SNMP_OID['sysDescr']) if os_description == '': print('could not establish connection') break connection_df = pd.DataFrame() ram_df = pd.DataFrame() cpu_df = pd.DataFrame() unused_port_df = pd.DataFrame() error_df = pd.DataFrame() if 'Cisco' in os_description and 'C2900' in os_description: connection_df, ram_df, cpu_df, unused_port_df, error_df = Cisco_2900( device).formatted_output() elif 'Cisco' in os_description and '3700' in os_description: connection_df, ram_df, cpu_df, unused_port_df, error_df = Cisco_3700( device).formatted_output() # update or insert these data to database if not connection_df.empty: for index, row in connection_df.iterrows(): insert_status = execute_procedure( 'prc_insert_lldp_connection', [ row['local_device'], row['local_port'], row['remote_device'], row['remote_port'], row['date_time'] ]) if insert_status != 'success': print('failed ' + insert_status) if not ram_df.empty: mem_status = execute_procedure('prc_insert_memory_usage', [ ram_df['device_name'][0], int(ram_df['currently_used'][0]), int(cpu_df['cpu_used'][0]), cpu_df['date_time'][0] ]) if mem_status != 'success': print('failed ' + mem_status) if not unused_port_df.empty: for index, row in unused_port_df.iterrows(): unused_port_status = execute_procedure( 'prc_insert_unused_port', [row['device_name'], row['port_name'], row['date_time']]) if unused_port_status != 'success': print('failed ' + unused_port_status) if not error_df.empty: for index, row in error_df.iterrows(): port_error_status = execute_procedure('prc_insert_port_error', [ row['device_name'], row['port'], int(row['input']), int(row['crc']), int(row['frame']), int(row['overrun']), int(row['ignored']), row['date_time'], ]) if port_error_status != 'success': print('failed ' + port_error_status) else: print('data extractor class is not present for {}'.format(device))
def delete_manual_connection(connection_id): execution_status = execute_procedure('prc_delete_manual_connection', [connection_id]) return execution_status