add filter events comments pandora_enterprise#11387

This commit is contained in:
daniel 2023-07-10 16:26:33 +02:00
parent 7a84419f3f
commit d3412a7ad1
7 changed files with 289 additions and 118 deletions

View File

@ -743,6 +743,17 @@ $table->data[$i][] = html_print_label_input_block(
) )
); );
$table->data[$i++][] = html_print_label_input_block(
__('Max. hours old events comments'),
html_print_input_number(
[
'name' => 'max_hours_old_event_comment',
'min' => 0,
'value' => $config['max_hours_old_event_comment'],
]
)
);
echo '<form class="max_floating_element_size" id="form_setup" method="post" action="index.php?sec=gsetup&sec2=godmode/setup/setup&amp;section=general&amp;pure='.$config['pure'].'">'; echo '<form class="max_floating_element_size" id="form_setup" method="post" action="index.php?sec=gsetup&sec2=godmode/setup/setup&amp;section=general&amp;pure='.$config['pure'].'">';
echo '<fieldset class="margin-bottom-10">'; echo '<fieldset class="margin-bottom-10">';

View File

@ -92,18 +92,34 @@ $get_id_source_event = get_parameter('get_id_source_event');
$node_id = (int) get_parameter('node_id', 0); $node_id = (int) get_parameter('node_id', 0);
if ($get_comments === true) { if ($get_comments === true) {
$event = get_parameter('event', false); global $config;
$event_rep = (int) get_parameter_post('event')['event_rep']; $event = json_decode(io_safe_output(base64_decode(get_parameter('event', ''))), true);
$group_rep = (int) get_parameter_post('event')['group_rep']; $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) { if ($event === false) {
return __('Failed to retrieve comments'); return __('Failed to retrieve comments');
} }
$eventsGrouped = event_get_comment($event, $group_rep, $event_rep); $eventsGrouped = event_get_comment($event, $filter);
echo events_page_comments($event, $eventsGrouped, $filter);
// End of get_comments.
echo events_page_comments($event, true, $eventsGrouped);
return; return;
} }
@ -1937,23 +1953,7 @@ if ($get_extended_event) {
$js .= '});'; $js .= '});';
$js .= ' $js .= '$("#link_comments").click(get_table_events_tabs(\''.base64_encode(json_encode($event)).'\',\''.base64_encode(json_encode($filter)).'\'));';
$("#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);
}
});
});';
if (events_has_extended_info($event['id_evento']) === true) { if (events_has_extended_info($event['id_evento']) === true) {
$js .= ' $js .= '

View File

@ -398,6 +398,10 @@ function config_update_config()
$error_update[] = __('Check conexion interval'); $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) { if (config_update_value('unique_ip', get_parameter('unique_ip'), true) === false) {
$error_update[] = __('Unique IP'); $error_update[] = __('Unique IP');
} }
@ -2397,6 +2401,10 @@ function config_process_config()
config_update_value('check_conexion_interval', 180); config_update_value('check_conexion_interval', 180);
} }
if (!isset($config['max_hours_old_event_comment'])) {
config_update_value('max_hours_old_event_comment', 48);
}
if (!isset($config['elasticsearch_ip'])) { if (!isset($config['elasticsearch_ip'])) {
config_update_value('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. * Retrieve all events filtered.
* *
@ -700,60 +768,7 @@ function events_get_all(
); );
} }
if (isset($filter['date_from']) === true $sql_filters = get_filter_date($filter);
&& 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']
);
}
}
if (isset($filter['id_agent']) === true && $filter['id_agent'] > 0) { if (isset($filter['id_agent']) === true && $filter['id_agent'] > 0) {
$sql_filters[] = sprintf( $sql_filters[] = sprintf(
@ -5132,7 +5147,7 @@ function events_page_general_acknowledged($event_id)
* *
* @return string HTML. * @return string HTML.
*/ */
function events_page_comments($event, $ajax=false, $groupedComments=[]) function events_page_comments($event, $groupedComments=[], $filter=null)
{ {
// Comments. // Comments.
global $config; global $config;
@ -5220,11 +5235,58 @@ function events_page_comments($event, $ajax=false, $groupedComments=[])
$comments_form .= '</div><br></div>'; $comments_form .= '</div><br></div>';
} }
if ($ajax === true) { $table_filter = new stdClass;
return $comments_form.html_print_table($table_comments, true); $table_filter->width = '100%';
} $table_filter->class = 'databox filters no_border filter-table-adv';
$table_filter->size = [];
$table_filter->size[0] = '80%';
$table_filter->data = [];
$table_filter->data[0][0] = html_print_label_input_block(
__('Max. hours old').ui_print_help_tip(__('Hours filter comments'), true),
html_print_extended_select_for_time(
'comments_events_max_hours_old',
$filter['event_view_hr_cs'],
'',
__('Default'),
-2,
false,
true,
false,
true,
'',
false,
[
SECONDS_1HOUR => __('1 hour'),
SECONDS_6HOURS => __('6 hours'),
SECONDS_12HOURS => __('12 hours'),
SECONDS_1DAY => __('24 hours'),
SECONDS_2DAY => __('48 hours'),
],
'',
false,
0,
[ SECONDS_1HOUR => __('hours') ],
)
);
return '<div id="extended_event_comments_page" class="extended_event_pages">'.$comments_form.html_print_table($table_comments, true).'</div>'; $event = base64_encode(json_encode($event));
$filter = base64_encode(json_encode($filter));
$table_filter->data[0][1] = html_print_submit_button(
__('Filter'),
'filter_comments_button',
false,
[
'class' => 'mini',
'icon' => 'search',
'onclick' => 'get_table_events_tabs("'.$event.'","'.$filter.'")',
],
true
);
$comments_time_input = html_print_table($table_filter, true);
return $comments_form.$comments_time_input.html_print_table($table_comments, true);
} }
@ -5942,39 +6004,50 @@ function get_count_event_criticity(
* *
* @return array Comments. * @return array Comments.
*/ */
function event_get_comment($event, $mode, $event_rep) function event_get_comment($event, $filter=null)
{ {
$whereGrouped = [];
if (empty($filter) === false) {
if (isset($filter['event_view_hr_cs']) === true && ($filter['event_view_hr_cs'] > 0)) {
$whereGrouped[] = sprintf(
' AND tevent_comment.utimestamp > UNIX_TIMESTAMP(now() - INTERVAL %d SECOND) ',
$filter['event_view_hr_cs']
);
}
}
$mode = (int) $filter['group_rep'];
$eventsGrouped = []; $eventsGrouped = [];
// Consider if the event is grouped. // Consider if the event is grouped.
$whereGrouped = '1=1'; if ($mode === EVENT_GROUP_REP_EVENTS) {
if ($mode === EVENT_GROUP_REP_EVENTS && $event_rep > 1) {
// Default grouped message filtering (evento and estado). // Default grouped message filtering (evento and estado).
$whereGrouped = sprintf( $whereGrouped[] = sprintf(
'`tevento`.`evento` = "%s"', 'AND `tevento`.`evento` = "%s"',
$event['evento'] $event['evento']
); );
// If id_agente is reported, filter the messages by them as well. // If id_agente is reported, filter the messages by them as well.
if ((int) $event['id_agente'] > 0) { if ((int) $event['id_agente'] > 0) {
$whereGrouped .= sprintf( $whereGrouped[] = sprintf(
' AND `tevento`.`id_agente` = %d', ' AND `tevento`.`id_agente` = %d',
(int) $event['id_agente'] (int) $event['id_agente']
); );
} }
if ((int) $event['id_agentmodule'] > 0) { if ((int) $event['id_agentmodule'] > 0) {
$whereGrouped .= sprintf( $whereGrouped[] = sprintf(
' AND `tevento`.`id_agentmodule` = %d', ' AND `tevento`.`id_agentmodule` = %d',
(int) $event['id_agentmodule'] (int) $event['id_agentmodule']
); );
} }
} else if ($mode === EVENT_GROUP_REP_EXTRAIDS) { } else if ($mode === EVENT_GROUP_REP_EXTRAIDS) {
$whereGrouped = sprintf( $whereGrouped[] = sprintf(
'`tevento`.`id_extra` = "%s"', 'AND `tevento`.`id_extra` = "%s"',
io_safe_output($event['id_extra']) io_safe_output($event['id_extra'])
); );
} else { } else {
$whereGrouped = sprintf('`tevento`.`id_evento` = %d', $event['id_evento']); $whereGrouped[] = sprintf('AND `tevento`.`id_evento` = %d', $event['id_evento']);
} }
try { try {
@ -5990,9 +6063,9 @@ function event_get_comment($event, $mode, $event_rep)
FROM tevento FROM tevento
INNER JOIN tevent_comment INNER JOIN tevent_comment
ON tevento.id_evento = tevent_comment.id_event ON tevento.id_evento = tevent_comment.id_event
WHERE %s WHERE 1=1 %s
ORDER BY tevent_comment.utimestamp DESC', ORDER BY tevent_comment.utimestamp DESC',
$whereGrouped implode(' ', $whereGrouped)
); );
// Get grouped comments. // Get grouped comments.
@ -6022,17 +6095,72 @@ function event_get_comment($event, $mode, $event_rep)
* Last comment for this event. * Last comment for this event.
* *
* @param array $event Info event. * @param array $event Info event.
* @param integer $mode Mode group by.
* @param integer $event_rep Events.
* *
* @return string Comment. * @return string Comment.
*/ */
function event_get_last_comment($event, $mode, $event_rep) function event_get_last_comment($event, $filter)
{ {
$comments = event_get_comment($event, (int) $mode, $event_rep); $comments = event_get_comment($event, $filter);
if (empty($comments) === false) { if (empty($comments) === false) {
return $comments[0]; return $comments[0];
} }
return ''; return '';
} }
/**
* Get counter events same extraid.
*
* @param array $event Event data.
* @param array $filters Filters.
*
* @return integer Counter.
*/
function event_get_counter_extraId(array $event, ?array $filters)
{
$counters = 0;
$where = get_filter_date($filters);
$where[] = sprintf(
'AND `te`.`id_extra` = "%s"',
io_safe_output($event['id_extra'])
);
try {
if (is_metaconsole() === true
&& $event['server_id'] > 0
) {
$node = new Node($event['server_id']);
$node->connect();
}
$sql = sprintf(
'SELECT count(*)
FROM tevento te
WHERE 1=1 %s',
implode(' ', $where)
);
// Get grouped comments.
$counters = db_get_value_sql($sql);
} catch (\Exception $e) {
// Unexistent agent.
if (is_metaconsole() === true
&& $event['server_id'] > 0
) {
$node->disconnect();
}
$counters = 0;
} finally {
if (is_metaconsole() === true
&& $event['server_id'] > 0
) {
$node->disconnect();
}
}
return $counters;
}

View File

@ -2161,7 +2161,8 @@ function html_print_extended_select_for_time(
$custom_fields=false, $custom_fields=false,
$style_icon='', $style_icon='',
$no_change=false, $no_change=false,
$allow_zero=0 $allow_zero=0,
$units=null
) { ) {
global $config; global $config;
$admin = is_user_admin($config['id_user']); $admin = is_user_admin($config['id_user']);
@ -2187,6 +2188,7 @@ function html_print_extended_select_for_time(
$selected = 300; $selected = 300;
} }
if (empty($units) === true) {
$units = [ $units = [
1 => __('seconds'), 1 => __('seconds'),
SECONDS_1MINUTE => __('minutes'), SECONDS_1MINUTE => __('minutes'),
@ -2196,6 +2198,7 @@ function html_print_extended_select_for_time(
SECONDS_1MONTH => __('months'), SECONDS_1MONTH => __('months'),
SECONDS_1YEAR => __('years'), SECONDS_1YEAR => __('years'),
]; ];
}
if ($unique_name === true) { if ($unique_name === true) {
$uniq_name = uniqid($name); $uniq_name = uniqid($name);

View File

@ -484,7 +484,7 @@ function event_comment(current_event) {
success: function() { success: function() {
$("#button-comment_button").removeAttr("disabled"); $("#button-comment_button").removeAttr("disabled");
$("#response_loading").hide(); $("#response_loading").hide();
$("#link_comments").click(); $("#button-filter_comments_button").click();
} }
}); });
@ -1229,3 +1229,22 @@ function removeElement(name_select, id_modal) {
.append(option); .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);
}
});
}

View File

@ -574,8 +574,7 @@ if (is_ajax() === true) {
$tmp->user_comment = ui_print_comments( $tmp->user_comment = ui_print_comments(
event_get_last_comment( event_get_last_comment(
$item, $item,
$filter['group_rep'], $filter
$item['event_rep']
) )
); );
@ -649,12 +648,15 @@ if (is_ajax() === true) {
// Grouped events. // Grouped events.
if ((int) $filter['group_rep'] === EVENT_GROUP_REP_EXTRAIDS) { if ((int) $filter['group_rep'] === EVENT_GROUP_REP_EXTRAIDS) {
$evn .= '(el contador de extraid iguales) '; $counter_extra_id = event_get_counter_extraId($item, $filter);
if (empty($counter_extra_id) === false && $counter_extra_id > 0) {
$evn .= '('.$counter_extra_id.') ';
} }
} else {
if (isset($tmp->event_rep) === true && $tmp->event_rep > 1) { if (isset($tmp->event_rep) === true && $tmp->event_rep > 1) {
$evn .= '('.$tmp->event_rep.') '; $evn .= '('.$tmp->event_rep.') ';
} }
}
$evn .= $tmp->evento.'</a>'; $evn .= $tmp->evento.'</a>';