diff --git a/pandora_console/extras/mr/32.sql b/pandora_console/extras/mr/32.sql index 18e31dfb38..2e50885f21 100644 --- a/pandora_console/extras/mr/32.sql +++ b/pandora_console/extras/mr/32.sql @@ -15,9 +15,30 @@ UPDATE `tlayout_data` SET `height` = 70 , `width` = 70 WHERE `height` = 0 && `wi (`type` = 10 && `image` IS NOT NULL && `image` != '' && `image` != 'none') || (`type` = 11 && `image` IS NOT NULL && `image` != '' && `image` != 'none' && `show_statistics` = 0)); +INSERT INTO `tconfig` (`token`, `value`) VALUES ('integria_enabled', 0); +INSERT INTO `tconfig` (`token`, `value`) VALUES ('integria_user', ''); +INSERT INTO `tconfig` (`token`, `value`) VALUES ('integria_pass', ''); +INSERT INTO `tconfig` (`token`, `value`) VALUES ('integria_hostname', ''); +INSERT INTO `tconfig` (`token`, `value`) VALUES ('integria_api_pass', ''); +INSERT INTO `tconfig` (`token`, `value`) VALUES ('integria_req_timeout', 5); +INSERT INTO `tconfig` (`token`, `value`) VALUES ('default_group', ''); +INSERT INTO `tconfig` (`token`, `value`) VALUES ('default_criticity', ''); +INSERT INTO `tconfig` (`token`, `value`) VALUES ('default_creator', ''); +INSERT INTO `tconfig` (`token`, `value`) VALUES ('default_owner', ''); +INSERT INTO `tconfig` (`token`, `value`) VALUES ('incident_type', ''); +INSERT INTO `tconfig` (`token`, `value`) VALUES ('incident_status', ''); +INSERT INTO `tconfig` (`token`, `value`) VALUES ('incident_title', ''); +INSERT INTO `tconfig` (`token`, `value`) VALUES ('incident_content', ''); +INSERT INTO `tconfig` (`token`, `value`) VALUES ('cr_default_group', ''); +INSERT INTO `tconfig` (`token`, `value`) VALUES ('cr_default_criticity', ''); +INSERT INTO `tconfig` (`token`, `value`) VALUES ('cr_default_creator', ''); +INSERT INTO `tconfig` (`token`, `value`) VALUES ('cr_default_owner', ''); +INSERT INTO `tconfig` (`token`, `value`) VALUES ('cr_incident_type', ''); +INSERT INTO `tconfig` (`token`, `value`) VALUES ('cr_incident_status', ''); +INSERT INTO `tconfig` (`token`, `value`) VALUES ('cr_incident_title', ''); +INSERT INTO `tconfig` (`token`, `value`) VALUES ('cr_incident_content', ''); ALTER TABLE `treport_content` ADD COLUMN `uncompressed_module` TINYINT DEFAULT '0'; ALTER TABLE `treport_content_template` ADD COLUMN `uncompressed_module` TINYINT DEFAULT '0'; - COMMIT; diff --git a/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql b/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql index a449004ce8..cac39dc56d 100644 --- a/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql +++ b/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql @@ -1256,10 +1256,30 @@ DELETE FROM `tconfig` WHERE `token` = 'current_package_enterprise'; INSERT INTO `tconfig` (`token`, `value`) VALUES ('current_package_enterprise', '737'); INSERT INTO `tconfig` (`token`, `value`) VALUES ('status_monitor_fields', 'policy,agent,data_type,module_name,server_type,interval,status,graph,warn,data,timestamp'); UPDATE `tconfig` SET `value` = 'mini_severity,evento,id_agente,estado,timestamp' WHERE `token` LIKE 'event_fields'; -DELETE FROM `tconfig` WHERE `token` LIKE 'integria_enabled'; DELETE FROM `tconfig` WHERE `token` LIKE 'integria_api_password'; DELETE FROM `tconfig` WHERE `token` LIKE 'integria_inventory'; DELETE FROM `tconfig` WHERE `token` LIKE 'integria_url'; +INSERT INTO `tconfig` (`token`, `value`) VALUES ('integria_user', ''); +INSERT INTO `tconfig` (`token`, `value`) VALUES ('integria_pass', ''); +INSERT INTO `tconfig` (`token`, `value`) VALUES ('integria_hostname', ''); +INSERT INTO `tconfig` (`token`, `value`) VALUES ('integria_api_pass', ''); +INSERT INTO `tconfig` (`token`, `value`) VALUES ('integria_req_timeout', 5); +INSERT INTO `tconfig` (`token`, `value`) VALUES ('default_group', ''); +INSERT INTO `tconfig` (`token`, `value`) VALUES ('default_criticity', ''); +INSERT INTO `tconfig` (`token`, `value`) VALUES ('default_creator', ''); +INSERT INTO `tconfig` (`token`, `value`) VALUES ('default_owner', ''); +INSERT INTO `tconfig` (`token`, `value`) VALUES ('incident_type', ''); +INSERT INTO `tconfig` (`token`, `value`) VALUES ('incident_status', ''); +INSERT INTO `tconfig` (`token`, `value`) VALUES ('incident_title', ''); +INSERT INTO `tconfig` (`token`, `value`) VALUES ('incident_content', ''); +INSERT INTO `tconfig` (`token`, `value`) VALUES ('cr_default_group', ''); +INSERT INTO `tconfig` (`token`, `value`) VALUES ('cr_default_criticity', ''); +INSERT INTO `tconfig` (`token`, `value`) VALUES ('cr_default_creator', ''); +INSERT INTO `tconfig` (`token`, `value`) VALUES ('cr_default_owner', ''); +INSERT INTO `tconfig` (`token`, `value`) VALUES ('cr_incident_type', ''); +INSERT INTO `tconfig` (`token`, `value`) VALUES ('cr_incident_status', ''); +INSERT INTO `tconfig` (`token`, `value`) VALUES ('cr_incident_title', ''); +INSERT INTO `tconfig` (`token`, `value`) VALUES ('cr_incident_content', ''); -- --------------------------------------------------------------------- -- Table `tconfig_os` diff --git a/pandora_console/godmode/menu.php b/pandora_console/godmode/menu.php index 000a105257..e57ee47409 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§ion=ehorus']['text'] = __('eHorus'); $sub2['godmode/setup/setup§ion=ehorus']['refr'] = 0; + $sub2['godmode/setup/setup§ion=integria']['text'] = __('Integria IMS'); + $sub2['godmode/setup/setup§ion=integria']['refr'] = 0; + $sub2['godmode/setup/setup§ion=notifications']['text'] = __('Notifications'); $sub2['godmode/setup/setup§ion=notifications']['refr'] = 0; diff --git a/pandora_console/godmode/setup/setup.php b/pandora_console/godmode/setup/setup.php index c32f128ddd..a46d7bc832 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/integria.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'); @@ -228,6 +239,10 @@ switch ($section) { include_once $config['homedir'].'/godmode/setup/setup_ehorus.php'; break; + case 'integria': + include_once $config['homedir'].'/godmode/setup/setup_integria.php'; + break; + case 'notifications': include_once $config['homedir'].'/godmode/setup/setup_notifications.php'; break; diff --git a/pandora_console/godmode/setup/setup_integria.php b/pandora_console/godmode/setup/setup_integria.php new file mode 100644 index 0000000000..95179f6add --- /dev/null +++ b/pandora_console/godmode/setup/setup_integria.php @@ -0,0 +1,702 @@ + 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 && $config['integria_enabled']) { + 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. + $event_response_exists = db_get_row_filter('tevent_response', ['name' => io_safe_input('Create ticket 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 ($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' => io_safe_input('Create ticket in IntegriaIMS from event'), + 'description' => io_safe_input('Create a ticket 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('Internal type'), + 'internal' => 1, + 'description' => io_safe_input('Create a ticket in Integria IMS'), + 'fields_descriptions' => '["'.io_safe_input('Ticket title').'","'.io_safe_input('Ticket group ID').'","'.io_safe_input('Ticket priority').'","'.io_safe_input('Ticket owner').'","'.io_safe_input('Ticket type').'","'.io_safe_input('Ticket status').'","'.io_safe_input('Ticket description').'"]', + ] + ); + + // 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['default_group']), + 'field2_recovery' => io_safe_input($config['default_group']), + 'field3' => io_safe_input($config['default_criticity']), + 'field3_recovery' => io_safe_input($config['default_criticity']), + 'field4' => io_safe_input($config['default_owner']), + 'field4_recovery' => io_safe_input($config['default_owner']), + 'field5' => io_safe_input($config['incident_type']), + 'field5_recovery' => io_safe_input($config['incident_type']), + 'field6' => io_safe_input($config['incident_status']), + 'field6_recovery' => io_safe_input($config['incident_status']), + 'field7' => io_safe_input($config['incident_content']), + 'field7_recovery' => io_safe_input($config['incident_content']), + 'id_group' => 0, + 'action_threshold' => 0, + ]; + + alerts_create_alert_action(io_safe_input('Create Integria IMS ticket'), $id_command_inserted, $action_values); + } else { + // 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['default_group']), + 'field2_recovery' => io_safe_input($config['default_group']), + 'field3' => io_safe_input($config['default_criticity']), + 'field3_recovery' => io_safe_input($config['default_criticity']), + 'field4' => io_safe_input($config['default_owner']), + 'field4_recovery' => io_safe_input($config['default_owner']), + 'field5' => io_safe_input($config['incident_type']), + 'field5_recovery' => io_safe_input($config['incident_type']), + 'field6' => io_safe_input($config['incident_status']), + 'field6_recovery' => io_safe_input($config['incident_status']), + 'field7' => io_safe_input($config['incident_content']), + 'field7_recovery' => io_safe_input($config['incident_content']), + ], + ['name' => io_safe_input('Create Integria IMS ticket')] + ); + } + } else { + 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 ticket 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. +$integria_group_values = []; +$integria_criticity_values = []; +$integria_users_values = []; +$integria_types_values = []; +$integria_status_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_pair($integria_groups_csv, $integria_group_values); + +$integria_status_csv = integria_api_call($config['integria_hostname'], $config['integria_user'], $config['integria_pass'], $config['integria_api_pass'], 'get_incidents_status', []); + +get_array_from_csv_data_pair($integria_status_csv, $integria_status_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_pair($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_pair($integria_types_csv, $integria_types_values); + +// Enable table. +$table_enable = new StdClass(); +$table_enable->data = []; +$table_enable->width = '100%'; +$table_enable->id = 'integria-enable-setup'; +$table_enable->class = 'databox filters'; +$table_enable->size['name'] = '30%'; +$table_enable->style['name'] = 'font-weight: bold'; + +// Enable Integria. +$row = []; +$row['name'] = __('Enable Integria IMS'); +$row['control'] = html_print_checkbox_switch('integria_enabled', 1, $config['integria_enabled'], true); +$table_enable->data['integria_enabled'] = $row; + +// Remote config table. +$table_remote = new StdClass(); +$table_remote->data = []; +$table_remote->width = '100%'; +$table_remote->styleTable = 'margin-bottom: 10px;'; +$table_remote->id = 'integria-remote-setup'; +$table_remote->class = 'databox filters'; +$table_remote->size['name'] = '30%'; +$table_remote->style['name'] = 'font-weight: bold'; + +// 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; + +// 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; + +// 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 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_password('integria_api_pass', io_output_password($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'); +$row['control'] = html_print_input_text('integria_req_timeout', $config['integria_req_timeout'], '', 3, 10, true); +$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; + +// Alert settings. +$table_alert_settings = new StdClass(); +$table_alert_settings->data = []; +$table_alert_settings->width = '100%'; +$table_alert_settings->styleTable = 'margin-bottom: 10px;'; +$table_alert_settings->id = 'integria-cr-settings-setup'; +$table_alert_settings->class = 'databox filters'; +$table_alert_settings->size['name'] = '30%'; +$table_alert_settings->style['name'] = 'font-weight: bold'; + +// Alert incident title. +$row = []; +$row['name'] = __('Title'); +$row['control'] = html_print_input_text( + 'incident_title', + $config['incident_title'], + __('Name'), + 50, + 100, + true, + false, + false +).ui_print_help_icon('alert_macros', true); +$table_alert_settings->data['custom_response_incident_title'] = $row; + +// Alert incident description. +$row = []; +$row['name'] = __('Description'); +$row['control'] = html_print_input_text( + 'incident_content', + $config['incident_content'], + '', + 50, + 100, + true, + false, + false +).ui_print_help_icon('alert_macros', true); +$table_alert_settings->data['custom_response_incident_content'] = $row; + +// Alert default group. +$row = []; +$row['name'] = __('Group'); +$row['control'] = html_print_select( + $integria_group_values, + 'default_group', + $config['default_group'], + '', + __('Select'), + 0, + true, + false, + true, + '', + false +); +$table_alert_settings->data['custom_response_def_group'] = $row; + +// Alert default criticity. +$row = []; +$row['name'] = __('Priority'); +$row['control'] = html_print_select( + $integria_criticity_values, + 'default_criticity', + $config['default_criticity'], + '', + __('Select'), + 0, + true, + false, + true, + '', + false +); +$table_alert_settings->data['custom_response_def_criticity'] = $row; + +// Alert default owner. +$row = []; +$row['name'] = __('Owner'); +$row['control'] = html_print_autocomplete_users_from_integria( + 'default_owner', + $config['default_owner'], + true +); + +$table_alert_settings->data['custom_response_def_owner'] = $row; + +// Alert default incident type. +$row = []; +$row['name'] = __('Type'); +$row['control'] = html_print_select( + $integria_types_values, + 'incident_type', + $config['incident_type'], + '', + __('Select'), + 0, + true, + false, + true, + '', + false +); +$table_alert_settings->data['custom_response_incident_type'] = $row; + +// Alert default incident status. +$row = []; +$row['name'] = __('Status'); +$row['control'] = html_print_select( + $integria_status_values, + 'incident_status', + $config['incident_status'], + '', + __('Select'), + 0, + true, + false, + true, + '', + false +); +$table_alert_settings->data['custom_response_incident_status'] = $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 incident title. +$row = []; +$row['name'] = __('Title'); +$row['control'] = html_print_input_text( + 'cr_incident_title', + $config['cr_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 description. +$row = []; +$row['name'] = __('Description'); +$row['control'] = html_print_input_text( + 'cr_incident_content', + $config['cr_incident_content'], + '', + 50, + 100, + true, + false, + false +).ui_print_help_icon('response_macros', true); +$table_cr_settings->data['custom_response_incident_content'] = $row; + +// Custom response default group. +$row = []; +$row['name'] = __('Group'); +$row['control'] = html_print_select( + $integria_group_values, + 'cr_default_group', + $config['cr_default_group'], + '', + __('Select'), + 0, + true, + false, + true, + '', + false +); +$table_cr_settings->data['custom_response_def_group'] = $row; + +// Custom response default criticity. +$row = []; +$row['name'] = __('Priority'); +$row['control'] = html_print_select( + $integria_criticity_values, + 'cr_default_criticity', + $config['cr_default_criticity'], + '', + __('Select'), + 0, + true, + false, + true, + '', + false +); +$table_cr_settings->data['custom_response_def_criticity'] = $row; + +// Custom response default owner. +$row = []; +$row['name'] = __('Owner'); +$row['control'] = html_print_autocomplete_users_from_integria( + 'cr_default_owner', + $config['cr_default_owner'], + true +); + +$table_cr_settings->data['custom_response_def_owner'] = $row; + +// Custom response default incident type. +$row = []; +$row['name'] = __('Type'); +$row['control'] = html_print_select( + $integria_types_values, + 'cr_incident_type', + $config['cr_incident_type'], + '', + __('Select'), + 0, + true, + false, + true, + '', + false +); +$table_cr_settings->data['custom_response_incident_type'] = $row; + +// Custom response default incident status. +$row = []; +$row['name'] = __('Status'); +$row['control'] = html_print_select( + $integria_status_values, + 'cr_incident_status', + $config['cr_incident_status'], + '', + __('Select'), + 0, + true, + false, + true, + '', + false +); +$table_cr_settings->data['custom_response_incident_status'] = $row; + +// Test. +$row = []; +$row['name'] = __('Test'); +$row['control'] = html_print_button(__('Start'), 'test-integria', false, '', 'class="sub next"', true); +$row['control'] .= ' '; +$row['control'] .= ' '; +$row['control'] .= ' '; +$row['control'] .= ' '; +$table_remote->data['integria_test'] = $row; + +// Print. +echo '
'.__('Title').': '.$help_macros.'
'; +$table->data[0][0] .= ''.__('Type').':
'; +$table->data[1][0] .= ''.__('Status').':
'; +$table->data[2][0] .= ''.__('Group').':
'; +$table->data[1][1] .= ''.__('Creator').':
'; +$table->data[2][1] .= ''.__('Priority').':
'; +$table->data[1][2] .= ''.__('Owner').':
'; + +$table->data[2][2] .= ''.__('Description').': '.$help_macros.'
'; +$table->data[3][0] .= ''.__('File name').':
'; +$table_files_section->data[0][0] .= html_print_input_file('userfile', true); +$table_files_section->data[1][0] = ''.__('Description').':
'; +$table_files_section->data[1][0] .= html_print_textarea( + 'file_description', + 3, + 20, + '', + '', + true +); + +$table_files_section->data[2][0] .= ''.__('Description').':
'; +$table_comments_section->data[0][0] .= html_print_textarea( + 'comment_description', + 3, + 20, + '', + $attribute, + true +); + +$table_comments_section->data[1][1] .= '