Merge branch 'ent-11387-post-mantener-conteo-y-comentarios-de-in-process-extra-id' into 'develop'

change events user_comment new table tevent_comment pandora_enterprise#11387

See merge request artica/pandorafms!6223
This commit is contained in:
Rafael Ameijeiras 2023-07-31 07:51:57 +00:00
commit 538f8363bc
20 changed files with 564 additions and 531 deletions

View File

@ -83,4 +83,32 @@ INSERT INTO `tmodule_inventory` (`id_module_inventory`, `id_os`, `name`, `descri
ALTER TABLE `treport_content` ADD COLUMN `period_range` INT NULL DEFAULT 0 AFTER `period`;
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;

View File

@ -747,6 +747,16 @@ $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'],
]
)
);
$table->data[$i][] = html_print_label_input_block(
__('Show experimental features'),
html_print_checkbox_switch(

View File

@ -94,84 +94,34 @@ $settings_modal = get_parameter('settings', 0);
$parameters_modal = get_parameter('parameters', 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 = [];
// 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();
}
}
// 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;
}
@ -2010,23 +1960,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 .= '

View File

@ -13102,9 +13102,14 @@ 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,id_usuario
FROM tevento
WHERE estado IN (0,2) AND id_extra ="'.$other['data'][18].'";';
$validation = db_get_all_rows_sql($sql_validation);
if ($validation) {
@ -13114,6 +13119,8 @@ function api_set_create_event($id, $trash1, $other, $returnType)
&& (int) $values['status'] === 0
) {
$values['status'] = 2;
$ack_utimestamp = $val['ack_utimestamp'];
$values['id_usuario'] = $val['id_usuario'];
}
api_set_validate_event_by_id($val['id_evento']);
@ -13143,7 +13150,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] != '') {
@ -15755,6 +15763,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.'

View File

@ -402,6 +402,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');
}
@ -2429,6 +2433,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', 8);
}
if (!isset($config['elasticsearch_ip'])) {
config_update_value('elasticsearch_ip', '');
}

View File

@ -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 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(
@ -1069,7 +1084,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 +1120,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 +1135,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 +1465,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 +1562,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 "<br>") 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,6 +1590,7 @@ function events_get_all(
FROM %s
%s
%s
%s
%s JOIN %s ta
ON ta.%s = te.id_agente
%s
@ -1611,6 +1606,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 +1621,7 @@ function events_get_all(
$tevento,
$event_lj,
$agentmodule_join,
$event_comment_join,
$tagente_join,
$tagente_table,
$tagente_field,
@ -1638,6 +1635,7 @@ function events_get_all(
$having,
$event_lj,
$agentmodule_join,
$event_comment_join,
$tagente_join,
$tagente_table,
$tagente_field,
@ -1654,6 +1652,7 @@ function events_get_all(
FROM %s
%s
%s
%s
%s JOIN %s ta
ON ta.%s = te.id_agente
%s
@ -1671,6 +1670,7 @@ function events_get_all(
$tevento,
$event_lj,
$agentmodule_join,
$event_comment_join,
$tagente_join,
$tagente_table,
$tagente_field,
@ -2238,90 +2238,17 @@ function events_comment(
$first_event = reset($id_event);
}
$sql = sprintf(
'SELECT user_comment
FROM tevento
WHERE id_evento = %d',
$first_event
);
$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(
// Update comment.
$ret = db_process_sql_insert(
'tevent_comment',
[
"\n",
'&#x0a;',
'id_event' => $first_event,
'comment' => $comment,
'action' => $action,
'utimestamp' => time(),
'id_user' => $config['id_user'],
],
'<br>',
$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"], '<br>', $comment);
if ($comment !== '') {
$commentbox = '<div class="comment_box">'.io_safe_input($comment).'</div>';
} 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 = '<b>-- '.$action.' by '.$config['id_user'].' ['.date($config['date_format']).'] --</b><br>'.$commentbox.'<br>';
// 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;
@ -2407,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();
@ -2428,7 +2356,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,
@ -2436,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,
@ -5059,8 +4986,12 @@ function events_page_general($event)
}
$data[1] = $user_ack.'&nbsp;(&nbsp;';
// 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'],
@ -5216,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;
@ -5227,12 +5158,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 +5167,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", '&#x0a;'], '<br>', $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", '&#x0a;'], '<br>', $comments);
// If comments are not stored in json, the format is old.
@ -5291,75 +5175,69 @@ function events_page_comments($event, $ajax=false, $groupedComments=[])
}
foreach ($comments_array as $comm) {
$comments_format = (empty($comm) === true && is_array($comments) === false) ? 'old' : 'new';
switch ($comments_format) {
case 'new':
foreach ($comm as $c) {
$eventIdExplanation = (empty($groupedComments) === false) ? sprintf(' (#%d)', $c['event_id']) : '';
$eventIdExplanation = (empty($groupedComments) === false) ? sprintf(' (#%d)', $comm['id_event']) : '';
$data[0] = sprintf(
'<b>%s %s %s%s</b>',
$c['action'],
$comm['action'],
__('by'),
get_user_fullname(io_safe_input($c['id_user'])).' ('.io_safe_input($c['id_user']).')',
get_user_fullname(io_safe_input($comm['id_user'])).' ('.io_safe_input($comm['id_user']).')',
$eventIdExplanation
);
$data[0] .= sprintf(
'<br><br><i>%s</i>',
date($config['date_format'], $c['utimestamp'])
date($config['date_format'], $comm['utimestamp'])
);
$data[1] = '<p class="break_word">'.stripslashes(str_replace(['\n', '\r'], '<br/>', $c['comment'])).'</p>';
$data[1] = '<p class="break_word">'.stripslashes(str_replace(['\n', '\r'], '<br/>', $comm['comment'])).'</p>';
$table_comments->data[] = $data;
}
break;
case 'old':
$comm = explode('<br>', $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\>/', '</i>', $row_text);
$row_text = preg_replace('/\[/', '</b><br><br><i>[', $row_text);
$row_text = preg_replace('/[\[|\]]/', '', $row_text);
break;
case 1:
$row_text = preg_replace("/[\r\n|\r|\n]/", '<br>', io_safe_output(strip_tags($c)));
break;
default:
// Ignore.
break;
}
$data[$col] = $row_text;
$comments_filter = '<div class="flex align-center">';
$comments_filter .= html_print_label_input_block(
null,
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') ],
)
);
$col++;
if ($col == 2) {
$col = 0;
$table_comments->data[] = $data;
$data = [];
}
}
break;
default:
// Ignore.
break;
}
}
}
$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 mrgn_lft_15px',
'icon' => 'search',
'onclick' => 'get_table_events_tabs("'.$eventb64.'","'.$filterb64.'")',
],
true
);
$comments_filter .= '</div>';
if (((tags_checks_event_acl(
$config['id_user'],
@ -5386,7 +5264,10 @@ function events_page_comments($event, $ajax=false, $groupedComments=[])
true
);
$comments_form .= '<br><div class="right mrgn_top_10px">';
$comments_form .= '<br>';
$comments_form .= '<div class="mrgn_top_10px container-filter-buttons">';
$comments_form .= $comments_filter;
$comments_form .= '<div>';
$comments_form .= html_print_button(
__('Add comment'),
'comment_button',
@ -5398,14 +5279,15 @@ function events_page_comments($event, $ajax=false, $groupedComments=[])
],
true
);
$comments_form .= '</div><br></div>';
$comments_form .= '</div>';
$comments_form .= '</div>';
$comments_form .= '<br></div>';
} else {
$comments_form = $comments_filter;
}
if ($ajax === true) {
return $comments_form.html_print_table($table_comments, true);
}
return '<div id="extended_event_comments_page" class="extended_event_pages">'.$comments_form.html_print_table($table_comments, true).'</div>';
}
@ -5540,7 +5422,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 +5994,179 @@ 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, $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']
);
} 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)
);
}
}
$mode = (int) $filter['group_rep'];
$eventsGrouped = [];
// Consider if the event is grouped.
if ($mode === EVENT_GROUP_REP_EVENTS) {
// Default grouped message filtering (evento and estado).
$whereGrouped[] = sprintf(
'AND `tevento`.`evento` = "%s"',
io_safe_input(io_safe_output($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(
'AND `tevento`.`id_extra` = "%s"',
io_safe_input(io_safe_output($event['id_extra']))
);
} else {
$whereGrouped[] = sprintf('AND `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 1=1 %s
ORDER BY tevent_comment.utimestamp DESC',
implode(' ', $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.
*
* @return string Comment.
*/
function event_get_last_comment($event, $filter)
{
$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"',
$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;
}

View File

@ -2162,7 +2162,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']);
@ -2188,6 +2189,7 @@ function html_print_extended_select_for_time(
$selected = 300;
}
if (empty($units) === true) {
$units = [
1 => __('seconds'),
SECONDS_1MINUTE => __('minutes'),
@ -2197,6 +2199,7 @@ function html_print_extended_select_for_time(
SECONDS_1MONTH => __('months'),
SECONDS_1YEAR => __('years'),
];
}
if ($unique_name === true) {
$uniq_name = uniqid($name);

View File

@ -7091,59 +7091,32 @@ function ui_print_comments($comments, $truncate_limit=255)
{
global $config;
$comments = explode('<br>', $comments);
$comments = str_replace(["\n", '&#x0a;'], '<br>', $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'];
}
$tip_comment = '';
$short_comment = substr($last_comment['comment'], 0, 20);
$short_comment = substr($comment['comment'], 0, 20);
if ($config['prominent_time'] == 'timestamp') {
$comentario = '<i>'.date($config['date_format'], $last_comment['utimestamp']).'&nbsp;('.$last_comment['id_user'].'):&nbsp;'.$last_comment['comment'].'';
$tip_comment = date($config['date_format'], $last_comment['utimestamp']).'('.$last_comment['id_user'].'): '.$last_comment['comment'];
$comentario = '<i>'.date($config['date_format'], $comment['utimestamp']).'&nbsp;('.$comment['id_user'].'):&nbsp;'.$comment['comment'].'';
if (strlen($comentario) > '200px' && $truncate_limit >= 255) {
$comentario = '<i>'.date($config['date_format'], $last_comment['utimestamp']).'&nbsp;('.$last_comment['id_user'].'):&nbsp;'.$short_comment.'...';
$comentario = '<i>'.date($config['date_format'], $comment['utimestamp']).'&nbsp;('.$comment['id_user'].'):&nbsp;'.$short_comment.'...';
}
} else {
$rest_time = (time() - $last_comment['utimestamp']);
$rest_time = (time() - $comment['utimestamp']);
$time_last = (($rest_time / 60) / 60);
$comentario = '<i>'.number_format($time_last, 0, $config['decimal_separator'], ($config['thousand_separator'] ?? ',')).'&nbsp; Hours &nbsp;('.$last_comment['id_user'].'):&nbsp;'.$last_comment['comment'].'</i>';
$tip_comment = number_format($time_last, 0, $config['decimal_separator'], ($config['thousand_separator'] ?? ',')).' Hours ('.$last_comment['id_user'].'): '.$last_comment['comment'];
$comentario = '<i>'.number_format($time_last, 0, $config['decimal_separator'], ($config['thousand_separator'] ?? ',')).'&nbsp; Hours &nbsp;('.$comment['id_user'].'):&nbsp;'.$comment['comment'].'';
if (strlen($comentario) > '200px' && $truncate_limit >= 255) {
$comentario = '<i>'.number_format($time_last, 0, $config['decimal_separator'], ($config['thousand_separator'] ?? ',')).'&nbsp; Hours &nbsp;('.$last_comment['id_user'].'):&nbsp;'.$short_comment.'...';
$comentario = '<i>'.number_format($time_last, 0, $config['decimal_separator'], ($config['thousand_separator'] ?? ',')).'&nbsp; Hours &nbsp;('.$comment['id_user'].'):&nbsp;'.$short_comment.'...';
}
}

View File

@ -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();
}
});
@ -1448,6 +1448,25 @@ 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);
}
});
}
// Define the minimize button functionality;
function hidden_dialog(dialog) {
setTimeout(function() {

View File

@ -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(
[

View File

@ -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;
}

View File

@ -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;

View File

@ -485,22 +485,16 @@ class Events
$event['tags'] = '<i>'.__('N/A').'</i>';
}
$event_comments = db_get_value(
'user_comment',
'tevento',
'id_evento',
$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 = '<i>'.__('N/A').'</i>';
} else {
$comment = '';
$comment = '<div>';
$event_comments_array = array_reverse(
$event_comments_array
);
@ -521,6 +515,8 @@ class Events
);
$comment .= '<br>'.$c['comment'].'<br>';
}
$comment .= '</div>';
}
$event['comments'] = $comment;

View File

@ -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%'";
}

