From 200750f90b2f2bc5e9353e323893a5566f58c77f Mon Sep 17 00:00:00 2001 From: daniel Date: Fri, 7 Jul 2023 12:53:14 +0200 Subject: [PATCH 1/8] change events user_comment new table tevent_comment pandora_enterprise#11387 --- pandora_console/include/ajax/events.php | 68 +-- pandora_console/include/functions_api.php | 2 + pandora_console/include/functions_events.php | 386 +++++++----------- pandora_console/include/functions_ui.php | 47 +-- .../lib/Dashboard/Widgets/events_list.php | 6 +- pandora_console/mobile/include/style/main.css | 4 + pandora_console/mobile/operation/events.php | 20 +- .../operation/events/events.build_query.php | 4 - pandora_console/operation/events/events.php | 50 +-- .../operation/events/events_rss.php | 2 - .../operation/events/export_csv.php | 3 - pandora_console/pandoradb.sql | 15 +- pandora_server/lib/PandoraFMS/Core.pm | 16 +- pandora_server/util/pandora_manage.pl | 39 +- 14 files changed, 235 insertions(+), 427 deletions(-) diff --git a/pandora_console/include/ajax/events.php b/pandora_console/include/ajax/events.php index 666d23d244..7237cbbefb 100644 --- a/pandora_console/include/ajax/events.php +++ b/pandora_console/include/ajax/events.php @@ -100,76 +100,10 @@ if ($get_comments === true) { return __('Failed to retrieve comments'); } - $eventsGrouped = []; - // Consider if the event is grouped. - $whereGrouped = '1=1'; - if ($group_rep === EVENT_GROUP_REP_EVENTS && $event_rep > 1) { - // Default grouped message filtering (evento and estado). - $whereGrouped = sprintf( - '`evento` = "%s"', - $event['evento'] - ); - - // If id_agente is reported, filter the messages by them as well. - if ((int) $event['id_agente'] > 0) { - $whereGrouped .= sprintf( - ' AND `id_agente` = %d', - (int) $event['id_agente'] - ); - } - - if ((int) $event['id_agentmodule'] > 0) { - $whereGrouped .= sprintf( - ' AND `id_agentmodule` = %d', - (int) $event['id_agentmodule'] - ); - } - } else if ($group_rep === EVENT_GROUP_REP_EXTRAIDS) { - $whereGrouped = sprintf( - '`id_extra` = "%s"', - io_safe_output($event['id_extra']) - ); - } else { - $whereGrouped = sprintf('`id_evento` = %d', $event['id_evento']); - } - - try { - if (is_metaconsole() === true - && $event['server_id'] > 0 - ) { - $node = new Node($event['server_id']); - $node->connect(); - } - - $sql = sprintf( - 'SELECT `user_comment` - FROM tevento - WHERE %s', - $whereGrouped - ); - - // Get grouped comments. - $eventsGrouped = db_get_all_rows_sql($sql); - } catch (\Exception $e) { - // Unexistent agent. - if (is_metaconsole() === true - && $event['server_id'] > 0 - ) { - $node->disconnect(); - } - - $eventsGrouped = []; - } finally { - if (is_metaconsole() === true - && $event['server_id'] > 0 - ) { - $node->disconnect(); - } - } + $eventsGrouped = event_get_comment($event, $group_rep, $event_rep); // End of get_comments. echo events_page_comments($event, true, $eventsGrouped); - return; } diff --git a/pandora_console/include/functions_api.php b/pandora_console/include/functions_api.php index 77b2f9e3fa..5810df39dc 100644 --- a/pandora_console/include/functions_api.php +++ b/pandora_console/include/functions_api.php @@ -15744,6 +15744,8 @@ function api_get_cluster_items($cluster_id) */ function api_set_create_event_filter($name, $thrash1, $other, $thrash3) { + global $config; + if ($name == '') { returnError( 'The event filter could not be created. Event filter name cannot be left blank.' diff --git a/pandora_console/include/functions_events.php b/pandora_console/include/functions_events.php index 3a6128e234..8498584e69 100644 --- a/pandora_console/include/functions_events.php +++ b/pandora_console/include/functions_events.php @@ -749,7 +749,7 @@ function events_get_all( if (isset($from) === false) { if (isset($filter['event_view_hr']) === true && ($filter['event_view_hr'] > 0)) { $sql_filters[] = sprintf( - ' AND utimestamp > UNIX_TIMESTAMP(now() - INTERVAL %d HOUR) ', + ' AND te.utimestamp > UNIX_TIMESTAMP(now() - INTERVAL %d HOUR) ', $filter['event_view_hr'] ); } @@ -1069,7 +1069,6 @@ function events_get_all( $array_search = [ 'te.id_evento', 'lower(te.evento)', - 'lower(te.user_comment)', 'lower(te.id_extra)', 'lower(te.source)', 'lower('.$custom_data_search.')', @@ -1106,7 +1105,6 @@ function events_get_all( ' AND (lower(ta.alias) not like lower("%%%s%%") AND te.id_evento not like "%%%s%%" AND lower(te.evento) not like lower("%%%s%%") - AND lower(te.user_comment) not like lower("%%%s%%") AND lower(te.id_extra) not like lower("%%%s%%") AND lower(te.source) not like lower("%%%s%%") )', array_fill(0, 6, $filter['search_exclude']) @@ -1122,16 +1120,13 @@ function events_get_all( } // User comment. + $event_comment_join = ''; if (empty($filter['user_comment']) === false) { - // For filter field. + $event_comment_join = 'INNER JOIN tevent_comment ON te.id_evento = tevent_comment.id_event'; $sql_filters[] = sprintf( - ' AND lower(te.user_comment) like lower("%%%s%%") ', - io_safe_input($filter['user_comment']) - ); - - // For show comments on event details. - $sql_filters[] = sprintf( - ' OR lower(te.user_comment) like lower("%%%s%%") ', + ' AND (lower(tevent_comment.comment) like lower("%%%s%%") + OR lower(tevent_comment.comment) like lower("%%%s%%"))', + io_safe_input($filter['user_comment']), $filter['user_comment'] ); } @@ -1455,7 +1450,7 @@ function events_get_all( ' LIMIT %d', $config['max_number_of_events_per_node'] ); - } else if (isset($limit, $offset) === true && $limit > 0) { + } else if (isset($limit, $offset) === true && empty($limit) === false && $limit > 0) { $pagination = sprintf(' LIMIT %d OFFSET %d', $limit, $offset); } @@ -1552,36 +1547,20 @@ function events_get_all( $group_selects = ''; if ($group_by != '') { if ($count === false) { - $idx = array_search('te.user_comment', $fields); - if ($idx !== false) { - unset($fields[$idx]); - } - - db_process_sql('SET group_concat_max_len = 9999999'); - $group_selects = sprintf( ',COUNT(id_evento) AS event_rep, - %s - MAX(utimestamp) as timestamp_last, - MIN(utimestamp) as timestamp_first, - MAX(id_evento) as max_id_evento', - ($idx !== false) ? 'GROUP_CONCAT(DISTINCT user_comment SEPARATOR "
") AS comments,' : '' + MAX(te.utimestamp) as timestamp_last, + MIN(te.utimestamp) as timestamp_first, + MAX(id_evento) as max_id_evento' ); $group_selects_trans = sprintf( ',tmax_event.event_rep, - %s tmax_event.timestamp_last, tmax_event.timestamp_first, - tmax_event.max_id_evento', - ($idx !== false) ? 'tmax_event.comments,' : '' + tmax_event.max_id_evento' ); } - } else { - $idx = array_search('te.user_comment', $fields); - if ($idx !== false) { - $fields[$idx] = 'te.user_comment AS comments'; - } } if (((int) $filter['group_rep'] === EVENT_GROUP_REP_EVENTS @@ -1596,11 +1575,12 @@ function events_get_all( FROM %s %s %s + %s %s JOIN %s ta - ON ta.%s = te.id_agente + ON ta.%s = te.id_agente %s %s JOIN tgrupo tg - ON %s + ON %s WHERE 1=1 %s %s @@ -1611,6 +1591,7 @@ function events_get_all( ON te.id_evento = tmax_event.max_id_evento %s %s + %s %s JOIN %s ta ON ta.%s = te.id_agente %s @@ -1625,6 +1606,7 @@ function events_get_all( $tevento, $event_lj, $agentmodule_join, + $event_comment_join, $tagente_join, $tagente_table, $tagente_field, @@ -1638,6 +1620,7 @@ function events_get_all( $having, $event_lj, $agentmodule_join, + $event_comment_join, $tagente_join, $tagente_table, $tagente_field, @@ -1654,6 +1637,7 @@ function events_get_all( FROM %s %s %s + %s %s JOIN %s ta ON ta.%s = te.id_agente %s @@ -1671,6 +1655,7 @@ function events_get_all( $tevento, $event_lj, $agentmodule_join, + $event_comment_join, $tagente_join, $tagente_table, $tagente_field, @@ -2238,91 +2223,18 @@ function events_comment( $first_event = reset($id_event); } - $sql = sprintf( - 'SELECT user_comment - FROM tevento - WHERE id_evento = %d', - $first_event + // Update comment. + $ret = db_process_sql_insert( + 'tevent_comment', + [ + 'id_event' => $first_event, + 'comment' => $comment, + 'action' => $action, + 'utimestamp' => time(), + 'id_user' => $config['id_user'], + ], ); - $event_comments = db_get_all_rows_sql($sql); - $event_comments_array = []; - - if ($event_comments[0]['user_comment'] == '') { - $comments_format = 'new'; - } else { - // If comments are not stored in json, the format is old. - $event_comments[0]['user_comment'] = str_replace( - [ - "\n", - ' ', - ], - '
', - $event_comments[0]['user_comment'] - ); - $event_comments_array = json_decode($event_comments[0]['user_comment']); - - if (empty($event_comments_array) === true) { - $comments_format = 'old'; - } else { - $comments_format = 'new'; - } - } - - switch ($comments_format) { - case 'new': - $comment_for_json['comment'] = io_safe_input($comment); - $comment_for_json['action'] = $action; - $comment_for_json['id_user'] = $config['id_user']; - $comment_for_json['utimestamp'] = time(); - $comment_for_json['event_id'] = $first_event; - - $event_comments_array[] = $comment_for_json; - - $event_comments = io_json_mb_encode($event_comments_array); - - // Update comment. - $ret = db_process_sql_update( - 'tevento', - ['user_comment' => $event_comments], - ['id_evento' => implode(',', $id_event)] - ); - break; - - case 'old': - // Give old ugly format to comment. - // Change this method for aux table or json. - $comment = str_replace(["\r\n", "\r", "\n"], '
', $comment); - - if ($comment !== '') { - $commentbox = '
'.io_safe_input($comment).'
'; - } else { - $commentbox = ''; - } - - // Don't translate 'by' word because if multiple users with - // different languages make comments in the same console - // will be a mess. - $comment = '-- '.$action.' by '.$config['id_user'].' ['.date($config['date_format']).'] --
'.$commentbox.'
'; - - // Update comment. - $sql_validation = sprintf( - 'UPDATE %s - SET user_comment = concat("%s", user_comment) - WHERE id_evento in (%s)', - 'tevento', - $comment, - implode(',', $id_event) - ); - - $ret = db_process_sql($sql_validation); - break; - - default: - // Ignore. - break; - } - if (($ret === false) || ($ret === 0)) { return false; } @@ -5059,8 +4971,12 @@ function events_page_general($event) } $data[1] = $user_ack.' ( '; + // hd($config['date_format'], true); + // hd($event['ack_utimestamp_raw'], true); + // TODO: mirar en el manage y en la api que este ack de venir vacio lo herede del anterior que hubiera. if ($event['ack_utimestamp_raw'] !== false && $event['ack_utimestamp_raw'] !== 'false' + && empty($event['ack_utimestamp_raw']) === false ) { $data[1] .= date( $config['date_format'], @@ -5227,12 +5143,7 @@ function events_page_comments($event, $ajax=false, $groupedComments=[]) $table_comments->head = []; $table_comments->class = 'table_modal_alternate'; - if (isset($event['user_comment']) === false) { - $event['user_comment'] = ''; - } - - $comments = (empty($groupedComments) === true) ? $event['user_comment'] : $groupedComments; - + $comments = $groupedComments; if (empty($comments) === true) { $table_comments->style[0] = 'text-align:left;'; $table_comments->colspan[0][0] = 2; @@ -5241,49 +5152,7 @@ function events_page_comments($event, $ajax=false, $groupedComments=[]) $table_comments->data[] = $data; } else { if (is_array($comments) === true) { - $comments_array = []; - foreach ($comments as $comm) { - if (empty($comm) === true) { - continue; - } - - // If exists user_comments, come from grouped events and must be handled like this. - if (isset($comm['user_comment']) === true) { - $comm = $comm['user_comment']; - } - - $comm = str_replace(["\n", ' '], '
', $comm); - - $comments_array[] = io_safe_output(json_decode($comm, true)); - } - - // Plain comments. Can be improved. - $sortedCommentsArray = []; - foreach ($comments_array as $comm) { - if (isset($comm) === true - && empty($comm) === false - ) { - foreach ($comm as $subComm) { - $sortedCommentsArray[] = $subComm; - } - } - } - - // Sorting the comments by utimestamp (newer is first). - usort( - $sortedCommentsArray, - function ($a, $b) { - if ($a['utimestamp'] == $b['utimestamp']) { - return 0; - } - - return ($a['utimestamp'] > $b['utimestamp']) ? -1 : 1; - } - ); - - // Clean the unsorted comments and return it to the original array. - $comments_array = []; - $comments_array[] = $sortedCommentsArray; + $comments_array = $comments; } else { $comments = str_replace(["\n", ' '], '
', $comments); // If comments are not stored in json, the format is old. @@ -5291,73 +5160,23 @@ function events_page_comments($event, $ajax=false, $groupedComments=[]) } foreach ($comments_array as $comm) { - $comments_format = (empty($comm) === true && is_array($comments) === false) ? 'old' : 'new'; + $eventIdExplanation = (empty($groupedComments) === false) ? sprintf(' (#%d)', $comm['id_event']) : ''; + $data[0] = sprintf( + '%s %s %s%s', + $comm['action'], + __('by'), + get_user_fullname(io_safe_input($comm['id_user'])).' ('.io_safe_input($comm['id_user']).')', + $eventIdExplanation + ); - switch ($comments_format) { - case 'new': - foreach ($comm as $c) { - $eventIdExplanation = (empty($groupedComments) === false) ? sprintf(' (#%d)', $c['event_id']) : ''; + $data[0] .= sprintf( + '

%s', + date($config['date_format'], $comm['utimestamp']) + ); - $data[0] = sprintf( - '%s %s %s%s', - $c['action'], - __('by'), - get_user_fullname(io_safe_input($c['id_user'])).' ('.io_safe_input($c['id_user']).')', - $eventIdExplanation - ); + $data[1] = '

'.stripslashes(str_replace(['\n', '\r'], '
', $comm['comment'])).'

'; - $data[0] .= sprintf( - '

%s', - date($config['date_format'], $c['utimestamp']) - ); - - $data[1] = '

'.stripslashes(str_replace(['\n', '\r'], '
', $c['comment'])).'

'; - - $table_comments->data[] = $data; - } - break; - - case 'old': - $comm = explode('
', $comments); - - // Split comments and put in table. - $col = 0; - $data = []; - - foreach ($comm as $c) { - switch ($col) { - case 0: - $row_text = preg_replace('/\s*--\s*/', '', $c); - $row_text = preg_replace('/\<\/b\>/', '', $row_text); - $row_text = preg_replace('/\[/', '

[', $row_text); - $row_text = preg_replace('/[\[|\]]/', '', $row_text); - break; - - case 1: - $row_text = preg_replace("/[\r\n|\r|\n]/", '
', io_safe_output(strip_tags($c))); - break; - - default: - // Ignore. - break; - } - - $data[$col] = $row_text; - - $col++; - - if ($col == 2) { - $col = 0; - $table_comments->data[] = $data; - $data = []; - } - } - break; - - default: - // Ignore. - break; - } + $table_comments->data[] = $data; } } @@ -5540,7 +5359,7 @@ function events_get_sql_order($sort_field='timestamp', $sort='DESC', $group_rep= break; case 'comment': - $sort_field_translated = 'user_comment'; + $sort_field_translated = 'tevent_comment.comment'; break; case 'extra_id': @@ -6112,3 +5931,108 @@ function get_count_event_criticity( return db_get_all_rows_sql($sql_meta); } + + +/** + * Comments for this events. + * + * @param array $event Info event. + * @param integer $mode Mode group by. + * @param integer $event_rep Events. + * + * @return array Comments. + */ +function event_get_comment($event, $mode, $event_rep) +{ + $eventsGrouped = []; + // Consider if the event is grouped. + $whereGrouped = '1=1'; + if ($mode === EVENT_GROUP_REP_EVENTS && $event_rep > 1) { + // Default grouped message filtering (evento and estado). + $whereGrouped = sprintf( + '`tevento`.`evento` = "%s"', + $event['evento'] + ); + + // If id_agente is reported, filter the messages by them as well. + if ((int) $event['id_agente'] > 0) { + $whereGrouped .= sprintf( + ' AND `tevento`.`id_agente` = %d', + (int) $event['id_agente'] + ); + } + + if ((int) $event['id_agentmodule'] > 0) { + $whereGrouped .= sprintf( + ' AND `tevento`.`id_agentmodule` = %d', + (int) $event['id_agentmodule'] + ); + } + } else if ($mode === EVENT_GROUP_REP_EXTRAIDS) { + $whereGrouped = sprintf( + '`tevento`.`id_extra` = "%s"', + io_safe_output($event['id_extra']) + ); + } else { + $whereGrouped = sprintf('`tevento`.`id_evento` = %d', $event['id_evento']); + } + + try { + if (is_metaconsole() === true + && $event['server_id'] > 0 + ) { + $node = new Node($event['server_id']); + $node->connect(); + } + + $sql = sprintf( + 'SELECT tevent_comment.* + FROM tevento + INNER JOIN tevent_comment + ON tevento.id_evento = tevent_comment.id_event + WHERE %s + ORDER BY tevent_comment.utimestamp DESC', + $whereGrouped + ); + + // Get grouped comments. + $eventsGrouped = db_get_all_rows_sql($sql); + } catch (\Exception $e) { + // Unexistent agent. + if (is_metaconsole() === true + && $event['server_id'] > 0 + ) { + $node->disconnect(); + } + + $eventsGrouped = []; + } finally { + if (is_metaconsole() === true + && $event['server_id'] > 0 + ) { + $node->disconnect(); + } + } + + return $eventsGrouped; +} + + +/** + * Last comment for this event. + * + * @param array $event Info event. + * @param integer $mode Mode group by. + * @param integer $event_rep Events. + * + * @return string Comment. + */ +function event_get_last_comment($event, $mode, $event_rep) +{ + $comments = event_get_comment($event, (int) $mode, $event_rep); + if (empty($comments) === false) { + return $comments[0]; + } + + return ''; +} diff --git a/pandora_console/include/functions_ui.php b/pandora_console/include/functions_ui.php index f50f2d56e4..b7018ac43d 100755 --- a/pandora_console/include/functions_ui.php +++ b/pandora_console/include/functions_ui.php @@ -7302,63 +7302,36 @@ function ui_print_breadcrums($tab_name) * * @return string HTML string with the last comment of the events. */ -function ui_print_comments($comments) +function ui_print_comments($comment) { global $config; - $comments = explode('
', $comments); - $comments = str_replace(["\n", ' '], '
', $comments); - if (is_array($comments)) { - foreach ($comments as $comm) { - if (empty($comm)) { - continue; - } - - $comments_array[] = io_safe_output(json_decode($comm, true)); - } - } - - $order_utimestamp = array_reduce( - $comments_array, - function ($carry, $item) { - foreach ($item as $k => $v) { - $carry[$v['utimestamp']] = $v; - } - - return $carry; - } - ); - - $key_max_utimestamp = max(array_keys($order_utimestamp)); - - $last_comment = $order_utimestamp[$key_max_utimestamp]; - - if (empty($last_comment) === true) { + if (empty($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['action'] != 'Added comment') { - $last_comment['comment'] = $last_comment['action']; + if ($comment['action'] != 'Added comment') { + $comment['comment'] = $comment['action']; } - $short_comment = substr($last_comment['comment'], 0, 20); + $short_comment = substr($comment['comment'], 0, 20); if ($config['prominent_time'] == 'timestamp') { - $comentario = ''.date($config['date_format'], $last_comment['utimestamp']).' ('.$last_comment['id_user'].'): '.$last_comment['comment'].''; + $comentario = ''.date($config['date_format'], $comment['utimestamp']).' ('.$comment['id_user'].'): '.$comment['comment'].''; if (strlen($comentario) > '200px') { - $comentario = ''.date($config['date_format'], $last_comment['utimestamp']).' ('.$last_comment['id_user'].'): '.$short_comment.'...'; + $comentario = ''.date($config['date_format'], $comment['utimestamp']).' ('.$comment['id_user'].'): '.$short_comment.'...'; } } else { - $rest_time = (time() - $last_comment['utimestamp']); + $rest_time = (time() - $comment['utimestamp']); $time_last = (($rest_time / 60) / 60); - $comentario = ''.number_format($time_last, 0, $config['decimal_separator'], ($config['thousand_separator'] ?? ',')).'  Hours  ('.$last_comment['id_user'].'): '.$last_comment['comment'].''; + $comentario = ''.number_format($time_last, 0, $config['decimal_separator'], ($config['thousand_separator'] ?? ',')).'  Hours  ('.$comment['id_user'].'): '.$comment['comment'].''; if (strlen($comentario) > '200px') { - $comentario = ''.number_format($time_last, 0, $config['decimal_separator'], ($config['thousand_separator'] ?? ',')).'  Hours  ('.$last_comment['id_user'].'): '.$short_comment.'...'; + $comentario = ''.number_format($time_last, 0, $config['decimal_separator'], ($config['thousand_separator'] ?? ',')).'  Hours  ('.$comment['id_user'].'): '.$short_comment.'...'; } } diff --git a/pandora_console/include/lib/Dashboard/Widgets/events_list.php b/pandora_console/include/lib/Dashboard/Widgets/events_list.php index adc9b3234e..ad9725825d 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/events_list.php +++ b/pandora_console/include/lib/Dashboard/Widgets/events_list.php @@ -528,7 +528,7 @@ class EventsListWidget extends Widget $values['eventType'] = \get_parameter('eventType', 0); $values['maxHours'] = \get_parameter('maxHours', 8); - $values['limit'] = \get_parameter('limit', 20); + $values['limit'] = (int) \get_parameter('limit', 20); $values['eventStatus'] = \get_parameter('eventStatus', -1); $values['severity'] = \get_parameter_switch('severity', -1); $values['groupId'] = \get_parameter_switch('groupId', []); @@ -708,6 +708,10 @@ class EventsListWidget extends Widget $hash = get_parameter('auth_hash', ''); $id_user = get_parameter('id_user', ''); + if ($this->values['limit'] === 'null') { + $this->values['limit'] = $config['block_size']; + } + // Print datatable. $output .= ui_print_datatable( [ diff --git a/pandora_console/mobile/include/style/main.css b/pandora_console/mobile/include/style/main.css index 9ed5784026..d27ff6db4c 100755 --- a/pandora_console/mobile/include/style/main.css +++ b/pandora_console/mobile/include/style/main.css @@ -496,6 +496,10 @@ table.event_details td.cell_event_name { font-size: 14px; } +table.event_details td.cell_event_comments { + height: auto; +} + #validate_button { margin: 10px auto; padding: 0; diff --git a/pandora_console/mobile/operation/events.php b/pandora_console/mobile/operation/events.php index 681de8445f..c03516f2d6 100644 --- a/pandora_console/mobile/operation/events.php +++ b/pandora_console/mobile/operation/events.php @@ -485,22 +485,16 @@ class Events $event['tags'] = ''.__('N/A').''; } - $event_comments = db_get_value( - 'user_comment', - 'tevento', - 'id_evento', - $id_event + $event_comments_array = db_get_all_rows_sql( + sprintf( + 'SELECT * FROM tevent_comment where id_event = %d', + $id_event + ) ); - $event_comments_array = []; - $event_comments_array = json_decode( - $event_comments, - true - ); - // Support for new format only. if (empty($event_comments_array) === true) { $comment = ''.__('N/A').''; } else { - $comment = ''; + $comment = '
'; $event_comments_array = array_reverse( $event_comments_array ); @@ -521,6 +515,8 @@ class Events ); $comment .= '
'.$c['comment'].'
'; } + + $comment .= '
'; } $event['comments'] = $comment; diff --git a/pandora_console/operation/events/events.build_query.php b/pandora_console/operation/events/events.build_query.php index f7744056bd..103d65f85c 100755 --- a/pandora_console/operation/events/events.build_query.php +++ b/pandora_console/operation/events/events.build_query.php @@ -223,10 +223,6 @@ if ($id_extra != '') { $sql_post .= " AND id_extra LIKE '%$id_extra%'"; } -if ($user_comment != '') { - $sql_post .= " AND user_comment LIKE '%$user_comment%'"; -} - if ($source != '') { $sql_post .= " AND source LIKE '%$source%'"; } diff --git a/pandora_console/operation/events/events.php b/pandora_console/operation/events/events.php index 696a85d40c..c1b930b2e3 100644 --- a/pandora_console/operation/events/events.php +++ b/pandora_console/operation/events/events.php @@ -330,7 +330,7 @@ if (is_ajax() === true) { $groupRecursion = (bool) get_parameter('groupRecursion', false); // Datatables offset, limit. - $start = get_parameter('start', 0); + $start = (int) get_parameter('start', 0); $length = get_parameter( 'length', $config['block_size'] @@ -368,13 +368,6 @@ if (is_ajax() === true) { 'ta.direccion', ]; - if (strpos($config['event_fields'], 'user_comment') !== false - || empty($user_comment) === false - || empty($search) === false - ) { - $fields[] = 'te.user_comment'; - } - $order = get_datatable_order(true); if (is_array($order) === true && $order['field'] === 'mini_severity') { @@ -462,7 +455,7 @@ if (is_ajax() === true) { $data = array_reduce( $events, - function ($carry, $item) use ($table_id, &$redirection_form_id) { + function ($carry, $item) use ($table_id, &$redirection_form_id, $filter) { global $config; $tmp = (object) $item; @@ -504,10 +497,6 @@ if (is_ajax() === true) { $tmp->module_name = io_safe_output($tmp->module_name); } - if (empty($tmp->comments) === false) { - $tmp->comments = ui_print_comments($tmp->comments); - } - // Show last event. if (isset($tmp->max_id_evento) === true && $tmp->max_id_evento !== $tmp->id_evento @@ -582,25 +571,13 @@ if (is_ajax() === true) { $tmp->b64 = base64_encode(json_encode($tmp)); - // Show comments events. - if (empty($tmp->comments) === false) { - $tmp->user_comment = $tmp->comments; - if ($tmp->comments !== 'undefined' && strlen($tmp->comments) > 80) { - $tmp->user_comment .= '  '; - $tmp->user_comment .= ''; // Grouped events. + if ((int) $filter['group_rep'] === EVENT_GROUP_REP_EXTRAIDS) { + $evn .= '(el contador de extraid iguales) '; + } + if (isset($tmp->event_rep) === true && $tmp->event_rep > 1) { $evn .= '('.$tmp->event_rep.') '; } @@ -2427,10 +2408,7 @@ try { $comment_id = array_search('user_comment', $fields); if ($comment_id !== false) { - $fields[$comment_id] = [ - 'text' => 'user_comment', - 'class' => 'nowrap_max180px', - ]; + $fields[$comment_id] = ['text' => 'user_comment']; } // Always add options column. diff --git a/pandora_console/operation/events/events_rss.php b/pandora_console/operation/events/events_rss.php index 4329910db9..aad21015fb 100644 --- a/pandora_console/operation/events/events_rss.php +++ b/pandora_console/operation/events/events_rss.php @@ -237,7 +237,6 @@ $column_names = [ 'id_agentmodule', 'id_alert_am', 'criticity', - 'user_comment', 'tags', 'source', 'id_extra', @@ -266,7 +265,6 @@ $fields = [ 'am.nombre as module_name', 'te.id_alert_am', 'te.criticity', - 'te.user_comment', 'te.tags', 'te.source', 'te.id_extra', diff --git a/pandora_console/operation/events/export_csv.php b/pandora_console/operation/events/export_csv.php index 98062ffab9..d820b8302a 100644 --- a/pandora_console/operation/events/export_csv.php +++ b/pandora_console/operation/events/export_csv.php @@ -70,7 +70,6 @@ $column_names = [ 'id_agentmodule', 'id_alert_am', 'criticity', - 'user_comment', 'tags', 'source', 'id_extra', @@ -99,7 +98,6 @@ if (is_metaconsole() === true) { 'te.id_agentmodule', 'te.id_alert_am', 'te.criticity', - 'te.user_comment', 'te.tags', 'te.source', 'te.id_extra', @@ -129,7 +127,6 @@ if (is_metaconsole() === true) { 'am.nombre as module_name', 'te.id_alert_am', 'te.criticity', - 'te.user_comment', 'te.tags', 'te.source', 'te.id_extra', diff --git a/pandora_console/pandoradb.sql b/pandora_console/pandoradb.sql index bc1715f97a..a1ef5a9b3e 100644 --- a/pandora_console/pandoradb.sql +++ b/pandora_console/pandoradb.sql @@ -706,7 +706,6 @@ CREATE TABLE IF NOT EXISTS `tevento` ( `id_agentmodule` INT NOT NULL DEFAULT 0, `id_alert_am` INT NOT NULL DEFAULT 0, `criticity` INT UNSIGNED NOT NULL DEFAULT 0, - `user_comment` TEXT, `tags` TEXT, `source` TINYTEXT, `id_extra` TINYTEXT, @@ -743,6 +742,20 @@ CREATE TABLE IF NOT EXISTS `tevent_extended` ( ON UPDATE CASCADE ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4; +-- --------------------------------------------------------------------- +-- Table `tevent_comment` +-- --------------------------------------------------------------------- +CREATE TABLE IF NOT EXISTS `tevent_comment` ( + `id` serial PRIMARY KEY, + `id_event` BIGINT UNSIGNED NOT NULL, + `utimestamp` BIGINT NOT NULL DEFAULT 0, + `comment` TEXT, + `id_user` VARCHAR(255) DEFAULT NULL, + `action` TEXT, + FOREIGN KEY (`id_event`) REFERENCES `tevento`(`id_evento`) + ON UPDATE CASCADE ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4; + -- --------------------------------------------------------------------- -- Table `tgrupo` -- --------------------------------------------------------------------- diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index c6e87003f7..60fb21a378 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -4103,11 +4103,6 @@ sub pandora_event { my $timestamp = strftime ("%Y-%m-%d %H:%M:%S", localtime ($utimestamp)); $id_agentmodule = 0 unless defined ($id_agentmodule); - if($comment ne '') { - my @comment_data = ({ comment => $comment, action => "Added comment", id_user => $user_name, utimestamp => $utimestamp}); - $comment = encode_json \@comment_data; - } - # Validate events with the same event id if (defined ($id_extra) && $id_extra ne '') { my $keep_in_process_status_extra_id = pandora_get_tconfig_token ($dbh, 'keep_in_process_status_extra_id', 0); @@ -4133,8 +4128,13 @@ sub pandora_event { # Create the event logger($pa_config, "Generating event '$evento' for agent ID $id_agente module ID $id_agentmodule.", 10); - $event_id = db_insert ($dbh, 'id_evento','INSERT INTO tevento (id_agente, id_grupo, evento, timestamp, estado, utimestamp, event_type, id_agentmodule, id_alert_am, criticity, user_comment, tags, source, id_extra, id_usuario, critical_instructions, warning_instructions, unknown_instructions, ack_utimestamp, custom_data, data, module_status) - VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', $id_agente, $id_grupo, safe_input ($evento), $timestamp, $event_status, $utimestamp, $event_type, $id_agentmodule, $id_alert_am, $severity, $comment, $module_tags, $source, $id_extra, $user_name, $critical_instructions, $warning_instructions, $unknown_instructions, $ack_utimestamp, $custom_data, safe_input($module_data), $module_status); + $event_id = db_insert ($dbh, 'id_evento','INSERT INTO tevento (id_agente, id_grupo, evento, timestamp, estado, utimestamp, event_type, id_agentmodule, id_alert_am, criticity, tags, source, id_extra, id_usuario, critical_instructions, warning_instructions, unknown_instructions, ack_utimestamp, custom_data, data, module_status) + VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', $id_agente, $id_grupo, safe_input ($evento), $timestamp, $event_status, $utimestamp, $event_type, $id_agentmodule, $id_alert_am, $severity, $module_tags, $source, $id_extra, $user_name, $critical_instructions, $warning_instructions, $unknown_instructions, $ack_utimestamp, $custom_data, safe_input($module_data), $module_status); + + if(defined($event_id) && $comment ne '') { + my $comment_id = db_insert ($dbh, 'id','INSERT INTO tevent_comment (id_event, utimestamp, comment, id_user, action) + VALUES (?, ?, ?, ?, ?)', $event_id, $utimestamp, safe_input($comment), $user_name, "Added comment"); + } # Do not write to the event file return $event_id if ($pa_config->{'event_file'} eq ''); @@ -4142,7 +4142,7 @@ sub pandora_event { # Add a header when the event file is created my $header = undef; if (! -f $pa_config->{'event_file'}) { - $header = "agent_name,group_name,evento,timestamp,estado,utimestamp,event_type,module_name,alert_name,criticity,user_comment,tags,source,id_extra,id_usuario,critical_instructions,warning_instructions,unknown_instructions,ack_utimestamp"; + $header = "agent_name,group_name,evento,timestamp,estado,utimestamp,event_type,module_name,alert_name,criticity,tags,source,id_extra,id_usuario,critical_instructions,warning_instructions,unknown_instructions,ack_utimestamp"; } # Open the event file for writing diff --git a/pandora_server/util/pandora_manage.pl b/pandora_server/util/pandora_manage.pl index 0358f4847b..3c1fc955bd 100755 --- a/pandora_server/util/pandora_manage.pl +++ b/pandora_server/util/pandora_manage.pl @@ -4551,7 +4551,7 @@ sub cli_create_event() { print_log "[INFO] Adding event '$event' for agent '$agent_name' \n\n"; pandora_event ($conf, $event, $id_group, $id_agent, $severity, - $id_alert_agent_module, $id_agentmodule, $event_type, $event_status, $dbh, safe_input($source), $user_name, safe_input($comment), safe_input($id_extra), safe_input($tags), safe_input($c_instructions), safe_input($w_instructions), safe_input($u_instructions), $custom_data, undef, undef, $server_id); + $id_alert_agent_module, $id_agentmodule, $event_type, $event_status, $dbh, safe_input($source), $user_name, $comment, safe_input($id_extra), safe_input($tags), safe_input($c_instructions), safe_input($w_instructions), safe_input($u_instructions), $custom_data, undef, undef, $server_id); } } @@ -4699,8 +4699,6 @@ sub cli_get_event_info () { print $csv_separator; print $event_data->{'criticity'}; print $csv_separator; - print $event_data->{'user_comment'}; - print $csv_separator; print $event_data->{'tags'}; print $csv_separator; print $event_data->{'source'}; @@ -4730,27 +4728,18 @@ sub cli_add_event_comment() { my $event_name = pandora_get_event_name($dbh, $id_event); exist_check($event_name,'event',$id_event); - - my $current_comment = encode_utf8(pandora_get_event_comment($dbh, $id_event)); - my $utimestamp = time (); - my @additional_comment = ({ comment => safe_input($comment), action => "Added comment", id_user => $id_user, utimestamp => $utimestamp, event_id => $id_event}); - + print_log "[INFO] Adding event comment for event '$id_event'. \n\n"; - my $decoded_comment; - my $update; - if ($current_comment eq '') { - $update->{'user_comment'} = encode_json \@additional_comment; - } - else { - $decoded_comment = decode_json($current_comment); - - push(@{$decoded_comment}, @additional_comment); - - $update->{'user_comment'} = encode_json($decoded_comment); - } - - pandora_update_event_from_hash ($update, 'id_evento', $id_event, $dbh); + my $parameters; + $parameters->{'id_event'} = $id_event; + $parameters->{'id_user'} = $user_name; + $parameters->{'utimestamp'} = time(); + $parameters->{'action'} = "Added comment"; + $parameters->{'comment'} = safe_input($comment); + + my $comment_id = db_process_insert($dbh, 'id', 'tevent_comment', $parameters); + return $comment_id; } ############################################################################## @@ -6703,12 +6692,12 @@ sub pandora_update_event_from_hash ($$$$) { # Return event comment given a event id ############################################################################## -sub pandora_get_event_comment($$) { +sub pandora_get_event_comments($$) { my ($dbh,$id_event) = @_; - my $event_name = get_db_value($dbh, 'SELECT user_comment FROM tevento WHERE id_evento = ?',$id_event); + my @comments = get_db_rows($dbh, 'SELECT * FROM tevent_comment WHERE id_evento = ?',$id_event); - return defined ($event_name) ? $event_name : -1; + return \@comments; } ############################################################################## From f97cf3a82406a0162e33d7b112cdae7b7f7bef32 Mon Sep 17 00:00:00 2001 From: daniel Date: Fri, 7 Jul 2023 13:02:00 +0200 Subject: [PATCH 2/8] change events user_comment new table tevent_comment pandora_enterprise#11387 --- pandora_console/extras/mr/65.sql | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/pandora_console/extras/mr/65.sql b/pandora_console/extras/mr/65.sql index cb8e3978dd..26ccd28ee8 100644 --- a/pandora_console/extras/mr/65.sql +++ b/pandora_console/extras/mr/65.sql @@ -12,4 +12,32 @@ DELETE FROM tconfig WHERE token = 'refr'; ALTER TABLE `tusuario` ADD COLUMN `session_max_time_expire` INT NOT NULL DEFAULT 0 AFTER `auth_token_secret`; +CREATE TABLE IF NOT EXISTS `tevent_comment` ( + `id` serial PRIMARY KEY, + `id_event` BIGINT UNSIGNED NOT NULL, + `utimestamp` BIGINT NOT NULL DEFAULT 0, + `comment` TEXT, + `id_user` VARCHAR(255) DEFAULT NULL, + `action` TEXT, + FOREIGN KEY (`id_event`) REFERENCES `tevento`(`id_evento`) + ON UPDATE CASCADE ON DELETE CASCADE, + FOREIGN KEY (`id_user`) REFERENCES tusuario(`id_user`) + ON DELETE SET NULL +) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4; + +INSERT INTO `tevent_comment` (`id_event`, `utimestamp`, `comment`, `id_user`, `action`) +SELECT * FROM ( + SELECT tevento.id_evento AS `id_event`, + JSON_UNQUOTE(JSON_EXTRACT(tevento.user_comment, CONCAT('$[',n.num,'].utimestamp'))) AS `utimestamp`, + JSON_UNQUOTE(JSON_EXTRACT(tevento.user_comment, CONCAT('$[',n.num,'].comment'))) AS `comment`, + JSON_UNQUOTE(JSON_EXTRACT(tevento.user_comment, CONCAT('$[',n.num,'].id_user'))) AS `id_user`, + JSON_UNQUOTE(JSON_EXTRACT(tevento.user_comment, CONCAT('$[',n.num,'].action'))) AS `action` + FROM tevento + INNER JOIN (SELECT 0 num UNION ALL SELECT 1 UNION ALL SELECT 2) n + ON n.num < JSON_LENGTH(tevento.user_comment) + WHERE tevento.user_comment != "" +) t order by utimestamp DESC; + +ALTER TABLE tevento DROP COLUMN user_comment; + COMMIT; From d3412a7ad1fb57b70e9a774badd6d4ba5780a626 Mon Sep 17 00:00:00 2001 From: daniel Date: Mon, 10 Jul 2023 16:26:33 +0200 Subject: [PATCH 3/8] add filter events comments pandora_enterprise#11387 --- .../godmode/setup/setup_general.php | 11 + pandora_console/include/ajax/events.php | 48 +-- pandora_console/include/functions_config.php | 8 + pandora_console/include/functions_events.php | 280 +++++++++++++----- pandora_console/include/functions_html.php | 23 +- .../include/javascript/pandora_events.js | 21 +- pandora_console/operation/events/events.php | 16 +- 7 files changed, 289 insertions(+), 118 deletions(-) diff --git a/pandora_console/godmode/setup/setup_general.php b/pandora_console/godmode/setup/setup_general.php index 96a01694d2..a7fcc23c8b 100644 --- a/pandora_console/godmode/setup/setup_general.php +++ b/pandora_console/godmode/setup/setup_general.php @@ -743,6 +743,17 @@ $table->data[$i][] = html_print_label_input_block( ) ); +$table->data[$i++][] = html_print_label_input_block( + __('Max. hours old events comments'), + html_print_input_number( + [ + 'name' => 'max_hours_old_event_comment', + 'min' => 0, + 'value' => $config['max_hours_old_event_comment'], + ] + ) +); + echo '
'; echo '
'; diff --git a/pandora_console/include/ajax/events.php b/pandora_console/include/ajax/events.php index 7237cbbefb..9b79f1f7c2 100644 --- a/pandora_console/include/ajax/events.php +++ b/pandora_console/include/ajax/events.php @@ -92,18 +92,34 @@ $get_id_source_event = get_parameter('get_id_source_event'); $node_id = (int) get_parameter('node_id', 0); if ($get_comments === true) { - $event = get_parameter('event', false); - $event_rep = (int) get_parameter_post('event')['event_rep']; - $group_rep = (int) get_parameter_post('event')['group_rep']; + global $config; + $event = json_decode(io_safe_output(base64_decode(get_parameter('event', ''))), true); + $filter = json_decode(io_safe_output(base64_decode(get_parameter('filter', ''))), true); + + $default_hour = (int) $filter['event_view_hr']; + if (isset($config['max_hours_old_event_comment']) === true + && empty($config['max_hours_old_event_comment']) === false + ) { + $default_hour = (int) $config['max_hours_old_event_comment']; + } + + $custom_event_view_hr = (int) get_parameter('custom_event_view_hr', 0); + if (empty($custom_event_view_hr) === false) { + if ($custom_event_view_hr === -2) { + $filter['event_view_hr_cs'] = ($default_hour * 3600); + } else { + $filter['event_view_hr_cs'] = $custom_event_view_hr; + } + } else { + $filter['event_view_hr_cs'] = ($default_hour * 3600); + } if ($event === false) { return __('Failed to retrieve comments'); } - $eventsGrouped = event_get_comment($event, $group_rep, $event_rep); - - // End of get_comments. - echo events_page_comments($event, true, $eventsGrouped); + $eventsGrouped = event_get_comment($event, $filter); + echo events_page_comments($event, $eventsGrouped, $filter); return; } @@ -1937,23 +1953,7 @@ if ($get_extended_event) { $js .= '});'; - $js .= ' - $("#link_comments").click(function (){ - $.post ({ - url : "ajax.php", - data : { - page: "include/ajax/events", - get_comments: 1, - event: '.json_encode($event).', - event_rep: '.$event_rep.' - }, - dataType : "html", - success: function (data) { - $("#extended_event_comments_page").empty(); - $("#extended_event_comments_page").html(data); - } - }); - });'; + $js .= '$("#link_comments").click(get_table_events_tabs(\''.base64_encode(json_encode($event)).'\',\''.base64_encode(json_encode($filter)).'\'));'; if (events_has_extended_info($event['id_evento']) === true) { $js .= ' diff --git a/pandora_console/include/functions_config.php b/pandora_console/include/functions_config.php index 7a82254cf8..e302b18bc2 100644 --- a/pandora_console/include/functions_config.php +++ b/pandora_console/include/functions_config.php @@ -398,6 +398,10 @@ function config_update_config() $error_update[] = __('Check conexion interval'); } + if (config_update_value('max_hours_old_event_comment', get_parameter('max_hours_old_event_comment'), true) === false) { + $error_update[] = __('Max hours old event comments'); + } + if (config_update_value('unique_ip', get_parameter('unique_ip'), true) === false) { $error_update[] = __('Unique IP'); } @@ -2397,6 +2401,10 @@ function config_process_config() config_update_value('check_conexion_interval', 180); } + if (!isset($config['max_hours_old_event_comment'])) { + config_update_value('max_hours_old_event_comment', 48); + } + if (!isset($config['elasticsearch_ip'])) { config_update_value('elasticsearch_ip', ''); } diff --git a/pandora_console/include/functions_events.php b/pandora_console/include/functions_events.php index 8498584e69..16a92f789e 100644 --- a/pandora_console/include/functions_events.php +++ b/pandora_console/include/functions_events.php @@ -613,6 +613,74 @@ function events_update_status($id_evento, $status, $filter=null) } +/** + * Get filter time. + * + * @param array $filter Filters. + * + * @return array conditions. + */ +function get_filter_date(array $filter) +{ + if (isset($filter['date_from']) === true + && empty($filter['date_from']) === false + && $filter['date_from'] !== '0000-00-00' + ) { + $date_from = $filter['date_from']; + } + + if (isset($filter['time_from']) === true) { + $time_from = (empty($filter['time_from']) === true) ? '00:00:00' : $filter['time_from']; + } + + if (isset($date_from) === true) { + if (isset($time_from) === false) { + $time_from = '00:00:00'; + } + + $from = $date_from.' '.$time_from; + $sql_filters[] = sprintf( + ' AND te.utimestamp >= %d', + strtotime($from) + ); + } + + if (isset($filter['date_to']) === true + && empty($filter['date_to']) === false + && $filter['date_to'] !== '0000-00-00' + ) { + $date_to = $filter['date_to']; + } + + if (isset($filter['time_to']) === true) { + $time_to = (empty($filter['time_to']) === true) ? '23:59:59' : $filter['time_to']; + } + + if (isset($date_to) === true) { + if (isset($time_to) === false) { + $time_to = '23:59:59'; + } + + $to = $date_to.' '.$time_to; + $sql_filters[] = sprintf( + ' AND te.utimestamp <= %d', + strtotime($to) + ); + } + + if (isset($from) === false) { + if (isset($filter['event_view_hr']) === true && ($filter['event_view_hr'] > 0)) { + $sql_filters[] = sprintf( + ' AND te.utimestamp > UNIX_TIMESTAMP(now() - INTERVAL %d HOUR) ', + $filter['event_view_hr'] + ); + } + } + + return $sql_filters; +} + + /** * Retrieve all events filtered. * @@ -700,60 +768,7 @@ function events_get_all( ); } - if (isset($filter['date_from']) === true - && empty($filter['date_from']) === false - && $filter['date_from'] !== '0000-00-00' - ) { - $date_from = $filter['date_from']; - } - - if (isset($filter['time_from']) === true) { - $time_from = (empty($filter['time_from']) === true) ? '00:00:00' : $filter['time_from']; - } - - if (isset($date_from) === true) { - if (isset($time_from) === false) { - $time_from = '00:00:00'; - } - - $from = $date_from.' '.$time_from; - $sql_filters[] = sprintf( - ' AND te.utimestamp >= %d', - strtotime($from) - ); - } - - if (isset($filter['date_to']) === true - && empty($filter['date_to']) === false - && $filter['date_to'] !== '0000-00-00' - ) { - $date_to = $filter['date_to']; - } - - if (isset($filter['time_to']) === true) { - $time_to = (empty($filter['time_to']) === true) ? '23:59:59' : $filter['time_to']; - } - - if (isset($date_to) === true) { - if (isset($time_to) === false) { - $time_to = '23:59:59'; - } - - $to = $date_to.' '.$time_to; - $sql_filters[] = sprintf( - ' AND te.utimestamp <= %d', - strtotime($to) - ); - } - - if (isset($from) === false) { - if (isset($filter['event_view_hr']) === true && ($filter['event_view_hr'] > 0)) { - $sql_filters[] = sprintf( - ' AND te.utimestamp > UNIX_TIMESTAMP(now() - INTERVAL %d HOUR) ', - $filter['event_view_hr'] - ); - } - } + $sql_filters = get_filter_date($filter); if (isset($filter['id_agent']) === true && $filter['id_agent'] > 0) { $sql_filters[] = sprintf( @@ -5132,7 +5147,7 @@ function events_page_general_acknowledged($event_id) * * @return string HTML. */ -function events_page_comments($event, $ajax=false, $groupedComments=[]) +function events_page_comments($event, $groupedComments=[], $filter=null) { // Comments. global $config; @@ -5220,11 +5235,58 @@ function events_page_comments($event, $ajax=false, $groupedComments=[]) $comments_form .= '
'; } - if ($ajax === true) { - return $comments_form.html_print_table($table_comments, true); - } + $table_filter = new stdClass; + $table_filter->width = '100%'; + $table_filter->class = 'databox filters no_border filter-table-adv'; + $table_filter->size = []; + $table_filter->size[0] = '80%'; + $table_filter->data = []; + $table_filter->data[0][0] = html_print_label_input_block( + __('Max. hours old').ui_print_help_tip(__('Hours filter comments'), true), + html_print_extended_select_for_time( + 'comments_events_max_hours_old', + $filter['event_view_hr_cs'], + '', + __('Default'), + -2, + false, + true, + false, + true, + '', + false, + [ + SECONDS_1HOUR => __('1 hour'), + SECONDS_6HOURS => __('6 hours'), + SECONDS_12HOURS => __('12 hours'), + SECONDS_1DAY => __('24 hours'), + SECONDS_2DAY => __('48 hours'), + ], + '', + false, + 0, + [ SECONDS_1HOUR => __('hours') ], + ) + ); - return '
'.$comments_form.html_print_table($table_comments, true).'
'; + $event = base64_encode(json_encode($event)); + $filter = base64_encode(json_encode($filter)); + + $table_filter->data[0][1] = html_print_submit_button( + __('Filter'), + 'filter_comments_button', + false, + [ + 'class' => 'mini', + 'icon' => 'search', + 'onclick' => 'get_table_events_tabs("'.$event.'","'.$filter.'")', + ], + true + ); + + $comments_time_input = html_print_table($table_filter, true); + + return $comments_form.$comments_time_input.html_print_table($table_comments, true); } @@ -5942,39 +6004,50 @@ function get_count_event_criticity( * * @return array Comments. */ -function event_get_comment($event, $mode, $event_rep) +function event_get_comment($event, $filter=null) { + $whereGrouped = []; + if (empty($filter) === false) { + if (isset($filter['event_view_hr_cs']) === true && ($filter['event_view_hr_cs'] > 0)) { + $whereGrouped[] = sprintf( + ' AND tevent_comment.utimestamp > UNIX_TIMESTAMP(now() - INTERVAL %d SECOND) ', + $filter['event_view_hr_cs'] + ); + } + } + + $mode = (int) $filter['group_rep']; + $eventsGrouped = []; // Consider if the event is grouped. - $whereGrouped = '1=1'; - if ($mode === EVENT_GROUP_REP_EVENTS && $event_rep > 1) { + if ($mode === EVENT_GROUP_REP_EVENTS) { // Default grouped message filtering (evento and estado). - $whereGrouped = sprintf( - '`tevento`.`evento` = "%s"', + $whereGrouped[] = sprintf( + 'AND `tevento`.`evento` = "%s"', $event['evento'] ); // If id_agente is reported, filter the messages by them as well. if ((int) $event['id_agente'] > 0) { - $whereGrouped .= sprintf( + $whereGrouped[] = sprintf( ' AND `tevento`.`id_agente` = %d', (int) $event['id_agente'] ); } if ((int) $event['id_agentmodule'] > 0) { - $whereGrouped .= sprintf( + $whereGrouped[] = sprintf( ' AND `tevento`.`id_agentmodule` = %d', (int) $event['id_agentmodule'] ); } } else if ($mode === EVENT_GROUP_REP_EXTRAIDS) { - $whereGrouped = sprintf( - '`tevento`.`id_extra` = "%s"', + $whereGrouped[] = sprintf( + 'AND `tevento`.`id_extra` = "%s"', io_safe_output($event['id_extra']) ); } else { - $whereGrouped = sprintf('`tevento`.`id_evento` = %d', $event['id_evento']); + $whereGrouped[] = sprintf('AND `tevento`.`id_evento` = %d', $event['id_evento']); } try { @@ -5990,9 +6063,9 @@ function event_get_comment($event, $mode, $event_rep) FROM tevento INNER JOIN tevent_comment ON tevento.id_evento = tevent_comment.id_event - WHERE %s + WHERE 1=1 %s ORDER BY tevent_comment.utimestamp DESC', - $whereGrouped + implode(' ', $whereGrouped) ); // Get grouped comments. @@ -6021,18 +6094,73 @@ function event_get_comment($event, $mode, $event_rep) /** * Last comment for this event. * - * @param array $event Info event. - * @param integer $mode Mode group by. - * @param integer $event_rep Events. + * @param array $event Info event. * * @return string Comment. */ -function event_get_last_comment($event, $mode, $event_rep) +function event_get_last_comment($event, $filter) { - $comments = event_get_comment($event, (int) $mode, $event_rep); + $comments = event_get_comment($event, $filter); if (empty($comments) === false) { return $comments[0]; } return ''; } + + +/** + * Get counter events same extraid. + * + * @param array $event Event data. + * @param array $filters Filters. + * + * @return integer Counter. + */ +function event_get_counter_extraId(array $event, ?array $filters) +{ + $counters = 0; + + $where = get_filter_date($filters); + + $where[] = sprintf( + 'AND `te`.`id_extra` = "%s"', + io_safe_output($event['id_extra']) + ); + + try { + if (is_metaconsole() === true + && $event['server_id'] > 0 + ) { + $node = new Node($event['server_id']); + $node->connect(); + } + + $sql = sprintf( + 'SELECT count(*) + FROM tevento te + WHERE 1=1 %s', + implode(' ', $where) + ); + + // Get grouped comments. + $counters = db_get_value_sql($sql); + } catch (\Exception $e) { + // Unexistent agent. + if (is_metaconsole() === true + && $event['server_id'] > 0 + ) { + $node->disconnect(); + } + + $counters = 0; + } finally { + if (is_metaconsole() === true + && $event['server_id'] > 0 + ) { + $node->disconnect(); + } + } + + return $counters; +} diff --git a/pandora_console/include/functions_html.php b/pandora_console/include/functions_html.php index c4d5c396cd..4282dfed80 100644 --- a/pandora_console/include/functions_html.php +++ b/pandora_console/include/functions_html.php @@ -2161,7 +2161,8 @@ function html_print_extended_select_for_time( $custom_fields=false, $style_icon='', $no_change=false, - $allow_zero=0 + $allow_zero=0, + $units=null ) { global $config; $admin = is_user_admin($config['id_user']); @@ -2187,15 +2188,17 @@ function html_print_extended_select_for_time( $selected = 300; } - $units = [ - 1 => __('seconds'), - SECONDS_1MINUTE => __('minutes'), - SECONDS_1HOUR => __('hours'), - SECONDS_1DAY => __('days'), - SECONDS_1WEEK => __('weeks'), - SECONDS_1MONTH => __('months'), - SECONDS_1YEAR => __('years'), - ]; + if (empty($units) === true) { + $units = [ + 1 => __('seconds'), + SECONDS_1MINUTE => __('minutes'), + SECONDS_1HOUR => __('hours'), + SECONDS_1DAY => __('days'), + SECONDS_1WEEK => __('weeks'), + SECONDS_1MONTH => __('months'), + SECONDS_1YEAR => __('years'), + ]; + } if ($unique_name === true) { $uniq_name = uniqid($name); diff --git a/pandora_console/include/javascript/pandora_events.js b/pandora_console/include/javascript/pandora_events.js index 7916b921d6..286c6d5ac4 100644 --- a/pandora_console/include/javascript/pandora_events.js +++ b/pandora_console/include/javascript/pandora_events.js @@ -484,7 +484,7 @@ function event_comment(current_event) { success: function() { $("#button-comment_button").removeAttr("disabled"); $("#response_loading").hide(); - $("#link_comments").click(); + $("#button-filter_comments_button").click(); } }); @@ -1229,3 +1229,22 @@ function removeElement(name_select, id_modal) { .append(option); }); } + +function get_table_events_tabs(event, filter) { + var custom_event_view_hr = $("#hidden-comments_events_max_hours_old").val(); + $.post({ + url: "ajax.php", + data: { + page: "include/ajax/events", + get_comments: 1, + event: event, + filter: filter, + custom_event_view_hr: custom_event_view_hr + }, + dataType: "html", + success: function(data) { + $("#extended_event_comments_page").empty(); + $("#extended_event_comments_page").html(data); + } + }); +} diff --git a/pandora_console/operation/events/events.php b/pandora_console/operation/events/events.php index c1b930b2e3..5e5e8a76ae 100644 --- a/pandora_console/operation/events/events.php +++ b/pandora_console/operation/events/events.php @@ -574,8 +574,7 @@ if (is_ajax() === true) { $tmp->user_comment = ui_print_comments( event_get_last_comment( $item, - $filter['group_rep'], - $item['event_rep'] + $filter ) ); @@ -649,11 +648,14 @@ if (is_ajax() === true) { // Grouped events. if ((int) $filter['group_rep'] === EVENT_GROUP_REP_EXTRAIDS) { - $evn .= '(el contador de extraid iguales) '; - } - - if (isset($tmp->event_rep) === true && $tmp->event_rep > 1) { - $evn .= '('.$tmp->event_rep.') '; + $counter_extra_id = event_get_counter_extraId($item, $filter); + if (empty($counter_extra_id) === false && $counter_extra_id > 0) { + $evn .= '('.$counter_extra_id.') '; + } + } else { + if (isset($tmp->event_rep) === true && $tmp->event_rep > 1) { + $evn .= '('.$tmp->event_rep.') '; + } } $evn .= $tmp->evento.'
'; From c520375c61fdef8360ed3667e347362dad944720 Mon Sep 17 00:00:00 2001 From: daniel Date: Wed, 19 Jul 2023 13:28:53 +0200 Subject: [PATCH 4/8] ack utimestamp pandora_enterprise#11387 --- pandora_console/include/functions_config.php | 2 +- pandora_console/include/functions_events.php | 124 ++++++++++--------- pandora_console/include/styles/events.css | 7 ++ pandora_console/operation/events/events.php | 2 +- pandora_server/lib/PandoraFMS/Core.pm | 3 +- 5 files changed, 76 insertions(+), 62 deletions(-) diff --git a/pandora_console/include/functions_config.php b/pandora_console/include/functions_config.php index 6024979a55..f98dae5bf9 100644 --- a/pandora_console/include/functions_config.php +++ b/pandora_console/include/functions_config.php @@ -2426,7 +2426,7 @@ function config_process_config() } if (!isset($config['max_hours_old_event_comment'])) { - config_update_value('max_hours_old_event_comment', 48); + config_update_value('max_hours_old_event_comment', 8); } if (!isset($config['elasticsearch_ip'])) { diff --git a/pandora_console/include/functions_events.php b/pandora_console/include/functions_events.php index 16a92f789e..28a931c3c4 100644 --- a/pandora_console/include/functions_events.php +++ b/pandora_console/include/functions_events.php @@ -5195,54 +5195,9 @@ function events_page_comments($event, $groupedComments=[], $filter=null) } } - if (((tags_checks_event_acl( - $config['id_user'], - $event['id_grupo'], - 'EM', - (isset($event['clean_tags']) === true) ? $event['clean_tags'] : [], - [] - )) || (tags_checks_event_acl( - $config['id_user'], - $event['id_grupo'], - 'EW', - (isset($event['clean_tags']) === true) ? $event['clean_tags'] : [], - [] - ))) - ) { - $event['evento'] = io_safe_output($event['evento']); - $comments_form = '
'; - $comments_form .= html_print_textarea( - 'comment', - 3, - 10, - '', - 'class="comments_form"', - true - ); - - $comments_form .= '
'; - $comments_form .= html_print_button( - __('Add comment'), - 'comment_button', - false, - 'event_comment("'.base64_encode(json_encode($event)).'");', - [ - 'icon' => 'next', - 'mode' => 'mini secondary', - ], - true - ); - $comments_form .= '

'; - } - - $table_filter = new stdClass; - $table_filter->width = '100%'; - $table_filter->class = 'databox filters no_border filter-table-adv'; - $table_filter->size = []; - $table_filter->size[0] = '80%'; - $table_filter->data = []; - $table_filter->data[0][0] = html_print_label_input_block( - __('Max. hours old').ui_print_help_tip(__('Hours filter comments'), true), + $comments_filter = '
'; + $comments_filter .= html_print_label_input_block( + null, html_print_extended_select_for_time( 'comments_events_max_hours_old', $filter['event_view_hr_cs'], @@ -5269,24 +5224,70 @@ function events_page_comments($event, $groupedComments=[], $filter=null) ) ); - $event = base64_encode(json_encode($event)); - $filter = base64_encode(json_encode($filter)); - - $table_filter->data[0][1] = html_print_submit_button( + $eventb64 = base64_encode(json_encode($event)); + $filterb64 = base64_encode(json_encode($filter)); + $comments_filter .= html_print_submit_button( __('Filter'), 'filter_comments_button', false, [ - 'class' => 'mini', + 'class' => 'mini mrgn_lft_15px', 'icon' => 'search', - 'onclick' => 'get_table_events_tabs("'.$event.'","'.$filter.'")', + 'onclick' => 'get_table_events_tabs("'.$eventb64.'","'.$filterb64.'")', ], true ); + $comments_filter .= '
'; - $comments_time_input = html_print_table($table_filter, true); + if (((tags_checks_event_acl( + $config['id_user'], + $event['id_grupo'], + 'EM', + (isset($event['clean_tags']) === true) ? $event['clean_tags'] : [], + [] + )) || (tags_checks_event_acl( + $config['id_user'], + $event['id_grupo'], + 'EW', + (isset($event['clean_tags']) === true) ? $event['clean_tags'] : [], + [] + ))) + ) { + $event['evento'] = io_safe_output($event['evento']); + $comments_form = '
'; + $comments_form .= html_print_textarea( + 'comment', + 3, + 10, + '', + 'class="comments_form"', + true + ); - return $comments_form.$comments_time_input.html_print_table($table_comments, true); + $comments_form .= '
'; + $comments_form .= '
'; + $comments_form .= $comments_filter; + $comments_form .= '
'; + $comments_form .= html_print_button( + __('Add comment'), + 'comment_button', + false, + 'event_comment("'.base64_encode(json_encode($event)).'");', + [ + 'icon' => 'next', + 'mode' => 'mini secondary', + ], + true + ); + $comments_form .= '
'; + $comments_form .= '
'; + + $comments_form .= '
'; + } else { + $comments_form = $comments_filter; + } + + return $comments_form.html_print_table($table_comments, true); } @@ -6013,6 +6014,11 @@ function event_get_comment($event, $filter=null) ' AND tevent_comment.utimestamp > UNIX_TIMESTAMP(now() - INTERVAL %d SECOND) ', $filter['event_view_hr_cs'] ); + } else if (isset($filter['event_view_hr']) === true && ($filter['event_view_hr'] > 0)) { + $whereGrouped[] = sprintf( + ' AND tevent_comment.utimestamp > UNIX_TIMESTAMP(now() - INTERVAL %d SECOND) ', + ((int) $filter['event_view_hr'] * 3600) + ); } } @@ -6024,7 +6030,7 @@ function event_get_comment($event, $filter=null) // Default grouped message filtering (evento and estado). $whereGrouped[] = sprintf( 'AND `tevento`.`evento` = "%s"', - $event['evento'] + io_safe_input(io_safe_output($event['evento'])) ); // If id_agente is reported, filter the messages by them as well. @@ -6044,7 +6050,7 @@ function event_get_comment($event, $filter=null) } else if ($mode === EVENT_GROUP_REP_EXTRAIDS) { $whereGrouped[] = sprintf( 'AND `tevento`.`id_extra` = "%s"', - io_safe_output($event['id_extra']) + io_safe_input(io_safe_output($event['id_extra'])) ); } else { $whereGrouped[] = sprintf('AND `tevento`.`id_evento` = %d', $event['id_evento']); @@ -6125,7 +6131,7 @@ function event_get_counter_extraId(array $event, ?array $filters) $where[] = sprintf( 'AND `te`.`id_extra` = "%s"', - io_safe_output($event['id_extra']) + $event['id_extra'] ); try { diff --git a/pandora_console/include/styles/events.css b/pandora_console/include/styles/events.css index 4f7b639eaa..c750550595 100644 --- a/pandora_console/include/styles/events.css +++ b/pandora_console/include/styles/events.css @@ -558,3 +558,10 @@ div#sunburst > svg { width: 750px; height: 750px; } + +div.container-filter-buttons { + display: flex; + flex-direction: row; + justify-content: space-between; + align-items: center; +} diff --git a/pandora_console/operation/events/events.php b/pandora_console/operation/events/events.php index 28f88ec8ab..caf2e70c76 100644 --- a/pandora_console/operation/events/events.php +++ b/pandora_console/operation/events/events.php @@ -653,7 +653,7 @@ if (is_ajax() === true) { // Grouped events. if ((int) $filter['group_rep'] === EVENT_GROUP_REP_EXTRAIDS) { $counter_extra_id = event_get_counter_extraId($item, $filter); - if (empty($counter_extra_id) === false && $counter_extra_id > 0) { + if (empty($counter_extra_id) === false && $counter_extra_id > 1) { $evn .= '('.$counter_extra_id.') '; } } else { diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index a5cb0bc731..b90044db58 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -4098,7 +4098,7 @@ sub pandora_event { $module_status = defined($module) ? $module->{'estado'} : 0 unless defined ($module_status); # If the event is created with validated status, assign ack_utimestamp - my $ack_utimestamp = $event_status == 1 ? time() : 0; + my $ack_utimestamp = ($event_status == 1 || $event_status == 2) ? time() : 0; my $utimestamp = time (); my $timestamp = strftime ("%Y-%m-%d %H:%M:%S", localtime ($utimestamp)); @@ -4117,6 +4117,7 @@ sub pandora_event { # Only when the event comes as New. Validated events are excluded if (defined($id_extra_inprocess_count) && $id_extra_inprocess_count > 0 && $event_status == 0) { logger($pa_config, "Keeping In process status from last event with extended id '$id_extra'.", 10); + $ack_utimestamp = get_db_value ($dbh, 'SELECT ack_utimestamp FROM tevento WHERE id_extra=? AND estado=2', $id_extra); $event_status = 2; } } From a10412872b6d4e9d07dae5bef2a3ae0da1f73e59 Mon Sep 17 00:00:00 2001 From: daniel Date: Wed, 19 Jul 2023 15:04:37 +0200 Subject: [PATCH 5/8] alerts user comment pandora_enterprise#11387 --- pandora_console/include/functions_events.php | 1 - 1 file changed, 1 deletion(-) diff --git a/pandora_console/include/functions_events.php b/pandora_console/include/functions_events.php index 28a931c3c4..5347f3cde4 100644 --- a/pandora_console/include/functions_events.php +++ b/pandora_console/include/functions_events.php @@ -2355,7 +2355,6 @@ function events_create_event( 'id_agentmodule' => $id_agent_module, 'id_alert_am' => $id_aam, 'criticity' => $priority, - 'user_comment' => '', 'tags' => $tags, 'source' => $source, 'id_extra' => $id_extra, From 8029125929106da3fae45a790bfa0fc7b23631a2 Mon Sep 17 00:00:00 2001 From: "alejandro.campos@artica.es" Date: Thu, 27 Jul 2023 15:04:22 +0200 Subject: [PATCH 6/8] fix inherit ack timestamp feature --- pandora_console/include/functions_api.php | 23 ++++++++++++++------ pandora_console/include/functions_events.php | 5 +++-- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/pandora_console/include/functions_api.php b/pandora_console/include/functions_api.php index 32ff85770b..b854668a0c 100644 --- a/pandora_console/include/functions_api.php +++ b/pandora_console/include/functions_api.php @@ -13102,18 +13102,26 @@ function api_set_create_event($id, $trash1, $other, $returnType) $values['custom_data'] = ''; } + $ack_utimestamp = 0; + if ($other['data'][18] != '') { $values['id_extra'] = $other['data'][18]; - $sql_validation = 'SELECT id_evento,estado FROM tevento where estado IN (0,2) and id_extra ="'.$other['data'][18].'";'; + $sql_validation = 'SELECT id_evento,estado,ack_utimestamp + FROM tevento + WHERE estado IN (0,2) AND id_extra ="'.$other['data'][18].'";'; + $validation = db_get_all_rows_sql($sql_validation); if ($validation) { foreach ($validation as $val) { - if ((bool) $config['keep_in_process_status_extra_id'] === true - && (int) $val['estado'] === EVENT_STATUS_INPROCESS - && (int) $values['status'] === 0 - ) { - $values['status'] = 2; + if ((bool) $config['keep_in_process_status_extra_id'] === true) { + // Inherit status when previous event was in "in process" status. + if ((int) $val['estado'] === EVENT_STATUS_INPROCESS && (int) $values['status'] === 0) { + $values['status'] = 2; + } + + // Always inherit ack_utimestamp. + $ack_utimestamp = $val['ack_utimestamp']; } api_set_validate_event_by_id($val['id_evento']); @@ -13143,7 +13151,8 @@ function api_set_create_event($id, $trash1, $other, $returnType) $values['tags'], $custom_data, $values['server_id'], - $values['id_extra'] + $values['id_extra'], + $ack_utimestamp ); if ($other['data'][12] != '') { diff --git a/pandora_console/include/functions_events.php b/pandora_console/include/functions_events.php index 5347f3cde4..1abcc8bb5e 100644 --- a/pandora_console/include/functions_events.php +++ b/pandora_console/include/functions_events.php @@ -2334,7 +2334,8 @@ function events_create_event( $tags='', $custom_data='', $server_id=0, - $id_extra='' + $id_extra='', + $ack_utimestamp=0 ) { if ($source === false) { $source = get_product_name(); @@ -2362,7 +2363,7 @@ function events_create_event( 'warning_instructions' => $warning_instructions, 'unknown_instructions' => $unknown_instructions, 'owner_user' => '', - 'ack_utimestamp' => 0, + 'ack_utimestamp' => $ack_utimestamp, 'custom_data' => $custom_data, 'data' => '', 'module_status' => 0, From cf26f4c32a3e1e2ce18b2000eeac886c0acb3955 Mon Sep 17 00:00:00 2001 From: "alejandro.campos@artica.es" Date: Thu, 27 Jul 2023 15:11:15 +0200 Subject: [PATCH 7/8] fix inherit ack timestamp feature --- pandora_console/include/functions_api.php | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/pandora_console/include/functions_api.php b/pandora_console/include/functions_api.php index b854668a0c..1e944044e8 100644 --- a/pandora_console/include/functions_api.php +++ b/pandora_console/include/functions_api.php @@ -13114,16 +13114,14 @@ function api_set_create_event($id, $trash1, $other, $returnType) if ($validation) { foreach ($validation as $val) { - if ((bool) $config['keep_in_process_status_extra_id'] === true) { - // Inherit status when previous event was in "in process" status. - if ((int) $val['estado'] === EVENT_STATUS_INPROCESS && (int) $values['status'] === 0) { - $values['status'] = 2; - } - - // Always inherit ack_utimestamp. + if ((bool) $config['keep_in_process_status_extra_id'] === true + && (int) $val['estado'] === EVENT_STATUS_INPROCESS + && (int) $values['status'] === 0 + ) { + $values['status'] = 2; $ack_utimestamp = $val['ack_utimestamp']; } - + api_set_validate_event_by_id($val['id_evento']); } } From 75219fb46511e6dad8d5c39d6a0e8b489ab506bd Mon Sep 17 00:00:00 2001 From: "alejandro.campos@artica.es" Date: Fri, 28 Jul 2023 12:31:20 +0200 Subject: [PATCH 8/8] keep user id --- pandora_console/include/functions_api.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandora_console/include/functions_api.php b/pandora_console/include/functions_api.php index 1e944044e8..2a21bed3a6 100644 --- a/pandora_console/include/functions_api.php +++ b/pandora_console/include/functions_api.php @@ -13106,7 +13106,7 @@ function api_set_create_event($id, $trash1, $other, $returnType) if ($other['data'][18] != '') { $values['id_extra'] = $other['data'][18]; - $sql_validation = 'SELECT id_evento,estado,ack_utimestamp + $sql_validation = 'SELECT id_evento,estado,ack_utimestamp,id_usuario FROM tevento WHERE estado IN (0,2) AND id_extra ="'.$other['data'][18].'";'; @@ -13120,6 +13120,7 @@ function api_set_create_event($id, $trash1, $other, $returnType) ) { $values['status'] = 2; $ack_utimestamp = $val['ack_utimestamp']; + $values['id_usuario'] = $val['id_usuario']; } api_set_validate_event_by_id($val['id_evento']);