From 027f9fd9d46f9d890ab7ab4f85f8db7fe14d1c3b Mon Sep 17 00:00:00 2001 From: Tatiana Llorente Date: Tue, 17 Sep 2019 12:59:29 +0200 Subject: [PATCH] New view - List of Integria IMS tickets - #4642 --- .../godmode/setup/setup_integria.php | 6 +- pandora_console/include/functions.php | 82 +++++++++++++- pandora_console/include/functions_html.php | 105 ++++++++++++++++++ pandora_console/include/styles/pandora.css | 11 ++ .../configure_integriaims_incident.php | 6 +- pandora_console/operation/menu.php | 1 + 6 files changed, 203 insertions(+), 8 deletions(-) diff --git a/pandora_console/godmode/setup/setup_integria.php b/pandora_console/godmode/setup/setup_integria.php index a3b25b7e07..c054e857b8 100644 --- a/pandora_console/godmode/setup/setup_integria.php +++ b/pandora_console/godmode/setup/setup_integria.php @@ -138,11 +138,11 @@ $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); +get_array_from_csv_data_pair($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); +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', []); @@ -156,7 +156,7 @@ foreach ($csv_array as $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); +get_array_from_csv_data_pair($integria_types_csv, $integria_types_values); // Enable table. $table_enable = new StdClass(); diff --git a/pandora_console/include/functions.php b/pandora_console/include/functions.php index 9442f88b20..35993d84de 100644 --- a/pandora_console/include/functions.php +++ b/pandora_console/include/functions.php @@ -5453,7 +5453,7 @@ if (!function_exists('getallheaders')) { * * @return boolean True if API request succeeded, false if API request failed. */ -function integria_api_call($api_hostname, $user, $user_pass, $api_pass, $operation, $params_array, $show_credentials_error_msg=false) +function integria_api_call($api_hostname, $user, $user_pass, $api_pass, $operation, $params_array=[], $show_credentials_error_msg=false) { $params_string = implode(',', $params_array); @@ -5506,7 +5506,7 @@ function integria_api_call($api_hostname, $user, $user_pass, $api_pass, $operati // Parse CSV consisting of one or more lines of the form key-value pair into an array. -function get_array_from_csv_data($csv_data, &$array_values) +function get_array_from_csv_data_pair($csv_data, &$array_values) { $csv_array = explode("\n", $csv_data); @@ -5520,3 +5520,81 @@ function get_array_from_csv_data($csv_data, &$array_values) $array_values[$new_csv_value[0]] = $new_csv_value[1]; } } + + +/** + * Parse CSV consisting of one or more lines of the form key-value pair into an array. + * + * @param string $csv_data Data returned of csv api call. + * @param string $array_values Returned array. + * @param array $index Array to create an associative index (opcional). + */ +function get_array_from_csv_data_all($csv_data, &$array_values, $index=false) +{ + $csv_array = explode("\n", $csv_data); + + foreach ($csv_array as $csv_value) { + if (empty($csv_value)) { + continue; + } + + $new_csv_value = str_getcsv($csv_value); + + if ($index !== false) { + foreach ($new_csv_value as $key => $value) { + $new_csv_value_index[$index[$key]] = $value; + } + + $array_values[$new_csv_value[0]] = $new_csv_value_index; + } else { + $array_values[$new_csv_value[0]] = $new_csv_value; + } + } +} + + +/** + * Print priority for Integria IMS with colors. + * + * @param string $priority value of priority in Integria IMS. + * @param string $priority_label text shown in color box. + * + * @return HTML code to print the color box. + */ +function ui_print_integria_incident_priority($priority, $priority_label) +{ + global $config; + + $output = ''; + switch ($priority) { + case 0: + $color = COL_UNKNOWN; + break; + + case 1: + $color = COL_NORMAL; + break; + + case 10: + $color = COL_NOTINIT; + break; + + case 2: + $color = COL_WARNING; + break; + + case 3: + $color = COL_ALERTFIRED; + break; + + case 4: + $color = COL_CRITICAL; + break; + } + + $output = '
'; + $output .= $priority_label; + $output .= '
'; + + return $output; +} diff --git a/pandora_console/include/functions_html.php b/pandora_console/include/functions_html.php index 08d60dbb6e..b464df210e 100644 --- a/pandora_console/include/functions_html.php +++ b/pandora_console/include/functions_html.php @@ -3356,3 +3356,108 @@ function html_print_input($data, $wrapper='div', $input_only=false) return $output; } + + +/** + * Print an autocomplete input filled out with Integria IMS users. + * + * @param string $name The name of ajax control, by default is "users". + * @param string $default The default value to show in the ajax control. + * @param boolean $return If it is true return a string with the output instead to echo the output. + * @param string $size Size. + * + * @return mixed If the $return is true, return the output as string. + */ +function html_print_autocomplete_users_from_integria( + $name='users', + $default='', + $return=false, + $size='30' +) { + global $config; + + ob_start(); + + html_print_input_text_extended( + $name, + $default, + 'text-'.$name, + '', + $size, + 100, + false, + '', + [] + ); + html_print_input_hidden($name.'_hidden', $id_agent_module); + ui_print_help_tip(__('Type at least two characters to search the module.'), false); + + $javascript_ajax_page = ui_get_full_url('ajax.php', false, false, false, false); + ?> + +