From 11cb53582cbac3dfa95e23f3f96cd01e841aa895 Mon Sep 17 00:00:00 2001 From: alejandro-campos Date: Mon, 2 Sep 2019 17:01:41 +0200 Subject: [PATCH] backup changes --- pandora_console/godmode/menu.php | 3 + pandora_console/godmode/setup/setup.php | 11 + .../godmode/setup/setup_integria.php | 367 ++++++++++++++--- pandora_console/images/integria_logo.png | Bin 0 -> 4614 bytes pandora_console/include/functions.php | 83 +++- pandora_console/include/functions_config.php | 28 ++ pandora_console/include/functions_events.php | 246 ++++++++++++ .../configure_integriaims_incident.php | 377 ++++-------------- pandora_server/util/integria_rticket.pl | 6 + 9 files changed, 754 insertions(+), 367 deletions(-) create mode 100644 pandora_console/images/integria_logo.png diff --git a/pandora_console/godmode/menu.php b/pandora_console/godmode/menu.php index 000a105257..1ab91f25f3 100644 --- a/pandora_console/godmode/menu.php +++ b/pandora_console/godmode/menu.php @@ -295,6 +295,9 @@ if (check_acl($config['id_user'], 0, 'PM')) { $sub2['godmode/setup/setup&section=ehorus']['text'] = __('eHorus'); $sub2['godmode/setup/setup&section=ehorus']['refr'] = 0; + $sub2['godmode/setup/setup&section=integria']['text'] = __('Integria IMS'); + $sub2['godmode/setup/setup&section=ehorus']['refr'] = 0; + $sub2['godmode/setup/setup&section=notifications']['text'] = __('Notifications'); $sub2['godmode/setup/setup&section=notifications']['refr'] = 0; diff --git a/pandora_console/godmode/setup/setup.php b/pandora_console/godmode/setup/setup.php index 595cfb1d14..bf34da4a61 100644 --- a/pandora_console/godmode/setup/setup.php +++ b/pandora_console/godmode/setup/setup.php @@ -117,6 +117,11 @@ if (check_acl($config['id_user'], 0, 'AW')) { } } +$buttons['integria'] = [ + 'active' => false, + 'text' => ''.html_print_image('images/ehorus/ehorus.png', true, ['title' => __('Integria IMS')]).'', +]; + $buttons['ehorus'] = [ 'active' => false, 'text' => ''.html_print_image('images/ehorus/ehorus.png', true, ['title' => __('eHorus')]).'', @@ -167,6 +172,12 @@ switch ($section) { $help_header = 'setup_ehorus_tab'; break; + case 'integria': + $buttons['integria']['active'] = true; + $subpage = ' » '.__('Integria IMS'); + $help_header = 'setup_integria_tab'; + break; + case 'notifications': $buttons['notifications']['active'] = true; $subpage = ' » '.__('Notifications'); diff --git a/pandora_console/godmode/setup/setup_integria.php b/pandora_console/godmode/setup/setup_integria.php index 29a1b199f7..a3b25b7e07 100644 --- a/pandora_console/godmode/setup/setup_integria.php +++ b/pandora_console/godmode/setup/setup_integria.php @@ -28,25 +28,136 @@ if (! check_acl($config['id_user'], 0, 'PM') && ! is_user_admin($config['id_user return; } -hd(get_parameter('update_config', 0)); +if (is_ajax()) { + $integria_user = get_parameter('integria_user', ''); + $integria_pass = get_parameter('integria_pass', ''); + $integria_api_hostname = get_parameter('api_hostname', ''); + $integria_api_pass = get_parameter('api_pass', ''); + + $login_result = integria_api_call($integria_api_hostname, $integria_user, $integria_pass, $integria_api_pass, 'get_login', []); + + if ($login_result != false) { + echo json_encode(['login' => 1]); + } else { + echo json_encode(['login' => 0]); + } + + return; +} + +$has_connection = integria_api_call($config['integria_hostname'], $config['integria_user'], $config['integria_pass'], $config['integria_api_pass'], 'get_login', []); + +if ($has_connection === false) { + ui_print_error_message(__('Integria IMS API is not reachable')); +} if (get_parameter('update_config', 0) == 1) { // Try to retrieve event response 'Create incident in IntegriaIMS from event' to check if it exists. - $row = db_get_row_filter('tevent_response', ['name' => 'Create incident in IntegriaIMS from event']); + $event_response_exists = db_get_row_filter('tevent_response', ['name' => io_safe_input('Create incident in IntegriaIMS from event')]); + + // Try to retrieve command 'Integia IMS Ticket' to check if it exists. + $command_exists = db_get_row_filter('talert_commands', ['name' => io_safe_input('Integria IMS Ticket')]); if ($config['integria_enabled'] == 1) { - if ($row === false) { + if ($event_response_exists === false) { // Create 'Create incident in IntegriaIMS from event' event response only when user enables IntegriaIMS integration and it does not exist in database. - db_process_sql_insert('tevent_response', ['name' => 'Create incident in IntegriaIMS from event', 'description' => 'Create an incident in IntegriaIMS from an event', 'target' => 'index.php?sec=incident&sec2=operation/incidents/configure_integriaims_incident&from_event=_event_id_', 'type' => 'url', 'id_group' => '0', 'modal_width' => '0', 'modal_height' => '0', 'new_window' => '1', 'params' => '', 'server_to_exec' => '0']); + db_process_sql_insert('tevent_response', ['name' => io_safe_input('Create incident in IntegriaIMS from event'), 'description' => io_safe_input('Create an incident in Integria IMS from an event'), 'target' => io_safe_input('index.php?sec=incident&sec2=operation/incidents/configure_integriaims_incident&from_event=_event_id_'), 'type' => 'url', 'id_group' => '0', 'modal_width' => '0', 'modal_height' => '0', 'new_window' => '1', 'params' => '', 'server_to_exec' => '0']); + } + + if ($command_exists === false) { + // Create 'Integria IMS Ticket' command only when user enables IntegriaIMS integration and it does not exist in database. + $id_command_inserted = db_process_sql_insert('talert_commands', ['name' => io_safe_input('Integria IMS Ticket'), 'command' => io_safe_input('perl /usr/share/pandora_server/util/integria_rticket.pl -p '.$config['integria_hostname'].'/integria/include/api.php -u '.$config['integria_api_pass'].','.$config['integria_user'].','.$config['integria_pass'].' -create_ticket -name "_field1_" -desc "_field2_" -group _field3_ -priority _field4_ -owner _field5_ -type _field6_'), 'description' => io_safe_input('Create an incident in Integria IMS'), 'fields_descriptions' => '["'.io_safe_input('Ticket title').'","'.io_safe_input('Ticket description').'","'.io_safe_input('Ticket group ID').'","'.io_safe_input('Ticket priority').'","'.io_safe_input('Ticket owner').'","'.io_safe_input('Ticket type').'"]', 'fields_values' => '["'.io_safe_input($config['incident_title']).'", "'.io_safe_input($config['incident_content']).'", "'.io_safe_input($config['default_group']).'", "'.io_safe_input($config['default_criticity']).'", "'.io_safe_input($config['default_owner']).'", "'.io_safe_input($config['incident_type']).'"]', 'fields_hidden' => '["","","","","","","","","",""]']); + + // Create 'Create Integria IMS Ticket' action only when user enables IntegriaIMS integration and command exists in database. + $action_values = [ + 'field1' => io_safe_input($config['incident_title']), + 'field1_recovery' => io_safe_input($config['incident_title']), + 'field2' => io_safe_input($config['incident_content']), + 'field2_recovery' => io_safe_input($config['incident_content']), + 'field3' => io_safe_input($config['default_group']), + 'field3_recovery' => io_safe_input($config['default_group']), + 'field4' => io_safe_input($config['default_criticity']), + 'field4_recovery' => io_safe_input($config['default_criticity']), + 'field5' => io_safe_input($config['default_owner']), + 'field5_recovery' => io_safe_input($config['default_owner']), + 'id_group' => 0, + 'action_threshold' => 0, + ]; + + alerts_create_alert_action(io_safe_input('Create Integria IMS ticket'), $id_command_inserted, $action_values); + } else { + // Update 'Integria IMS Ticket' command setup when setup data is updated, user enables IntegriaIMS integration and it does exist in database. + db_process_sql_update( + 'talert_commands', + [ + 'command' => io_safe_input('perl /usr/share/pandora_server/util/integria_rticket.pl -p '.$config['integria_hostname'].'/integria/include/api.php -u '.$config['integria_api_pass'].','.$config['integria_user'].','.$config['integria_pass'].' -create_ticket -name "_field1_" -desc "_field2_" -group _field3_ -priority _field4_ -owner _field5_ -type _field6_'), + 'fields_values' => '["'.io_safe_input($config['incident_title']).'", "'.io_safe_input($config['incident_content']).'", "'.io_safe_input($config['default_group']).'", "'.io_safe_input($config['default_criticity']).'", "'.io_safe_input($config['default_owner']).'", "'.io_safe_input($config['incident_type']).'"]', + ], + ['name' => io_safe_input('Integria IMS Ticket')] + ); + + // Update 'Create Integria IMS Ticket' action when setup data is updated, user enables IntegriaIMS integration and command does exist in database. + db_process_sql_update( + 'talert_actions', + [ + 'field1' => io_safe_input($config['incident_title']), + 'field1_recovery' => io_safe_input($config['incident_title']), + 'field2' => io_safe_input($config['incident_content']), + 'field2_recovery' => io_safe_input($config['incident_content']), + 'field3' => io_safe_input($config['default_group']), + 'field3_recovery' => io_safe_input($config['default_group']), + 'field4' => io_safe_input($config['default_criticity']), + 'field4_recovery' => io_safe_input($config['default_criticity']), + 'field5' => io_safe_input($config['default_owner']), + 'field5_recovery' => io_safe_input($config['default_owner']), + ], + ['name' => io_safe_input('Create Integria IMS ticket')] + ); } } else { - if ($row != false) { - // Delete 'Create incident in IntegriaIMS from event' event response if it does exist and IntegriaIMS integration is disabled - db_process_sql_delete('tevent_response', ['name' => 'Create incident in IntegriaIMS from event']); + if ($event_response_exists != false) { + // Delete 'Create incident in IntegriaIMS from event' event response if it does exist and IntegriaIMS integration is disabled. + db_process_sql_delete('tevent_response', ['name' => io_safe_input('Create incident in IntegriaIMS from event')]); + } + + if ($command_exists != false) { + // Delete 'Integria IMS Ticket' command if it does exist and IntegriaIMS integration is disabled. + db_process_sql_delete('talert_commands', ['name' => io_safe_input('Integria IMS Ticket')]); + + // Delete 'Create Integria IMS Ticket' action if command exists and IntegriaIMS integration is disabled. + db_process_sql_delete('talert_actions', ['name' => io_safe_input('Create Integria IMS ticket')]); } } } +// Get parameters from Integria IMS API. +$group_values = []; +$integria_criticity_values = []; +$integria_users_values = []; +$integria_types_values = []; + +$integria_groups_csv = integria_api_call($config['integria_hostname'], $config['integria_user'], $config['integria_pass'], $config['integria_api_pass'], 'get_groups', []); + +get_array_from_csv_data($integria_groups_csv, $group_values); + +$integria_criticity_levels_csv = integria_api_call($config['integria_hostname'], $config['integria_user'], $config['integria_pass'], $config['integria_api_pass'], 'get_incident_priorities', []); + +get_array_from_csv_data($integria_criticity_levels_csv, $integria_criticity_values); + +$integria_users_csv = integria_api_call($config['integria_hostname'], $config['integria_user'], $config['integria_pass'], $config['integria_api_pass'], 'get_users', []); + +$csv_array = explode("\n", $integria_users_csv); + +foreach ($csv_array as $csv_line) { + if (!empty($csv_line)) { + $integria_users_values[$csv_line] = $csv_line; + } +} + +$integria_types_csv = integria_api_call($config['integria_hostname'], $config['integria_user'], $config['integria_pass'], $config['integria_api_pass'], 'get_types', []); + +get_array_from_csv_data($integria_types_csv, $integria_types_values); + // Enable table. $table_enable = new StdClass(); $table_enable->data = []; @@ -72,25 +183,32 @@ $table_remote->class = 'databox filters'; $table_remote->size['name'] = '30%'; $table_remote->style['name'] = 'font-weight: bold'; -// User. +// Integria user. $row = []; $row['name'] = __('User'); $row['control'] = html_print_input_text('integria_user', $config['integria_user'], '', 30, 100, true); $table_remote->data['integria_user'] = $row; -// Pass. +// Integria password. $row = []; $row['name'] = __('Password'); $row['control'] = html_print_input_password('integria_pass', io_output_password($config['integria_pass']), '', 30, 100, true); $table_remote->data['integria_pass'] = $row; -// Directory hostname. +// Integria hostname. $row = []; $row['name'] = __('API Hostname'); $row['control'] = html_print_input_text('integria_hostname', $config['integria_hostname'], '', 30, 100, true); -$row['control'] .= ui_print_help_tip(__('Hostname of the Integria API')); +$row['control'] .= ui_print_help_tip(__('Hostname of Integria IMS\' API (scheme must be specified. Example: http://192.168.0.0)'), true); $table_remote->data['integria_hostname'] = $row; +// API password. +$row = []; +$row['name'] = __('API Password'); +$row['control'] = html_print_input_text('integria_api_pass', $config['integria_api_pass'], '', 30, 100, true); +$row['control'] .= ui_print_help_tip(__('Password of Integria IMS\' API'), true); +$table_remote->data['integria_api_pass'] = $row; + // Request timeout. $row = []; $row['name'] = __('Request timeout'); @@ -98,6 +216,118 @@ $row['control'] = html_print_input_text('integria_req_timeout', $config['integri $row['control'] .= ui_print_help_tip(__('Time in seconds to set the maximum time of the requests to the Integria API').'. '.__('0 to disable'), true); $table_remote->data['integria_req_timeout'] = $row; +// Custom response settings. +$table_cr_settings = new StdClass(); +$table_cr_settings->data = []; +$table_cr_settings->width = '100%'; +$table_cr_settings->styleTable = 'margin-bottom: 10px;'; +$table_cr_settings->id = 'integria-cr-settings-setup'; +$table_cr_settings->class = 'databox filters'; +$table_cr_settings->size['name'] = '30%'; +$table_cr_settings->style['name'] = 'font-weight: bold'; + +// Custom response default group. +$row = []; +$row['name'] = __('Default group'); +$row['control'] = html_print_select( + $group_values, + 'default_group', + $config['default_group'], + '', + __('Select'), + 0, + true, + false, + true, + '', + false +); +$table_cr_settings->data['custom_response_def_group'] = $row; + +// Custom response default criticity. +$row = []; +$row['name'] = __('Default criticity'); +$row['control'] = html_print_select( + $integria_criticity_values, + 'default_criticity', + $config['default_criticity'], + '', + __('Select'), + 0, + true, + false, + true, + '', + false +); +$table_cr_settings->data['custom_response_def_criticity'] = $row; + +// Custom response default owner. +$row = []; +$row['name'] = __('Default owner'); +$row['control'] = html_print_select( + $integria_users_values, + 'default_owner', + $config['default_owner'], + '', + __('Select'), + 0, + true, + false, + true, + '', + false +); +$table_cr_settings->data['custom_response_def_owner'] = $row; + +// Custom response default incident type. +$row = []; +$row['name'] = __('Incident type'); +$row['control'] = html_print_select( + $integria_types_values, + 'incident_type', + $config['incident_type'], + '', + __('Select'), + 0, + true, + false, + true, + '', + false +); +$table_cr_settings->data['custom_response_incident_type'] = $row; + +// Custom response incident title. +$row = []; +$row['name'] = __('Incident title'); +$row['control'] = html_print_input_text( + 'incident_title', + $config['incident_title'], + __('Name'), + 50, + 100, + true, + false, + false +).ui_print_help_icon('response_macros', true); +$table_cr_settings->data['custom_response_incident_title'] = $row; + +// Custom response incident content. +$row = []; +$row['name'] = __('Incident content'); +$row['control'] = html_print_input_text( + 'incident_content', + $config['incident_content'], + '', + 50, + 100, + true, + false, + false +).ui_print_help_icon('response_macros', true); +$table_cr_settings->data['custom_response_incident_content'] = $row; + // Test. $row = []; $row['name'] = __('Test'); @@ -108,68 +338,86 @@ $row['control'] .= '