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', ] ); } $ticket_types = integria_api_call($config['integria_hostname'], $config['integria_user'], $config['integria_pass'], $config['integria_api_pass'], 'get_types', '', false, 'json'); $types_string = ''; if ($ticket_types !== '') { foreach (json_decode($ticket_types, true) as $key => $value) { $types_string .= $value['id'].','.$value['name'].';'; } } 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').'","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_"]', 'fields_values' => '["", "", "","","'.$types_string.'","","","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_"]', ] ); // 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 'Integria IMS Ticket' command with ticket types retrieved from Integria IMS. $sql_update_command_values = sprintf( ' UPDATE talert_commands SET fields_values = \'["","","","","%s","","","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_"]\' WHERE name="%s"', $types_string, io_safe_input('Integria IMS Ticket') ); db_process_sql($sql_update_command_values); // Update those actions that make use of 'Integria IMS Ticket' command when setup default fields are updated. Empty fields in actions will be filled in with default values. $update_action_values = [ $config['incident_title'], $config['default_group'], $config['default_criticity'], $config['default_owner'], $config['incident_type'], $config['incident_status'], $config['incident_content'], ]; foreach ($update_action_values as $key => $value) { $field_key = ($key + 1); $sql_update_action_field = sprintf( ' UPDATE talert_actions taa INNER JOIN talert_commands tac ON taa.id_alert_command=tac.id SET field%s= "%s" WHERE tac.name="Integria IMS Ticket" AND ( taa.field%s IS NULL OR taa.field%s="" )', $field_key, $value, $field_key, $field_key, $field_key ); db_process_sql($sql_update_action_field); } foreach ($update_action_values as $key => $value) { $field_key = ($key + 1); $sql_update_action_recovery_field = sprintf( ' UPDATE talert_actions taa INNER JOIN talert_commands tac ON taa.id_alert_command=tac.id SET field%s_recovery = "%s" WHERE tac.name="Integria IMS Ticket" AND ( taa.field%s_recovery IS NULL OR taa.field%s_recovery="" )', $field_key, $value, $field_key, $field_key, $field_key ); db_process_sql($sql_update_action_recovery_field); } } } 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')]); } } } // 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); $row['control'] .= ui_print_reveal_password('integria_pass', 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); $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_reveal_password('integria_api_pass', 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); $table_remote->data['integria_req_timeout'] = $row; $row = []; $row['name'] = __('Inventory'); $row['control'] = html_print_button(__('Sync inventory'), 'sync-inventory', false, '', 'class="sub next"', true); $row['control'] .= ' '.html_print_image('images/spinner.gif', true).''; $row['control'] .= ' '.html_print_image('images/status_sets/default/severity_normal.png', true).''; $row['control'] .= ' '.html_print_image('images/status_sets/default/severity_critical.png', true).''; $row['control'] .= ' '; $table_remote->data['integria_test'] = $row; // Print. echo '
'; $row['control'] .= ' '; $row['control'] .= ' '; $table_remote->data['integria_sync_inventory'] = $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'] .= '