change events user_comment new table tevent_comment pandora_enterprise#11387
This commit is contained in:
parent
1d0eaa2738
commit
200750f90b
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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.'
|
||||
|
|
|
@ -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 "<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,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",
|
||||
'
',
|
||||
],
|
||||
'<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;
|
||||
}
|
||||
|
@ -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", '
'], '<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", '
'], '<br>', $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(
|
||||
'<b>%s %s %s%s</b>',
|
||||
$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(
|
||||
'<br><br><i>%s</i>',
|
||||
date($config['date_format'], $comm['utimestamp'])
|
||||
);
|
||||
|
||||
$data[0] = sprintf(
|
||||
'<b>%s %s %s%s</b>',
|
||||
$c['action'],
|
||||
__('by'),
|
||||
get_user_fullname(io_safe_input($c['id_user'])).' ('.io_safe_input($c['id_user']).')',
|
||||
$eventIdExplanation
|
||||
);
|
||||
$data[1] = '<p class="break_word">'.stripslashes(str_replace(['\n', '\r'], '<br/>', $comm['comment'])).'</p>';
|
||||
|
||||
$data[0] .= sprintf(
|
||||
'<br><br><i>%s</i>',
|
||||
date($config['date_format'], $c['utimestamp'])
|
||||
);
|
||||
|
||||
$data[1] = '<p class="break_word">'.stripslashes(str_replace(['\n', '\r'], '<br/>', $c['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;
|
||||
|
||||
$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 '';
|
||||
}
|
||||
|
|
|
@ -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('<br>', $comments);
|
||||
$comments = str_replace(["\n", '
'], '<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'];
|
||||
}
|
||||
|
||||
$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']).' ('.$last_comment['id_user'].'): '.$last_comment['comment'].'';
|
||||
$comentario = '<i>'.date($config['date_format'], $comment['utimestamp']).' ('.$comment['id_user'].'): '.$comment['comment'].'';
|
||||
|
||||
if (strlen($comentario) > '200px') {
|
||||
$comentario = '<i>'.date($config['date_format'], $last_comment['utimestamp']).' ('.$last_comment['id_user'].'): '.$short_comment.'...';
|
||||
$comentario = '<i>'.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 = '<i>'.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'] ?? ',')).' Hours ('.$comment['id_user'].'): '.$comment['comment'].'';
|
||||
|
||||
if (strlen($comentario) > '200px') {
|
||||
$comentario = '<i>'.number_format($time_last, 0, $config['decimal_separator'], ($config['thousand_separator'] ?? ',')).' Hours ('.$last_comment['id_user'].'): '.$short_comment.'...';
|
||||
$comentario = '<i>'.number_format($time_last, 0, $config['decimal_separator'], ($config['thousand_separator'] ?? ',')).' Hours ('.$comment['id_user'].'): '.$short_comment.'...';
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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(
|
||||
[
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -485,22 +485,16 @@ class Events
|
|||
$event['tags'] = '<i>'.__('N/A').'</i>';
|
||||
}
|
||||
|
||||
$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 = '<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;
|
||||
|
|
|
@ -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%'";
|
||||
}
|
||||
|
|
|
@ -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 .= '<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 .= '</a>';
|
||||
}
|
||||
}
|
||||
$tmp->user_comment = ui_print_comments(
|
||||
event_get_last_comment(
|
||||
$item,
|
||||
$filter['group_rep'],
|
||||
$item['event_rep']
|
||||
)
|
||||
);
|
||||
|
||||
// Grouped events.
|
||||
if (isset($tmp->max_id_evento) === true
|
||||
|
@ -671,6 +648,10 @@ 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) {
|
||||
$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.
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -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`
|
||||
-- ---------------------------------------------------------------------
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
##############################################################################
|
||||
|
|
Loading…
Reference in New Issue