diff --git a/pandora_console/godmode/events/event_edit_filter.php b/pandora_console/godmode/events/event_edit_filter.php index 2e7e009686..af086d55d7 100644 --- a/pandora_console/godmode/events/event_edit_filter.php +++ b/pandora_console/godmode/events/event_edit_filter.php @@ -442,8 +442,12 @@ $table->data[10][1] = html_print_select( true ); -$repeated_sel[0] = __('All events'); -$repeated_sel[1] = __('Group events'); +$repeated_sel = [ + EVENT_GROUP_REP_ALL => __('All events'), + EVENT_GROUP_REP_EVENTS => __('Group events'), + EVENT_GROUP_REP_AGENTS => __('Group agents'), + EVENT_GROUP_REP_EXTRAIDS => __('Group extra id'), +]; $table->data[11][0] = ''.__('Repeated').''; $table->data[11][1] = html_print_select( $repeated_sel, diff --git a/pandora_console/include/ajax/events.php b/pandora_console/include/ajax/events.php index 8b20e93736..5cb86d027e 100644 --- a/pandora_console/include/ajax/events.php +++ b/pandora_console/include/ajax/events.php @@ -90,7 +90,7 @@ $node_id = (int) get_parameter('node_id', 0); if ($get_comments === true) { $event = get_parameter('event', false); - $event_rep = get_parameter('event_rep', false); + $event_rep = (int) get_parameter('event_rep', 0); if ($event === false) { return __('Failed to retrieve comments'); } @@ -98,7 +98,7 @@ if ($get_comments === true) { $eventsGrouped = []; // Consider if the event is grouped. $whereGrouped = '1=1'; - if (isset($event_rep) === true && $event_rep > 0) { + if ($event_rep === EVENT_GROUP_REP_EVENTS) { // Default grouped message filtering (evento and estado). $whereGrouped = sprintf( '`evento` = "%s"', @@ -119,6 +119,11 @@ if ($get_comments === true) { (int) $event['id_agentmodule'] ); } + } else if ($event_rep === EVENT_GROUP_REP_EXTRAIDS) { + $whereGrouped = sprintf( + '`id_extra` = "%s"', + $event['id_extra'] + ); } else { $whereGrouped = sprintf('`id_evento` = %d', $event['id_evento']); } @@ -175,7 +180,7 @@ if ($delete_event === true) { $filter = get_parameter('filter', []); $id_evento = (int) get_parameter('id_evento', 0); $server_id = (int) get_parameter('server_id', 0); - $event_rep = get_parameter('event_rep', 0); + $event_rep = (int) get_parameter('event_rep', 0); try { if (is_metaconsole() === true @@ -228,7 +233,7 @@ if ($validate_event === true) { $filter = get_parameter('filter', []); $id_evento = (int) get_parameter('id_evento', 0); $server_id = (int) get_parameter('server_id', 0); - $event_rep = get_parameter('event_rep', 0); + $event_rep = (int) get_parameter('event_rep', 0); try { if (is_metaconsole() === true @@ -240,7 +245,7 @@ if ($validate_event === true) { if ($event_rep === 0) { // Disable group by when there're result is unique. - $filter['group_rep'] = 0; + $filter['group_rep'] = EVENT_GROUP_REP_ALL; } // Check acl. @@ -285,7 +290,7 @@ if ($in_process_event === true) { $filter = get_parameter('filter', []); $id_evento = (int) get_parameter('id_evento', 0); $server_id = (int) get_parameter('server_id', 0); - $event_rep = get_parameter('event_rep', 0); + $event_rep = (int) get_parameter('event_rep', 0); try { if (is_metaconsole() === true @@ -297,7 +302,7 @@ if ($in_process_event === true) { if ($event_rep === 0) { // Disable group by when there're result is unique. - $filter['group_rep'] = 0; + $filter['group_rep'] = EVENT_GROUP_REP_ALL; } // Check acl. @@ -466,7 +471,6 @@ if ($get_filter_values) { $event_filter = [ 'status' => EVENT_NO_VALIDATED, 'event_view_hr' => $config['event_view_hr'], - 'group_rep' => 1, 'tag_with' => [], 'tag_without' => [], 'history' => false, @@ -483,7 +487,7 @@ if ($get_filter_values) { 'time_to' => '', 'severity' => '', 'event_type' => '', - 'group_rep' => 0, + 'group_rep' => EVENT_GROUP_REP_ALL, 'id_group' => 0, 'id_group_filter' => 0, 'group_name' => 'All', @@ -2418,7 +2422,7 @@ if ($get_events_fired) { 'id_agent_module' => 0, 'pagination' => 0, 'id_user_ack' => 0, - 'group_rep' => 0, + 'group_rep' => EVENT_GROUP_REP_ALL, 'tag_with' => [], 'tag_without' => [], 'filter_only_alert' => -1, diff --git a/pandora_console/include/constants.php b/pandora_console/include/constants.php index 64be59b7aa..6688a91d78 100644 --- a/pandora_console/include/constants.php +++ b/pandora_console/include/constants.php @@ -45,6 +45,11 @@ define('EVENT_VALIDATE', 1); define('EVENT_PROCESS', 2); define('EVENT_NO_VALIDATED', 3); +// Events group by constants. +define('EVENT_GROUP_REP_ALL', 0); +define('EVENT_GROUP_REP_EVENTS', 1); +define('EVENT_GROUP_REP_AGENTS', 2); +define('EVENT_GROUP_REP_EXTRAIDS', 3); // Agents disabled status. define('AGENT_ENABLED', 0); diff --git a/pandora_console/include/functions_api.php b/pandora_console/include/functions_api.php index 90935bbc6d..c602bbe601 100644 --- a/pandora_console/include/functions_api.php +++ b/pandora_console/include/functions_api.php @@ -11246,7 +11246,7 @@ function get_events_with_user($trash1, $trash2, $other, $returnType, $user_in_db $id_user_ack = 0; $event_view_hr = 0; $tag = ''; - $group_rep = 0; + $group_rep = EVENT_GROUP_REP_ALL; $utimestamp_upper = 0; $utimestamp_bottom = 0; $id_alert_template = -1; @@ -11449,7 +11449,7 @@ function get_events_with_user($trash1, $trash2, $other, $returnType, $user_in_db $alert_join = ' INNER JOIN talert_template_modules ON '.$table_events.'.id_alert_am=talert_template_modules.id'; } - if ($group_rep == 0) { + if ($group_rep == EVENT_GROUP_REP_ALL) { if ($filter['total']) { $sql = 'SELECT COUNT(*) FROM '.$table_events.' @@ -15922,7 +15922,7 @@ function api_set_create_event_filter($name, $thrash1, $other, $thrash3) $id_user_ack = (in_array($other['data'][9], $users)) ? $other['data'][9] : 0; - $group_rep = ($other['data'][10] == 0 || $other['data'][10] == 1) ? $other['data'][10] : 0; + $group_rep = ($other['data'][10] == EVENT_GROUP_REP_ALL || $other['data'][10] == EVENT_GROUP_REP_EVENTS) ? $other['data'][10] : EVENT_GROUP_REP_ALL; $date_from = (preg_match('/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/', $other['data'][11])) ? $other['data'][11] : '0000-00-00'; @@ -16149,7 +16149,7 @@ function api_set_update_event_filter($id_event_filter, $thrash1, $other, $thrash break; case 11: - $values['group_rep'] = ($other['data'][11] == 0 || $other['data'][11] == 1) ? $other['data'][11] : 0; + $values['group_rep'] = ($other['data'][11] == EVENT_GROUP_REP_ALL || $other['data'][11] == EVENT_GROUP_REP_EVENTS) ? $other['data'][11] : EVENT_GROUP_REP_ALL; break; case 12: diff --git a/pandora_console/include/functions_events.php b/pandora_console/include/functions_events.php index 9e0a3650d6..3aa121ec6a 100644 --- a/pandora_console/include/functions_events.php +++ b/pandora_console/include/functions_events.php @@ -382,14 +382,14 @@ function events_delete($id_evento, $filter=null, $history=false, $force_node=fal } if (isset($filter) === false - || is_array($filter) === true + || is_array($filter) === false ) { - $filter = ['group_rep' => 0]; + $filter = ['group_rep' => EVENT_GROUP_REP_ALL]; } switch ($filter['group_rep']) { - case '0': - case '2': + case EVENT_GROUP_REP_ALL: + case EVENT_GROUP_REP_AGENTS: default: // No groups option direct update. $delete_sql = sprintf( @@ -399,7 +399,8 @@ function events_delete($id_evento, $filter=null, $history=false, $force_node=fal ); break; - case '1': + case EVENT_GROUP_REP_EVENTS: + case EVENT_GROUP_REP_EXTRAIDS: // Group by events. $sql = events_get_all( ['te.*'], @@ -418,8 +419,16 @@ function events_delete($id_evento, $filter=null, $history=false, $force_node=fal true ); - $target_ids = db_get_all_rows_sql( - sprintf( + if ((int) $filter['group_rep'] === EVENT_GROUP_REP_EXTRAIDS) { + $sql = sprintf( + 'SELECT tu.id_evento FROM tevento tu INNER JOIN ( %s ) tf + ON tu.id_extra = tf.id_extra + AND tf.max_id_evento = %d', + $sql, + $id_evento + ); + } else { + $sql = sprintf( 'SELECT tu.id_evento FROM tevento tu INNER JOIN ( %s ) tf ON tu.estado = tf.estado AND tu.evento = tf.evento @@ -428,8 +437,10 @@ function events_delete($id_evento, $filter=null, $history=false, $force_node=fal AND tf.max_id_evento = %d', $sql, $id_evento - ) - ); + ); + } + + $target_ids = db_get_all_rows_sql($sql); // Try to avoid deadlock while updating full set. if ($target_ids !== false && count($target_ids) > 0) { @@ -475,12 +486,12 @@ function events_update_status($id_evento, $status, $filter=null) } if (isset($filter) === false || is_array($filter) === false) { - $filter = ['group_rep' => 0]; + $filter = ['group_rep' => EVENT_GROUP_REP_ALL]; } switch ($filter['group_rep']) { - case '0': - case '2': + case EVENT_GROUP_REP_ALL: + case EVENT_GROUP_REP_AGENTS: default: // No groups option direct update. $update_sql = sprintf( @@ -492,7 +503,8 @@ function events_update_status($id_evento, $status, $filter=null) ); break; - case '1': + case EVENT_GROUP_REP_EVENTS: + case EVENT_GROUP_REP_EXTRAIDS: // Group by events. $sql = events_get_all( ['te.*'], @@ -511,8 +523,16 @@ function events_update_status($id_evento, $status, $filter=null) true ); - $target_ids = db_get_all_rows_sql( - sprintf( + if ((int) $filter['group_rep'] === EVENT_GROUP_REP_EXTRAIDS) { + $sql = sprintf( + 'SELECT tu.id_evento FROM tevento tu INNER JOIN ( %s ) tf + ON tu.id_extra = tf.id_extra + AND tf.max_id_evento = %d', + $sql, + $id_evento + ); + } else { + $sql = sprintf( 'SELECT tu.id_evento FROM tevento tu INNER JOIN ( %s ) tf ON tu.estado = tf.estado AND tu.evento = tf.evento @@ -521,8 +541,10 @@ function events_update_status($id_evento, $status, $filter=null) AND tf.max_id_evento = %d', $sql, $id_evento - ) - ); + ); + } + + $target_ids = db_get_all_rows_sql($sql); // Try to avoid deadlock while updating full set. if ($target_ids !== false && count($target_ids) > 0) { @@ -1367,7 +1389,10 @@ function events_get_all( // Order. $order_by = ''; if (isset($order, $sort_field) === true) { - if (isset($filter['group_rep']) === true && $filter['group_rep'] == 1) { + if (isset($filter['group_rep']) === true + && $filter['group_rep'] === EVENT_GROUP_REP_EVENTS + && $filter['group_rep'] === EVENT_GROUP_REP_EXTRAIDS + ) { $order_by = events_get_sql_order('MAX('.$sort_field.')', $order); } else { $order_by = events_get_sql_order($sort_field, $order); @@ -1401,22 +1426,22 @@ function events_get_all( $group_by = 'GROUP BY '; $tagente_join = 'LEFT'; if (isset($filter['group_rep']) === false) { - $filter['group_rep'] = 0; + $filter['group_rep'] = EVENT_GROUP_REP_ALL; } switch ($filter['group_rep']) { - case '0': + case EVENT_GROUP_REP_ALL: default: // All events. $group_by = ''; break; - case '1': + case EVENT_GROUP_REP_EVENTS: // Group by events. $group_by .= 'te.evento, te.id_agente, te.id_agentmodule'; break; - case '2': + case EVENT_GROUP_REP_AGENTS: // Group by agents. $tagente_join = 'INNER'; $group_by = ''; @@ -1430,6 +1455,11 @@ function events_get_all( ); } break; + + case EVENT_GROUP_REP_EXTRAIDS: + // Group by events. + $group_by .= 'te.id_extra'; + break; } $tgrupo_join = 'LEFT'; @@ -1516,7 +1546,9 @@ function events_get_all( } } - if ((int) $filter['group_rep'] === 1 && $count === false) { + if (((int) $filter['group_rep'] === EVENT_GROUP_REP_EVENTS + || (int) $filter['group_rep'] === EVENT_GROUP_REP_EXTRAIDS) && $count === false + ) { $sql = sprintf( 'SELECT %s %s @@ -1547,7 +1579,9 @@ function events_get_all( %s %s %s JOIN tgrupo tg - ON %s', + ON %s + %s + %s', join(',', $fields), $group_selects_trans, $tevento, @@ -1576,7 +1610,8 @@ function events_get_all( join(' ', $agent_join_filters), $tgrupo_join, join(' ', $tgrupo_join_filters), - join(' ', $sql_filters) + join(' ', $sql_filters), + $order_by ); } else { $sql = sprintf( @@ -2900,9 +2935,9 @@ function events_get_agent( // Group by agent. if ((bool) $show_summary_group === true) { - $filters['group_rep'] = 1; + $filters['group_rep'] = EVENT_GROUP_REP_EVENTS; } else { - $filters['group_rep'] = 2; + $filters['group_rep'] = EVENT_GROUP_REP_AGENTS; } $events = Event::search( @@ -5153,7 +5188,7 @@ function events_get_count_events_validated_by_user($data) * * @return string SQL. */ -function events_get_sql_order($sort_field='timestamp', $sort='DESC', $group_rep=0, $only_fields=false) +function events_get_sql_order($sort_field='timestamp', $sort='DESC', $group_rep=EVENT_GROUP_REP_ALL, $only_fields=false) { $sort_field_translated = $sort_field; switch ($sort_field) { @@ -5174,7 +5209,7 @@ function events_get_sql_order($sort_field='timestamp', $sort='DESC', $group_rep= break; case 'timestamp': - $sort_field_translated = ($group_rep == 0) ? 'timestamp' : 'timestamp_last'; + $sort_field_translated = ($group_rep == EVENT_GROUP_REP_ALL) ? 'timestamp' : 'timestamp_last'; break; case 'user_id': @@ -5201,6 +5236,14 @@ function events_get_sql_order($sort_field='timestamp', $sort='DESC', $group_rep= $sort_field_translated = 'id_extra'; break; + case 'agent_name': + $sort_field_translated = 'ta.nombre'; + break; + + case 'module_custom_id': + $sort_field_translated = 'am.custom_id'; + break; + default: $sort_field_translated = $sort_field; break; diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index ab1e64cfcf..54e0173fa2 100755 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -4011,7 +4011,7 @@ function reporting_groups_nodes($content) } // Grouped. - $filters['group_rep'] = 1; + $filters['group_rep'] = EVENT_GROUP_REP_EVENTS; $events = Event::search( [ diff --git a/pandora_console/include/functions_ui.php b/pandora_console/include/functions_ui.php index 1e9d9f8dd7..6ae90f29ef 100755 --- a/pandora_console/include/functions_ui.php +++ b/pandora_console/include/functions_ui.php @@ -6513,7 +6513,7 @@ function ui_print_breadcrums($tab_name) /** * Show last comment * - * @param array $comments array with comments + * @param string $comments String with comments. * * @return string HTML string with the last comment of the events. */ @@ -6537,31 +6537,45 @@ function ui_print_comments($comments) foreach ($comments_array as $comm) { // Show the comments more recent first. if (is_array($comm)) { - $last_comment[] = array_reverse($comm); + $order_utimestamp = array_reduce( + $comm, + function ($carry, $item) { + $carry[$item['utimestamp']] = $item; + return $carry; + } + ); + + $key_max_utimestamp = max(array_keys($order_utimestamp)); + + $last_comment = $order_utimestamp[$key_max_utimestamp]; } } + if (empty($last_comment) === true) { + return ''; + } + // Only show the last comment. If commment its too long,the comment will short with ... // If $config['prominent_time'] is timestamp the date show Month, day, hour and minutes. // Else show comments hours ago - if ($last_comment[0][0]['action'] != 'Added comment') { - $last_comment[0][0]['comment'] = $last_comment[0][0]['action']; + if ($last_comment['action'] != 'Added comment') { + $last_comment['comment'] = $last_comment['action']; } - $short_comment = substr($last_comment[0][0]['comment'], 0, 20); + $short_comment = substr($last_comment['comment'], 0, 20); if ($config['prominent_time'] == 'timestamp') { - $comentario = ''.date($config['date_format'], $last_comment[0][0]['utimestamp']).' ('.$last_comment[0][0]['id_user'].'): '.$last_comment[0][0]['comment'].''; + $comentario = ''.date($config['date_format'], $last_comment['utimestamp']).' ('.$last_comment['id_user'].'): '.$last_comment['comment'].''; if (strlen($comentario) > '200px') { - $comentario = ''.date($config['date_format'], $last_comment[0][0]['utimestamp']).' ('.$last_comment[0][0]['id_user'].'): '.$short_comment.'...'; + $comentario = ''.date($config['date_format'], $last_comment['utimestamp']).' ('.$last_comment['id_user'].'): '.$short_comment.'...'; } } else { - $rest_time = (time() - $last_comment[0][0]['utimestamp']); + $rest_time = (time() - $last_comment['utimestamp']); $time_last = (($rest_time / 60) / 60); - $comentario = ''.number_format($time_last, 0).'  Hours  ('.$last_comment[0][0]['id_user'].'): '.$last_comment[0][0]['comment'].''; + $comentario = ''.number_format($time_last, 0).'  Hours  ('.$last_comment['id_user'].'): '.$last_comment['comment'].''; if (strlen($comentario) > '200px') { - $comentario = ''.number_format($time_last, 0).'  Hours  ('.$last_comment[0][0]['id_user'].'): '.$short_comment.'...'; + $comentario = ''.number_format($time_last, 0).'  Hours  ('.$last_comment['id_user'].'): '.$short_comment.'...'; } } diff --git a/pandora_console/mobile/operation/events.php b/pandora_console/mobile/operation/events.php index 360f2710d6..50e9aab8ba 100644 --- a/pandora_console/mobile/operation/events.php +++ b/pandora_console/mobile/operation/events.php @@ -357,10 +357,10 @@ class Events ); if (isset($group_rep) === false) { - $group_rep = 0; + $group_rep = EVENT_GROUP_REP_ALL; } - if ((int) $group_rep !== 0) { + if ((int) $group_rep !== EVENT_GROUP_REP_ALL) { if ($event['event_rep'] <= 1) { $event['event_repeated'] = ''.__('No').''; } else { @@ -1068,7 +1068,7 @@ class Events $filters['id_agent'] = $this->id_agent; } - $filters['group_rep'] = 1; + $filters['group_rep'] = EVENT_GROUP_REP_EVENTS; if (isset($this->limit) === true && $this->limit !== -1 diff --git a/pandora_console/operation/events/events.php b/pandora_console/operation/events/events.php index cf7c6b9a54..bd7109c635 100644 --- a/pandora_console/operation/events/events.php +++ b/pandora_console/operation/events/events.php @@ -84,7 +84,7 @@ ui_require_javascript_file('pandora_events'); $default_filter = [ 'status' => EVENT_NO_VALIDATED, 'event_view_hr' => $config['event_view_hr'], - 'group_rep' => 1, + 'group_rep' => EVENT_GROUP_REP_EVENTS, 'tag_with' => [], 'tag_without' => [], 'history' => false, @@ -360,6 +360,10 @@ if (is_ajax() === true) { $order['field'] = 'agent_name'; break; + case 'if(te.ack_utimestamp > 0, from_unixtime(te.ack_utimestamp),"") as ack_utimestamp': + $order['field'] = 'ack_utimestamp'; + break; + default: $order['field'] = $field; break; @@ -1665,9 +1669,10 @@ $inputs[] = $in; // Duplicates group { events | agents }. $data = html_print_select( [ - 0 => __('All events'), - 1 => __('Group events'), - 2 => __('Group agents'), + EVENT_GROUP_REP_ALL => __('All events'), + EVENT_GROUP_REP_EVENTS => __('Group events'), + EVENT_GROUP_REP_AGENTS => __('Group agents'), + EVENT_GROUP_REP_EXTRAIDS => __('Group extra id'), ], 'group_rep', $group_rep, @@ -2300,12 +2305,14 @@ try { $active_filters_div .= '
'; $active_filters_div .= '
'.__('Duplicated').'
'; $active_filters_div .= '
'; - if ($group_rep == 0) { + if ($group_rep == EVENT_GROUP_REP_ALL) { $active_filters_div .= __('All events.'); - } else if ($group_rep == 1) { + } else if ($group_rep == EVENT_GROUP_REP_EVENTS) { $active_filters_div .= __('Group events'); - } else if ($group_rep == 2) { + } else if ($group_rep == EVENT_GROUP_REP_AGENTS) { $active_filters_div .= __('Group agents.'); + } else if ($group_rep == EVENT_GROUP_REP_EXTRAIDS) { + $active_filters_div .= __('Group extra id.'); } $active_filters_div .= '
'; diff --git a/pandora_console/operation/menu.php b/pandora_console/operation/menu.php index fb303dd3fa..326eecf73f 100644 --- a/pandora_console/operation/menu.php +++ b/pandora_console/operation/menu.php @@ -410,7 +410,7 @@ if ($access_console_node === true) { $user_event_filter = [ 'status' => EVENT_NO_VALIDATED, 'event_view_hr' => $config['event_view_hr'], - 'group_rep' => 1, + 'group_rep' => EVENT_GROUP_REP_EVENTS, 'tag_with' => [], 'tag_without' => [], 'history' => false,