diff --git a/pandora_console/include/ajax/events.php b/pandora_console/include/ajax/events.php index 55834d86d6..6838c97edd 100644 --- a/pandora_console/include/ajax/events.php +++ b/pandora_console/include/ajax/events.php @@ -992,6 +992,9 @@ if ($get_extended_event) { $timestamp_first = get_parameter('timestamp_first', $event['utimestamp']); $timestamp_last = get_parameter('timestamp_last', $event['utimestamp']); $server_id = get_parameter('server_id', 0); + $filter = get_parameter('filter', []); + + $event_rep = events_get_related_events($event_id, true, $filter); $event['similar_ids'] = $similar_ids; $event['timestamp_first'] = $timestamp_first; diff --git a/pandora_console/include/functions_events.php b/pandora_console/include/functions_events.php index c9733d7de0..51caab0753 100644 --- a/pandora_console/include/functions_events.php +++ b/pandora_console/include/functions_events.php @@ -261,6 +261,96 @@ function events_delete($id_evento, $filter=null, $history=false) } +/** + * Retrieves all events related to matching one. + * + * @param integer $id_evento Master event (max_id_evento). + * @param array $filter Filters. + * @param boolean $count Count results or get results. + * @param boolean $history Apply on historical table. + * + * @return array Events or false in case of error. + */ +function events_get_related_events( + $id_evento, + $filter=null, + $count=false, + $history=false +) { + global $config; + + if (!isset($id_evento) || $id_evento <= 0) { + return false; + } + + if (!isset($filter) || !is_array($filter)) { + $filter = ['group_rep' => 0]; + } + + $table = events_get_events_table(is_metaconsole(), $history); + $select = '*'; + if ($count === true) { + $select = 'count(*) as n'; + }; + + switch ($filter['group_rep']) { + case '0': + case '2': + default: + // No groups option direct update. + $related_sql = sprintf( + 'SELECT %s FROM %s + WHERE id_evento = %d', + $select, + $table, + $id_evento + ); + break; + + case '1': + // Group by events. + $sql = events_get_all( + ['te.*'], + $filter, + // Offset. + null, + // Limit. + null, + // Order. + null, + // Sort_field. + null, + // Historical table. + $history, + // Return_sql. + true + ); + $related_sql = sprintf( + 'SELECT %s FROM %s tu INNER JOIN ( %s ) tf + WHERE tu.estado = tf.estado + AND tu.evento = tf.evento + AND tu.id_agente = tf.id_agente + AND tu.id_agentmodule = tf.id_agentmodule + AND tf.max_id_evento = %d', + $select, + $table, + $sql, + $id_evento + ); + break; + } + + if ($count === true) { + $r = db_get_all_rows_sql($related_sql); + + return $r[0]['n']; + } + + return db_get_all_rows_sql($related_sql); + +} + + /** * Validates all events matching target filter. * diff --git a/pandora_console/include/javascript/pandora_events.js b/pandora_console/include/javascript/pandora_events.js index 9c9e62704a..86f101ab83 100644 --- a/pandora_console/include/javascript/pandora_events.js +++ b/pandora_console/include/javascript/pandora_events.js @@ -16,6 +16,12 @@ function show_event_dialog(event_id, group_rep, dialog_page, result) { var server_id = $("#hidden-server_id_" + event_id).val(); var childrens_ids = $("#hidden-childrens_ids").val(); + var inputs = $("#events_form :input"); + var values = {}; + inputs.each(function() { + values[this.name] = $(this).val(); + }); + // Metaconsole mode flag var meta = $("#hidden-meta").val(); @@ -38,7 +44,8 @@ function show_event_dialog(event_id, group_rep, dialog_page, result) { server_id: server_id, meta: meta, childrens_ids: childrens_ids, - history: history + history: history, + filter: values }, function(data) { $("#event_details_window")