mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-31 01:35:36 +02:00
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');
|
return __('Failed to retrieve comments');
|
||||||
}
|
}
|
||||||
|
|
||||||
$eventsGrouped = [];
|
$eventsGrouped = event_get_comment($event, $group_rep, $event_rep);
|
||||||
// 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.
|
// End of get_comments.
|
||||||
echo events_page_comments($event, true, $eventsGrouped);
|
echo events_page_comments($event, true, $eventsGrouped);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15744,6 +15744,8 @@ function api_get_cluster_items($cluster_id)
|
|||||||
*/
|
*/
|
||||||
function api_set_create_event_filter($name, $thrash1, $other, $thrash3)
|
function api_set_create_event_filter($name, $thrash1, $other, $thrash3)
|
||||||
{
|
{
|
||||||
|
global $config;
|
||||||
|
|
||||||
if ($name == '') {
|
if ($name == '') {
|
||||||
returnError(
|
returnError(
|
||||||
'The event filter could not be created. Event filter name cannot be left blank.'
|
'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($from) === false) {
|
||||||
if (isset($filter['event_view_hr']) === true && ($filter['event_view_hr'] > 0)) {
|
if (isset($filter['event_view_hr']) === true && ($filter['event_view_hr'] > 0)) {
|
||||||
$sql_filters[] = sprintf(
|
$sql_filters[] = sprintf(
|
||||||
' AND utimestamp > UNIX_TIMESTAMP(now() - INTERVAL %d HOUR) ',
|
' AND te.utimestamp > UNIX_TIMESTAMP(now() - INTERVAL %d HOUR) ',
|
||||||
$filter['event_view_hr']
|
$filter['event_view_hr']
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -1069,7 +1069,6 @@ function events_get_all(
|
|||||||
$array_search = [
|
$array_search = [
|
||||||
'te.id_evento',
|
'te.id_evento',
|
||||||
'lower(te.evento)',
|
'lower(te.evento)',
|
||||||
'lower(te.user_comment)',
|
|
||||||
'lower(te.id_extra)',
|
'lower(te.id_extra)',
|
||||||
'lower(te.source)',
|
'lower(te.source)',
|
||||||
'lower('.$custom_data_search.')',
|
'lower('.$custom_data_search.')',
|
||||||
@ -1106,7 +1105,6 @@ function events_get_all(
|
|||||||
' AND (lower(ta.alias) not like lower("%%%s%%")
|
' AND (lower(ta.alias) not like lower("%%%s%%")
|
||||||
AND te.id_evento not like "%%%s%%"
|
AND te.id_evento not like "%%%s%%"
|
||||||
AND lower(te.evento) not like lower("%%%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.id_extra) not like lower("%%%s%%")
|
||||||
AND lower(te.source) not like lower("%%%s%%") )',
|
AND lower(te.source) not like lower("%%%s%%") )',
|
||||||
array_fill(0, 6, $filter['search_exclude'])
|
array_fill(0, 6, $filter['search_exclude'])
|
||||||
@ -1122,16 +1120,13 @@ function events_get_all(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// User comment.
|
// User comment.
|
||||||
|
$event_comment_join = '';
|
||||||
if (empty($filter['user_comment']) === false) {
|
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(
|
$sql_filters[] = sprintf(
|
||||||
' AND lower(te.user_comment) like lower("%%%s%%") ',
|
' AND (lower(tevent_comment.comment) like lower("%%%s%%")
|
||||||
io_safe_input($filter['user_comment'])
|
OR lower(tevent_comment.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%%") ',
|
|
||||||
$filter['user_comment']
|
$filter['user_comment']
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -1455,7 +1450,7 @@ function events_get_all(
|
|||||||
' LIMIT %d',
|
' LIMIT %d',
|
||||||
$config['max_number_of_events_per_node']
|
$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);
|
$pagination = sprintf(' LIMIT %d OFFSET %d', $limit, $offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1552,36 +1547,20 @@ function events_get_all(
|
|||||||
$group_selects = '';
|
$group_selects = '';
|
||||||
if ($group_by != '') {
|
if ($group_by != '') {
|
||||||
if ($count === false) {
|
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(
|
$group_selects = sprintf(
|
||||||
',COUNT(id_evento) AS event_rep,
|
',COUNT(id_evento) AS event_rep,
|
||||||
%s
|
MAX(te.utimestamp) as timestamp_last,
|
||||||
MAX(utimestamp) as timestamp_last,
|
MIN(te.utimestamp) as timestamp_first,
|
||||||
MIN(utimestamp) as timestamp_first,
|
MAX(id_evento) as max_id_evento'
|
||||||
MAX(id_evento) as max_id_evento',
|
|
||||||
($idx !== false) ? 'GROUP_CONCAT(DISTINCT user_comment SEPARATOR "<br>") AS comments,' : ''
|
|
||||||
);
|
);
|
||||||
|
|
||||||
$group_selects_trans = sprintf(
|
$group_selects_trans = sprintf(
|
||||||
',tmax_event.event_rep,
|
',tmax_event.event_rep,
|
||||||
%s
|
|
||||||
tmax_event.timestamp_last,
|
tmax_event.timestamp_last,
|
||||||
tmax_event.timestamp_first,
|
tmax_event.timestamp_first,
|
||||||
tmax_event.max_id_evento',
|
tmax_event.max_id_evento'
|
||||||
($idx !== false) ? 'tmax_event.comments,' : ''
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} 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
|
if (((int) $filter['group_rep'] === EVENT_GROUP_REP_EVENTS
|
||||||
@ -1596,6 +1575,7 @@ function events_get_all(
|
|||||||
FROM %s
|
FROM %s
|
||||||
%s
|
%s
|
||||||
%s
|
%s
|
||||||
|
%s
|
||||||
%s JOIN %s ta
|
%s JOIN %s ta
|
||||||
ON ta.%s = te.id_agente
|
ON ta.%s = te.id_agente
|
||||||
%s
|
%s
|
||||||
@ -1611,6 +1591,7 @@ function events_get_all(
|
|||||||
ON te.id_evento = tmax_event.max_id_evento
|
ON te.id_evento = tmax_event.max_id_evento
|
||||||
%s
|
%s
|
||||||
%s
|
%s
|
||||||
|
%s
|
||||||
%s JOIN %s ta
|
%s JOIN %s ta
|
||||||
ON ta.%s = te.id_agente
|
ON ta.%s = te.id_agente
|
||||||
%s
|
%s
|
||||||
@ -1625,6 +1606,7 @@ function events_get_all(
|
|||||||
$tevento,
|
$tevento,
|
||||||
$event_lj,
|
$event_lj,
|
||||||
$agentmodule_join,
|
$agentmodule_join,
|
||||||
|
$event_comment_join,
|
||||||
$tagente_join,
|
$tagente_join,
|
||||||
$tagente_table,
|
$tagente_table,
|
||||||
$tagente_field,
|
$tagente_field,
|
||||||
@ -1638,6 +1620,7 @@ function events_get_all(
|
|||||||
$having,
|
$having,
|
||||||
$event_lj,
|
$event_lj,
|
||||||
$agentmodule_join,
|
$agentmodule_join,
|
||||||
|
$event_comment_join,
|
||||||
$tagente_join,
|
$tagente_join,
|
||||||
$tagente_table,
|
$tagente_table,
|
||||||
$tagente_field,
|
$tagente_field,
|
||||||
@ -1654,6 +1637,7 @@ function events_get_all(
|
|||||||
FROM %s
|
FROM %s
|
||||||
%s
|
%s
|
||||||
%s
|
%s
|
||||||
|
%s
|
||||||
%s JOIN %s ta
|
%s JOIN %s ta
|
||||||
ON ta.%s = te.id_agente
|
ON ta.%s = te.id_agente
|
||||||
%s
|
%s
|
||||||
@ -1671,6 +1655,7 @@ function events_get_all(
|
|||||||
$tevento,
|
$tevento,
|
||||||
$event_lj,
|
$event_lj,
|
||||||
$agentmodule_join,
|
$agentmodule_join,
|
||||||
|
$event_comment_join,
|
||||||
$tagente_join,
|
$tagente_join,
|
||||||
$tagente_table,
|
$tagente_table,
|
||||||
$tagente_field,
|
$tagente_field,
|
||||||
@ -2238,90 +2223,17 @@ function events_comment(
|
|||||||
$first_event = reset($id_event);
|
$first_event = reset($id_event);
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql = sprintf(
|
// Update comment.
|
||||||
'SELECT user_comment
|
$ret = db_process_sql_insert(
|
||||||
FROM tevento
|
'tevent_comment',
|
||||||
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(
|
|
||||||
[
|
[
|
||||||
"\n",
|
'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)) {
|
if (($ret === false) || ($ret === 0)) {
|
||||||
return false;
|
return false;
|
||||||
@ -5059,8 +4971,12 @@ function events_page_general($event)
|
|||||||
}
|
}
|
||||||
|
|
||||||
$data[1] = $user_ack.' ( ';
|
$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
|
if ($event['ack_utimestamp_raw'] !== false
|
||||||
&& $event['ack_utimestamp_raw'] !== 'false'
|
&& $event['ack_utimestamp_raw'] !== 'false'
|
||||||
|
&& empty($event['ack_utimestamp_raw']) === false
|
||||||
) {
|
) {
|
||||||
$data[1] .= date(
|
$data[1] .= date(
|
||||||
$config['date_format'],
|
$config['date_format'],
|
||||||
@ -5227,12 +5143,7 @@ function events_page_comments($event, $ajax=false, $groupedComments=[])
|
|||||||
$table_comments->head = [];
|
$table_comments->head = [];
|
||||||
$table_comments->class = 'table_modal_alternate';
|
$table_comments->class = 'table_modal_alternate';
|
||||||
|
|
||||||
if (isset($event['user_comment']) === false) {
|
$comments = $groupedComments;
|
||||||
$event['user_comment'] = '';
|
|
||||||
}
|
|
||||||
|
|
||||||
$comments = (empty($groupedComments) === true) ? $event['user_comment'] : $groupedComments;
|
|
||||||
|
|
||||||
if (empty($comments) === true) {
|
if (empty($comments) === true) {
|
||||||
$table_comments->style[0] = 'text-align:left;';
|
$table_comments->style[0] = 'text-align:left;';
|
||||||
$table_comments->colspan[0][0] = 2;
|
$table_comments->colspan[0][0] = 2;
|
||||||
@ -5241,49 +5152,7 @@ function events_page_comments($event, $ajax=false, $groupedComments=[])
|
|||||||
$table_comments->data[] = $data;
|
$table_comments->data[] = $data;
|
||||||
} else {
|
} else {
|
||||||
if (is_array($comments) === true) {
|
if (is_array($comments) === true) {
|
||||||
$comments_array = [];
|
$comments_array = $comments;
|
||||||
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;
|
|
||||||
} else {
|
} else {
|
||||||
$comments = str_replace(["\n", '
'], '<br>', $comments);
|
$comments = str_replace(["\n", '
'], '<br>', $comments);
|
||||||
// If comments are not stored in json, the format is old.
|
// If comments are not stored in json, the format is old.
|
||||||
@ -5291,74 +5160,24 @@ function events_page_comments($event, $ajax=false, $groupedComments=[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
foreach ($comments_array as $comm) {
|
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']) : '';
|
||||||
|
|
||||||
switch ($comments_format) {
|
|
||||||
case 'new':
|
|
||||||
foreach ($comm as $c) {
|
|
||||||
$eventIdExplanation = (empty($groupedComments) === false) ? sprintf(' (#%d)', $c['event_id']) : '';
|
|
||||||
|
|
||||||
$data[0] = sprintf(
|
$data[0] = sprintf(
|
||||||
'<b>%s %s %s%s</b>',
|
'<b>%s %s %s%s</b>',
|
||||||
$c['action'],
|
$comm['action'],
|
||||||
__('by'),
|
__('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
|
$eventIdExplanation
|
||||||
);
|
);
|
||||||
|
|
||||||
$data[0] .= sprintf(
|
$data[0] .= sprintf(
|
||||||
'<br><br><i>%s</i>',
|
'<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;
|
$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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (((tags_checks_event_acl(
|
if (((tags_checks_event_acl(
|
||||||
@ -5540,7 +5359,7 @@ function events_get_sql_order($sort_field='timestamp', $sort='DESC', $group_rep=
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 'comment':
|
case 'comment':
|
||||||
$sort_field_translated = 'user_comment';
|
$sort_field_translated = 'tevent_comment.comment';
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'extra_id':
|
case 'extra_id':
|
||||||
@ -6112,3 +5931,108 @@ function get_count_event_criticity(
|
|||||||
|
|
||||||
return db_get_all_rows_sql($sql_meta);
|
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.
|
* @return string HTML string with the last comment of the events.
|
||||||
*/
|
*/
|
||||||
function ui_print_comments($comments)
|
function ui_print_comments($comment)
|
||||||
{
|
{
|
||||||
global $config;
|
global $config;
|
||||||
|
|
||||||
$comments = explode('<br>', $comments);
|
if (empty($comment) === true) {
|
||||||
$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) {
|
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only show the last comment. If commment its too long,the comment will short with ...
|
// 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.
|
// If $config['prominent_time'] is timestamp the date show Month, day, hour and minutes.
|
||||||
// Else show comments hours ago
|
// Else show comments hours ago
|
||||||
if ($last_comment['action'] != 'Added comment') {
|
if ($comment['action'] != 'Added comment') {
|
||||||
$last_comment['comment'] = $last_comment['action'];
|
$comment['comment'] = $comment['action'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$short_comment = substr($last_comment['comment'], 0, 20);
|
$short_comment = substr($comment['comment'], 0, 20);
|
||||||
if ($config['prominent_time'] == 'timestamp') {
|
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') {
|
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 {
|
} else {
|
||||||
$rest_time = (time() - $last_comment['utimestamp']);
|
$rest_time = (time() - $comment['utimestamp']);
|
||||||
$time_last = (($rest_time / 60) / 60);
|
$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') {
|
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['eventType'] = \get_parameter('eventType', 0);
|
||||||
$values['maxHours'] = \get_parameter('maxHours', 8);
|
$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['eventStatus'] = \get_parameter('eventStatus', -1);
|
||||||
$values['severity'] = \get_parameter_switch('severity', -1);
|
$values['severity'] = \get_parameter_switch('severity', -1);
|
||||||
$values['groupId'] = \get_parameter_switch('groupId', []);
|
$values['groupId'] = \get_parameter_switch('groupId', []);
|
||||||
@ -708,6 +708,10 @@ class EventsListWidget extends Widget
|
|||||||
$hash = get_parameter('auth_hash', '');
|
$hash = get_parameter('auth_hash', '');
|
||||||
$id_user = get_parameter('id_user', '');
|
$id_user = get_parameter('id_user', '');
|
||||||
|
|
||||||
|
if ($this->values['limit'] === 'null') {
|
||||||
|
$this->values['limit'] = $config['block_size'];
|
||||||
|
}
|
||||||
|
|
||||||
// Print datatable.
|
// Print datatable.
|
||||||
$output .= ui_print_datatable(
|
$output .= ui_print_datatable(
|
||||||
[
|
[
|
||||||
|
@ -496,6 +496,10 @@ table.event_details td.cell_event_name {
|
|||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
table.event_details td.cell_event_comments {
|
||||||
|
height: auto;
|
||||||
|
}
|
||||||
|
|
||||||
#validate_button {
|
#validate_button {
|
||||||
margin: 10px auto;
|
margin: 10px auto;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
|
@ -485,22 +485,16 @@ class Events
|
|||||||
$event['tags'] = '<i>'.__('N/A').'</i>';
|
$event['tags'] = '<i>'.__('N/A').'</i>';
|
||||||
}
|
}
|
||||||
|
|
||||||
$event_comments = db_get_value(
|
$event_comments_array = db_get_all_rows_sql(
|
||||||
'user_comment',
|
sprintf(
|
||||||
'tevento',
|
'SELECT * FROM tevent_comment where id_event = %d',
|
||||||
'id_evento',
|
|
||||||
$id_event
|
$id_event
|
||||||
|
)
|
||||||
);
|
);
|
||||||
$event_comments_array = [];
|
|
||||||
$event_comments_array = json_decode(
|
|
||||||
$event_comments,
|
|
||||||
true
|
|
||||||
);
|
|
||||||
// Support for new format only.
|
|
||||||
if (empty($event_comments_array) === true) {
|
if (empty($event_comments_array) === true) {
|
||||||
$comment = '<i>'.__('N/A').'</i>';
|
$comment = '<i>'.__('N/A').'</i>';
|
||||||
} else {
|
} else {
|
||||||
$comment = '';
|
$comment = '<div>';
|
||||||
$event_comments_array = array_reverse(
|
$event_comments_array = array_reverse(
|
||||||
$event_comments_array
|
$event_comments_array
|
||||||
);
|
);
|
||||||
@ -521,6 +515,8 @@ class Events
|
|||||||
);
|
);
|
||||||
$comment .= '<br>'.$c['comment'].'<br>';
|
$comment .= '<br>'.$c['comment'].'<br>';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$comment .= '</div>';
|
||||||
}
|
}
|
||||||
|
|
||||||
$event['comments'] = $comment;
|
$event['comments'] = $comment;
|
||||||
|
@ -223,10 +223,6 @@ if ($id_extra != '') {
|
|||||||
$sql_post .= " AND id_extra LIKE '%$id_extra%'";
|
$sql_post .= " AND id_extra LIKE '%$id_extra%'";
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($user_comment != '') {
|
|
||||||
$sql_post .= " AND user_comment LIKE '%$user_comment%'";
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($source != '') {
|
if ($source != '') {
|
||||||
$sql_post .= " AND source LIKE '%$source%'";
|
$sql_post .= " AND source LIKE '%$source%'";
|
||||||
}
|
}
|
||||||
|
@ -330,7 +330,7 @@ if (is_ajax() === true) {
|
|||||||
$groupRecursion = (bool) get_parameter('groupRecursion', false);
|
$groupRecursion = (bool) get_parameter('groupRecursion', false);
|
||||||
|
|
||||||
// Datatables offset, limit.
|
// Datatables offset, limit.
|
||||||
$start = get_parameter('start', 0);
|
$start = (int) get_parameter('start', 0);
|
||||||
$length = get_parameter(
|
$length = get_parameter(
|
||||||
'length',
|
'length',
|
||||||
$config['block_size']
|
$config['block_size']
|
||||||
@ -368,13 +368,6 @@ if (is_ajax() === true) {
|
|||||||
'ta.direccion',
|
'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);
|
$order = get_datatable_order(true);
|
||||||
|
|
||||||
if (is_array($order) === true && $order['field'] === 'mini_severity') {
|
if (is_array($order) === true && $order['field'] === 'mini_severity') {
|
||||||
@ -462,7 +455,7 @@ if (is_ajax() === true) {
|
|||||||
|
|
||||||
$data = array_reduce(
|
$data = array_reduce(
|
||||||
$events,
|
$events,
|
||||||
function ($carry, $item) use ($table_id, &$redirection_form_id) {
|
function ($carry, $item) use ($table_id, &$redirection_form_id, $filter) {
|
||||||
global $config;
|
global $config;
|
||||||
|
|
||||||
$tmp = (object) $item;
|
$tmp = (object) $item;
|
||||||
@ -504,10 +497,6 @@ if (is_ajax() === true) {
|
|||||||
$tmp->module_name = io_safe_output($tmp->module_name);
|
$tmp->module_name = io_safe_output($tmp->module_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($tmp->comments) === false) {
|
|
||||||
$tmp->comments = ui_print_comments($tmp->comments);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Show last event.
|
// Show last event.
|
||||||
if (isset($tmp->max_id_evento) === true
|
if (isset($tmp->max_id_evento) === true
|
||||||
&& $tmp->max_id_evento !== $tmp->id_evento
|
&& $tmp->max_id_evento !== $tmp->id_evento
|
||||||
@ -582,25 +571,13 @@ if (is_ajax() === true) {
|
|||||||
|
|
||||||
$tmp->b64 = base64_encode(json_encode($tmp));
|
$tmp->b64 = base64_encode(json_encode($tmp));
|
||||||
|
|
||||||
// Show comments events.
|
$tmp->user_comment = ui_print_comments(
|
||||||
if (empty($tmp->comments) === false) {
|
event_get_last_comment(
|
||||||
$tmp->user_comment = $tmp->comments;
|
$item,
|
||||||
if ($tmp->comments !== 'undefined' && strlen($tmp->comments) > 80) {
|
$filter['group_rep'],
|
||||||
$tmp->user_comment .= ' ';
|
$item['event_rep']
|
||||||
$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>';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Grouped events.
|
// Grouped events.
|
||||||
if (isset($tmp->max_id_evento) === true
|
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.'\')">';
|
$evn = '<a href="javascript:" onclick="show_event_dialog(\''.$tmp->b64.'\')">';
|
||||||
|
|
||||||
// Grouped events.
|
// 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) {
|
if (isset($tmp->event_rep) === true && $tmp->event_rep > 1) {
|
||||||
$evn .= '('.$tmp->event_rep.') ';
|
$evn .= '('.$tmp->event_rep.') ';
|
||||||
}
|
}
|
||||||
@ -2427,10 +2408,7 @@ try {
|
|||||||
|
|
||||||
$comment_id = array_search('user_comment', $fields);
|
$comment_id = array_search('user_comment', $fields);
|
||||||
if ($comment_id !== false) {
|
if ($comment_id !== false) {
|
||||||
$fields[$comment_id] = [
|
$fields[$comment_id] = ['text' => 'user_comment'];
|
||||||
'text' => 'user_comment',
|
|
||||||
'class' => 'nowrap_max180px',
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Always add options column.
|
// Always add options column.
|
||||||
|
@ -237,7 +237,6 @@ $column_names = [
|
|||||||
'id_agentmodule',
|
'id_agentmodule',
|
||||||
'id_alert_am',
|
'id_alert_am',
|
||||||
'criticity',
|
'criticity',
|
||||||
'user_comment',
|
|
||||||
'tags',
|
'tags',
|
||||||
'source',
|
'source',
|
||||||
'id_extra',
|
'id_extra',
|
||||||
@ -266,7 +265,6 @@ $fields = [
|
|||||||
'am.nombre as module_name',
|
'am.nombre as module_name',
|
||||||
'te.id_alert_am',
|
'te.id_alert_am',
|
||||||
'te.criticity',
|
'te.criticity',
|
||||||
'te.user_comment',
|
|
||||||
'te.tags',
|
'te.tags',
|
||||||
'te.source',
|
'te.source',
|
||||||
'te.id_extra',
|
'te.id_extra',
|
||||||
|
@ -70,7 +70,6 @@ $column_names = [
|
|||||||
'id_agentmodule',
|
'id_agentmodule',
|
||||||
'id_alert_am',
|
'id_alert_am',
|
||||||
'criticity',
|
'criticity',
|
||||||
'user_comment',
|
|
||||||
'tags',
|
'tags',
|
||||||
'source',
|
'source',
|
||||||
'id_extra',
|
'id_extra',
|
||||||
@ -99,7 +98,6 @@ if (is_metaconsole() === true) {
|
|||||||
'te.id_agentmodule',
|
'te.id_agentmodule',
|
||||||
'te.id_alert_am',
|
'te.id_alert_am',
|
||||||
'te.criticity',
|
'te.criticity',
|
||||||
'te.user_comment',
|
|
||||||
'te.tags',
|
'te.tags',
|
||||||
'te.source',
|
'te.source',
|
||||||
'te.id_extra',
|
'te.id_extra',
|
||||||
@ -129,7 +127,6 @@ if (is_metaconsole() === true) {
|
|||||||
'am.nombre as module_name',
|
'am.nombre as module_name',
|
||||||
'te.id_alert_am',
|
'te.id_alert_am',
|
||||||
'te.criticity',
|
'te.criticity',
|
||||||
'te.user_comment',
|
|
||||||
'te.tags',
|
'te.tags',
|
||||||
'te.source',
|
'te.source',
|
||||||
'te.id_extra',
|
'te.id_extra',
|
||||||
|
@ -706,7 +706,6 @@ CREATE TABLE IF NOT EXISTS `tevento` (
|
|||||||
`id_agentmodule` INT NOT NULL DEFAULT 0,
|
`id_agentmodule` INT NOT NULL DEFAULT 0,
|
||||||
`id_alert_am` INT NOT NULL DEFAULT 0,
|
`id_alert_am` INT NOT NULL DEFAULT 0,
|
||||||
`criticity` INT UNSIGNED NOT NULL DEFAULT 0,
|
`criticity` INT UNSIGNED NOT NULL DEFAULT 0,
|
||||||
`user_comment` TEXT,
|
|
||||||
`tags` TEXT,
|
`tags` TEXT,
|
||||||
`source` TINYTEXT,
|
`source` TINYTEXT,
|
||||||
`id_extra` TINYTEXT,
|
`id_extra` TINYTEXT,
|
||||||
@ -743,6 +742,20 @@ CREATE TABLE IF NOT EXISTS `tevent_extended` (
|
|||||||
ON UPDATE CASCADE ON DELETE CASCADE
|
ON UPDATE CASCADE ON DELETE CASCADE
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4;
|
) 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`
|
-- Table `tgrupo`
|
||||||
-- ---------------------------------------------------------------------
|
-- ---------------------------------------------------------------------
|
||||||
|
@ -4103,11 +4103,6 @@ sub pandora_event {
|
|||||||
my $timestamp = strftime ("%Y-%m-%d %H:%M:%S", localtime ($utimestamp));
|
my $timestamp = strftime ("%Y-%m-%d %H:%M:%S", localtime ($utimestamp));
|
||||||
$id_agentmodule = 0 unless defined ($id_agentmodule);
|
$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
|
# Validate events with the same event id
|
||||||
if (defined ($id_extra) && $id_extra ne '') {
|
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);
|
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
|
# Create the event
|
||||||
logger($pa_config, "Generating event '$evento' for agent ID $id_agente module ID $id_agentmodule.", 10);
|
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)
|
$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, $comment, $module_tags, $source, $id_extra, $user_name, $critical_instructions, $warning_instructions, $unknown_instructions, $ack_utimestamp, $custom_data, safe_input($module_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
|
# Do not write to the event file
|
||||||
return $event_id if ($pa_config->{'event_file'} eq '');
|
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
|
# Add a header when the event file is created
|
||||||
my $header = undef;
|
my $header = undef;
|
||||||
if (! -f $pa_config->{'event_file'}) {
|
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
|
# 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";
|
print_log "[INFO] Adding event '$event' for agent '$agent_name' \n\n";
|
||||||
|
|
||||||
pandora_event ($conf, $event, $id_group, $id_agent, $severity,
|
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 $csv_separator;
|
||||||
print $event_data->{'criticity'};
|
print $event_data->{'criticity'};
|
||||||
print $csv_separator;
|
print $csv_separator;
|
||||||
print $event_data->{'user_comment'};
|
|
||||||
print $csv_separator;
|
|
||||||
print $event_data->{'tags'};
|
print $event_data->{'tags'};
|
||||||
print $csv_separator;
|
print $csv_separator;
|
||||||
print $event_data->{'source'};
|
print $event_data->{'source'};
|
||||||
@ -4731,26 +4729,17 @@ sub cli_add_event_comment() {
|
|||||||
my $event_name = pandora_get_event_name($dbh, $id_event);
|
my $event_name = pandora_get_event_name($dbh, $id_event);
|
||||||
exist_check($event_name,'event',$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";
|
print_log "[INFO] Adding event comment for event '$id_event'. \n\n";
|
||||||
|
|
||||||
my $decoded_comment;
|
my $parameters;
|
||||||
my $update;
|
$parameters->{'id_event'} = $id_event;
|
||||||
if ($current_comment eq '') {
|
$parameters->{'id_user'} = $user_name;
|
||||||
$update->{'user_comment'} = encode_json \@additional_comment;
|
$parameters->{'utimestamp'} = time();
|
||||||
}
|
$parameters->{'action'} = "Added comment";
|
||||||
else {
|
$parameters->{'comment'} = safe_input($comment);
|
||||||
$decoded_comment = decode_json($current_comment);
|
|
||||||
|
|
||||||
push(@{$decoded_comment}, @additional_comment);
|
my $comment_id = db_process_insert($dbh, 'id', 'tevent_comment', $parameters);
|
||||||
|
return $comment_id;
|
||||||
$update->{'user_comment'} = encode_json($decoded_comment);
|
|
||||||
}
|
|
||||||
|
|
||||||
pandora_update_event_from_hash ($update, 'id_evento', $id_event, $dbh);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
##############################################################################
|
##############################################################################
|
||||||
@ -6703,12 +6692,12 @@ sub pandora_update_event_from_hash ($$$$) {
|
|||||||
# Return event comment given a event id
|
# Return event comment given a event id
|
||||||
##############################################################################
|
##############################################################################
|
||||||
|
|
||||||
sub pandora_get_event_comment($$) {
|
sub pandora_get_event_comments($$) {
|
||||||
my ($dbh,$id_event) = @_;
|
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…
x
Reference in New Issue
Block a user