View File

@ -333,7 +333,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']
@ -375,13 +375,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') {
@ -469,7 +462,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;
@ -658,25 +651,13 @@ if (is_ajax() === true) {
$tmp->evento = $event_text;
$tmp->b64 = base64_encode(json_encode($tmp));
$tmp->evento = $aux_event;
// Show comments events.
if (empty($tmp->comments) === false) {
$tmp->user_comment = $tmp->comments;
if ($tmp->comments !== 'undefined' && strlen($tmp->comments) > 80) {
$tmp->user_comment .= '&nbsp;&nbsp;';
$tmp->user_comment .= '<a id="show_comments" href="javascript:" onclick="show_event_dialog(\'';
$tmp->user_comment .= $tmp->b64;
$tmp->user_comment .= '\',\'comments\')>;';
$tmp->user_comment .= html_print_image(
'images/details.svg',
true,
[
'title' => __('Show more'),
'class' => 'invert_filter main_menu_icon',
]
$tmp->user_comment = ui_print_comments(
event_get_last_comment(
$item,
$filter
)
);
$tmp->user_comment .= '</a>';
}
}
// Grouped events.
if (isset($tmp->max_id_evento) === true
@ -747,9 +728,16 @@ if (is_ajax() === true) {
$evn = '<a href="javascript:" onclick="show_event_dialog(\''.$tmp->b64.'\')">';
// 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 > 1) {
$evn .= '('.$counter_extra_id.') ';
}
} else {
if (isset($tmp->event_rep) === true && $tmp->event_rep > 1) {
$evn .= '('.$tmp->event_rep.') ';
}
}
$evn .= $tmp->evento.'</a>';
@ -2558,12 +2546,9 @@ try {
];
}
$user_comment = array_search('user_comment', $fields);
if ($user_comment !== false) {
$fields[$user_comment] = [
'text' => 'user_comment',
'class' => 'mw100px',
];
$comment_id = array_search('user_comment', $fields);
if ($comment_id !== false) {
$fields[$comment_id] = ['text' => 'user_comment'];
}

View File

@ -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',

View File

@ -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',

View File

@ -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`
-- ---------------------------------------------------------------------

View File

@ -4098,17 +4098,12 @@ 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));
$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);
@ -4122,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;
}
}
@ -4134,8 +4130,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 '');
@ -4143,7 +4144,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

View File

@ -4544,7 +4544,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);
}
}
@ -4692,8 +4692,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'};
@ -4724,26 +4722,17 @@ 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);
my $parameters;
$parameters->{'id_event'} = $id_event;
$parameters->{'id_user'} = $user_name;
$parameters->{'utimestamp'} = time();
$parameters->{'action'} = "Added comment";
$parameters->{'comment'} = safe_input($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 $comment_id = db_process_insert($dbh, 'id', 'tevent_comment', $parameters);
return $comment_id;
}
##############################################################################
@ -6708,12 +6697,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;
}
##############################################################################