From 75bb4338b7a36ac09af8639075769a6924b35c9c Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Thu, 22 Oct 2020 18:10:46 +0200 Subject: [PATCH 01/18] fixes in event macros (responses) --- pandora_console/include/functions_events.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/pandora_console/include/functions_events.php b/pandora_console/include/functions_events.php index 7a337fbdab..6996157cbb 100644 --- a/pandora_console/include/functions_events.php +++ b/pandora_console/include/functions_events.php @@ -3811,7 +3811,7 @@ function events_get_response_target( if (strpos($target, '_alert_id_') !== false) { $target = str_replace( '_alert_id_', - empty($event['is_alert_am']) ? __('N/A') : $event['is_alert_am'], + empty($event['id_alert_am']) ? __('N/A') : $event['id_alert_am'], $target ); } @@ -3893,6 +3893,15 @@ function events_get_response_target( $target = str_replace('_current_user_', $config['id_user'], $target); } + // This will replace the macro with the command timeout value. + if (strpos($target, '_command_timeout_') !== false) { + $target = str_replace( + '_command_timeout_', + $event_response['command_timeout'], + $target + ); + } + return $target; } @@ -6973,7 +6982,7 @@ function events_get_field_value_by_event_id( if (strpos($value, '_group_name_') !== false) { $value = str_replace( '_group_name_', - groups_get_name($event['id_grupo'], true), + io_safe_output(groups_get_name($event['id_grupo'], true)), $value ); } From 5d812d58596e1d53bbc8c0ba6a02d4ce46fdcdd6 Mon Sep 17 00:00:00 2001 From: alejandro-campos Date: Fri, 23 Oct 2020 09:20:23 +0200 Subject: [PATCH 02/18] added new macros --- pandora_console/include/functions_events.php | 32 ++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/pandora_console/include/functions_events.php b/pandora_console/include/functions_events.php index 7a337fbdab..c150aec85a 100644 --- a/pandora_console/include/functions_events.php +++ b/pandora_console/include/functions_events.php @@ -3692,6 +3692,38 @@ function events_get_response_target( $event_response = db_get_row('tevent_response', 'id', $response_id); $target = io_safe_output($event_response['target']); + if (strpos($target, '_agent_alias_') !== false) { + if ($meta) { + $agente_table_name = 'tmetaconsole_agent'; + $filter = [ + 'id_tagente' => $event['id_agente'], + 'id_tmetaconsole_setup' => $server_id, + ]; + } else { + $agente_table_name = 'tagente'; + $filter = ['id_agente' => $event['id_agente']]; + } + + $alias = db_get_value_filter('alias', $agente_table_name, $filter); + $target = str_replace('_agent_alias_', io_safe_output($alias), $target); + } + + if (strpos($target, '_agent_name_') !== false) { + if ($meta) { + $agente_table_name = 'tmetaconsole_agent'; + $filter = [ + 'id_tagente' => $event['id_agente'], + 'id_tmetaconsole_setup' => $server_id, + ]; + } else { + $agente_table_name = 'tagente'; + $filter = ['id_agente' => $event['id_agente']]; + } + + $name = db_get_value_filter('nombre', $agente_table_name, $filter); + $target = str_replace('_agent_name_', io_safe_output($name), $target); + } + // Substitute each macro. if (strpos($target, '_agent_address_') !== false) { if ($meta) { From bebac548d3946e1d972e5b946a54c3d674fdf931 Mon Sep 17 00:00:00 2001 From: Daniel Barbero Martin Date: Fri, 23 Oct 2020 10:47:03 +0200 Subject: [PATCH 03/18] fix exportation/exportation --- .../extensions/resource_exportation.php | 6 +- .../extensions/resource_registration.php | 83 ++++++++++++++----- 2 files changed, 65 insertions(+), 24 deletions(-) diff --git a/pandora_console/extensions/resource_exportation.php b/pandora_console/extensions/resource_exportation.php index 3946ec053d..16cf674ab6 100755 --- a/pandora_console/extensions/resource_exportation.php +++ b/pandora_console/extensions/resource_exportation.php @@ -92,7 +92,11 @@ function output_xml_report($id) $group = db_get_value('nombre', 'tgrupo', 'id_grupo', $report['id_group']); echo '\n"; - $items = db_get_all_rows_field_filter('treport_content', 'id_report', $report['id_report']); + $items = db_get_all_rows_field_filter( + 'treport_content', + 'id_report', + $report['id_report'] + ); foreach ($items as $item) { echo "\n"; echo ''.io_safe_output($item['type'])."\n"; diff --git a/pandora_console/extensions/resource_registration.php b/pandora_console/extensions/resource_registration.php index dae61e3a78..80fed2cf6c 100755 --- a/pandora_console/extensions/resource_registration.php +++ b/pandora_console/extensions/resource_registration.php @@ -37,8 +37,16 @@ function insert_item_report($report_id, $values) ui_print_result_message( $result, - sprintf(__("Success add '%s' item in report '%s'."), $values['type'], $name), - sprintf(__("Error create '%s' item in report '%s'."), $values['type'], $name) + sprintf( + __("Success add '%s' item in report '%s'."), + $values['type'], + $name + ), + sprintf( + __("Error create '%s' item in report '%s'."), + $values['type'], + $name + ) ); } } @@ -55,9 +63,12 @@ function process_upload_xml_report($xml, $group_filter=0) $posible_name = $values['name']; $exist = true; $loops = 30; - // Loops to exit or tries + // Loops to exit or tries. while ($exist && $loops > 0) { - $exist = (bool) db_get_row_filter('treport', ['name' => io_safe_input($posible_name)]); + $exist = (bool) db_get_row_filter( + 'treport', + ['name' => io_safe_input($posible_name)] + ); if ($exist) { $loops--; @@ -74,7 +85,7 @@ function process_upload_xml_report($xml, $group_filter=0) ); break; } else if ($loops != 30) { - ui_print_error_message( + ui_print_warning_message( sprintf( __("Warning create '%s' report, the name exist, the report have a name %s."), $reportElement->name, @@ -89,13 +100,22 @@ function process_upload_xml_report($xml, $group_filter=0) break; } - $id_group = db_get_value('id_grupo', 'tgrupo', 'nombre', $reportElement->group); - if ($id_group === false) { - ui_print_error_message(__("Error the report haven't group.")); - break; + if (isset($reportElement->group) === true + && empty($reportElement->group) === false + ) { + $id_group = db_get_value( + 'id_grupo', + 'tgrupo', + 'nombre', + $reportElement->group + ); + if ($id_group === false) { + ui_print_error_message(__("Error the report haven't group.")); + break; + } } - if (isset($reportElement->description)) { + if (isset($reportElement->description) === true) { $values['description'] = $reportElement->description; } @@ -108,9 +128,19 @@ function process_upload_xml_report($xml, $group_filter=0) ); if ($id_report) { - db_pandora_audit('Report management', 'Create report '.$id_report, false, false); + db_pandora_audit( + 'Report management', + 'Create report '.$id_report, + false, + false + ); } else { - db_pandora_audit('Report management', 'Fail to create report', false, false); + db_pandora_audit( + 'Report management', + 'Fail to create report', + false, + false + ); break; } @@ -119,45 +149,52 @@ function process_upload_xml_report($xml, $group_filter=0) $values = []; $values['id_report'] = $id_report; - if (isset($item['description'])) { + if (isset($item['description']) === true) { $values['description'] = io_safe_input($item['description']); } - if (isset($item['period'])) { + if (isset($item['period']) === true) { $values['period'] = io_safe_input($item['period']); } - if (isset($item['type'])) { + if (isset($item['type']) === true) { $values['type'] = io_safe_input($item['type']); } $agents_item = []; - if (isset($item['agent'])) { + if (isset($item['agent']) === true) { $agents = agents_get_agents( ['id_grupo' => $group_filter], [ 'id_agente', - 'nombre', + 'alias', ] ); - $agent_clean = str_replace(['[', ']'], '', $item['agent']); + $agent_clean = str_replace( + [ + '[', + ']', + ], + '', + io_safe_output($item['agent']) + ); $regular_expresion = ($agent_clean != $item['agent']); foreach ($agents as $agent) { if ($regular_expresion) { - if ((bool) preg_match('/'.$agent_clean.'/', io_safe_output($agent['nombre']))) { - $agents_item[$agent['id_agente']]['name'] = $agent['nombre']; + if ((bool) preg_match('/'.$agent_clean.'/', io_safe_output($agent['alias']))) { + $agents_item[$agent['id_agente']]['name'] = $agent['alias']; } } else { - if ($agent_clean == io_safe_output($agent['nombre'])) { - $agents_item[$agent['id_agente']]['name'] = $agent['nombre']; + if ($agent_clean == io_safe_output($agent['alias'])) { + $agents_item[$agent['id_agente']]['name'] = $agent['alias']; } } } } - if (isset($item['module'])) { + if (isset($item['module']) === true) { $module_clean = str_replace(['[', ']'], '', $item['module']); $regular_expresion = ($module_clean != $item['module']); From 765d7938f90307a324de6bb865c0832ba9f17f8b Mon Sep 17 00:00:00 2001 From: Jose Gonzalez Date: Fri, 23 Oct 2020 12:20:20 +0200 Subject: [PATCH 04/18] Handled comments for validated comments --- pandora_console/include/ajax/events.php | 4 ++- pandora_console/include/functions_events.php | 36 +++++++++++++------- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/pandora_console/include/ajax/events.php b/pandora_console/include/ajax/events.php index 230b55a476..d6a760413b 100644 --- a/pandora_console/include/ajax/events.php +++ b/pandora_console/include/ajax/events.php @@ -114,7 +114,9 @@ if ($get_comments) { sprintf( ' HAVING max_id_evento = %d', $event['id_evento'] - ) + ), + // True for show comments of validated events. + true ); if ($events !== false) { $event = $events[0]; diff --git a/pandora_console/include/functions_events.php b/pandora_console/include/functions_events.php index 7a337fbdab..8efeff3f2e 100644 --- a/pandora_console/include/functions_events.php +++ b/pandora_console/include/functions_events.php @@ -673,15 +673,16 @@ function events_update_status($id_evento, $status, $filter=null, $history=false) /** * Retrieve all events filtered. * - * @param array $fields Fields to retrieve. - * @param array $filter Filters to be applied. - * @param integer $offset Offset (pagination). - * @param integer $limit Limit (pagination). - * @param string $order Sort order. - * @param string $sort_field Sort field. - * @param boolean $history Apply on historical table. - * @param boolean $return_sql Return SQL (true) or execute it (false). - * @param string $having Having filter. + * @param array $fields Fields to retrieve. + * @param array $filter Filters to be applied. + * @param integer $offset Offset (pagination). + * @param integer $limit Limit (pagination). + * @param string $order Sort order. + * @param string $sort_field Sort field. + * @param boolean $history Apply on historical table. + * @param boolean $return_sql Return SQL (true) or execute it (false). + * @param string $having Having filter. + * @param boolean $validatedEvents If true, evaluate validated events. * * @return array Events. * @throws Exception On error. @@ -695,7 +696,8 @@ function events_get_all( $sort_field=null, $history=false, $return_sql=false, - $having='' + $having='', + $validatedEvents=false ) { global $config; @@ -926,10 +928,20 @@ function events_get_all( break; case EVENT_NO_VALIDATED: + // Show comments in validated events. + $validatedState = ''; + if ($validatedEvents === true) { + $validatedState = sprintf( + 'OR estado = %d', + EVENT_VALIDATE + ); + } + $sql_filters[] = sprintf( - ' AND (estado = %d OR estado = %d)', + ' AND (estado = %d OR estado = %d %s)', EVENT_NEW, - EVENT_PROCESS + EVENT_PROCESS, + $validatedState ); break; } From 4ff09235899f8e8210f1f5144f7dd74cdb9d4790 Mon Sep 17 00:00:00 2001 From: alejandro-campos Date: Fri, 23 Oct 2020 13:53:38 +0200 Subject: [PATCH 05/18] fixed sound events --- .../operation/events/sound_events.php | 29 ++++++++++++++----- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/pandora_console/operation/events/sound_events.php b/pandora_console/operation/events/sound_events.php index 4377faaa63..5037e63b22 100644 --- a/pandora_console/operation/events/sound_events.php +++ b/pandora_console/operation/events/sound_events.php @@ -77,7 +77,7 @@ $table->data[0][2] = __('Type'); $table->data[0][3] = html_print_checkbox('alert_fired', 'alert_fired', true, true, false, 'changeType();').__('Alert fired').'
'.html_print_checkbox('critical', 'critical', true, true, false, 'changeType();').__('Monitor critical').'
'.html_print_checkbox('unknown', 'unknown', true, true, false, 'changeType();').__('Monitor unknown').'
'.html_print_checkbox('warning', 'warning', true, true, false, 'changeType();').__('Monitor warning').'
'; $table->data[1][0] = __('Agent'); -$table->data[1][1] = html_print_select($agents, 'id_agents[]', true, false, '', '', true, true, '', '', '', 'width:120px; height:100px', '', false, '', '', true); +$table->data[1][1] = html_print_select($agents, 'id_agents[]', true, false, '', '', true, true, '', '', '', 'max-width:200px; height:100px', '', false, '', '', true); $table->data[1][2] = __('Event'); $table->data[1][3] = html_print_textarea('events_fired', 200, 20, '', 'readonly="readonly" style="max-height:100px; background: #ddd; resize:none;"', true); @@ -152,10 +152,26 @@ function changeGroup() { } function changeType() { - alert_fired = $("input[name=alert_fired]").attr('checked'); - critical = $("input[name=critical]").attr('checked'); - warning = $("input[name=warning]").attr('checked'); - unknown = $("input[name=unknown]").attr('checked'); + alert_fired = false; + critical = false; + warning = false; + unknown = false; + + if($("input[name=alert_fired]").is(':checked') ) { + alert_fired = true; + } + + if($("input[name=critical]").is(':checked') ) { + critical = true; + } + + if($("input[name=warning]").is(':checked') ) { + warning = true; + } + + if($("input[name=unknown]").is(':checked') ) { + unknown = true; + } } function toggleButton() { @@ -256,9 +272,6 @@ $(document).ready (function () { setInterval("check_event()", (10 * 1000)); //10 seconds between ajax request $("#table1").css("background-color", "#fff"); $("#table2").css("background-color", "#fff"); - - group_width = $("#group").width(); - $("#id_agents").width(group_width + 9); }); From 29174a87ef41d38638f5877feef99bfe57a6c190 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Mon, 26 Oct 2020 10:14:14 +0100 Subject: [PATCH 06/18] removed strict-user from monitor detail --- .../operation/agentes/status_monitor.php | 25 +------------------ 1 file changed, 1 insertion(+), 24 deletions(-) diff --git a/pandora_console/operation/agentes/status_monitor.php b/pandora_console/operation/agentes/status_monitor.php index a49db7b7f4..7be62557f4 100644 --- a/pandora_console/operation/agentes/status_monitor.php +++ b/pandora_console/operation/agentes/status_monitor.php @@ -701,7 +701,6 @@ foreach ($custom_fields as $custom_field) { $table_custom_fields->data[] = $row; } - $filters = '
'; if (is_metaconsole()) { $table->colspan[4][0] = 7; @@ -1750,24 +1749,13 @@ if (!empty($result)) { // End Build List Result. echo "
"; -// Strict user hidden. -echo ''; enterprise_hook('close_meta_frame'); ui_require_javascript_file('pandora_modules'); ?> -