add filter events comments pandora_enterprise#11387
This commit is contained in:
parent
7a84419f3f
commit
d3412a7ad1
|
@ -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&section=general&pure='.$config['pure'].'">';
|
||||
|
||||
echo '<fieldset class="margin-bottom-10">';
|
||||
|
|
|
@ -92,18 +92,34 @@ $get_id_source_event = get_parameter('get_id_source_event');
|
|||
$node_id = (int) get_parameter('node_id', 0);
|
||||
|
||||
if ($get_comments === true) {
|
||||
$event = get_parameter('event', false);
|
||||
$event_rep = (int) get_parameter_post('event')['event_rep'];
|
||||
$group_rep = (int) get_parameter_post('event')['group_rep'];
|
||||
global $config;
|
||||
$event = json_decode(io_safe_output(base64_decode(get_parameter('event', ''))), true);
|
||||
$filter = json_decode(io_safe_output(base64_decode(get_parameter('filter', ''))), true);
|
||||
|
||||
$default_hour = (int) $filter['event_view_hr'];
|
||||
if (isset($config['max_hours_old_event_comment']) === true
|
||||
&& empty($config['max_hours_old_event_comment']) === false
|
||||
) {
|
||||
$default_hour = (int) $config['max_hours_old_event_comment'];
|
||||
}
|
||||
|
||||
$custom_event_view_hr = (int) get_parameter('custom_event_view_hr', 0);
|
||||
if (empty($custom_event_view_hr) === false) {
|
||||
if ($custom_event_view_hr === -2) {
|
||||
$filter['event_view_hr_cs'] = ($default_hour * 3600);
|
||||
} else {
|
||||
$filter['event_view_hr_cs'] = $custom_event_view_hr;
|
||||
}
|
||||
} else {
|
||||
$filter['event_view_hr_cs'] = ($default_hour * 3600);
|
||||
}
|
||||
|
||||
if ($event === false) {
|
||||
return __('Failed to retrieve comments');
|
||||
}
|
||||
|
||||
$eventsGrouped = event_get_comment($event, $group_rep, $event_rep);
|
||||
|
||||
// End of get_comments.
|
||||
echo events_page_comments($event, true, $eventsGrouped);
|
||||
$eventsGrouped = event_get_comment($event, $filter);
|
||||
echo events_page_comments($event, $eventsGrouped, $filter);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1937,23 +1953,7 @@ if ($get_extended_event) {
|
|||
|
||||
$js .= '});';
|
||||
|
||||
$js .= '
|
||||
$("#link_comments").click(function (){
|
||||
$.post ({
|
||||
url : "ajax.php",
|
||||
data : {
|
||||
page: "include/ajax/events",
|
||||
get_comments: 1,
|
||||
event: '.json_encode($event).',
|
||||
event_rep: '.$event_rep.'
|
||||
},
|
||||
dataType : "html",
|
||||
success: function (data) {
|
||||
$("#extended_event_comments_page").empty();
|
||||
$("#extended_event_comments_page").html(data);
|
||||
}
|
||||
});
|
||||
});';
|
||||
$js .= '$("#link_comments").click(get_table_events_tabs(\''.base64_encode(json_encode($event)).'\',\''.base64_encode(json_encode($filter)).'\'));';
|
||||
|
||||
if (events_has_extended_info($event['id_evento']) === true) {
|
||||
$js .= '
|
||||
|
|
|
@ -398,6 +398,10 @@ function config_update_config()
|
|||
$error_update[] = __('Check conexion interval');
|
||||
}
|
||||
|
||||
if (config_update_value('max_hours_old_event_comment', get_parameter('max_hours_old_event_comment'), true) === false) {
|
||||
$error_update[] = __('Max hours old event comments');
|
||||
}
|
||||
|
||||
if (config_update_value('unique_ip', get_parameter('unique_ip'), true) === false) {
|
||||
$error_update[] = __('Unique IP');
|
||||
}
|
||||
|
@ -2397,6 +2401,10 @@ function config_process_config()
|
|||
config_update_value('check_conexion_interval', 180);
|
||||
}
|
||||
|
||||
if (!isset($config['max_hours_old_event_comment'])) {
|
||||
config_update_value('max_hours_old_event_comment', 48);
|
||||
}
|
||||
|
||||
if (!isset($config['elasticsearch_ip'])) {
|
||||
config_update_value('elasticsearch_ip', '');
|
||||
}
|
||||
|
|
|
@ -613,6 +613,74 @@ function events_update_status($id_evento, $status, $filter=null)
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get filter time.
|
||||
*
|
||||
* @param array $filter Filters.
|
||||
*
|
||||
* @return array conditions.
|
||||
*/
|
||||
function get_filter_date(array $filter)
|
||||
{
|
||||
if (isset($filter['date_from']) === true
|
||||
&& empty($filter['date_from']) === false
|
||||
&& $filter['date_from'] !== '0000-00-00'
|
||||
) {
|
||||
$date_from = $filter['date_from'];
|
||||
}
|
||||
|
||||
if (isset($filter['time_from']) === true) {
|
||||
$time_from = (empty($filter['time_from']) === true) ? '00:00:00' : $filter['time_from'];
|
||||
}
|
||||
|
||||
if (isset($date_from) === true) {
|
||||
if (isset($time_from) === false) {
|
||||
$time_from = '00:00:00';
|
||||
}
|
||||
|
||||
$from = $date_from.' '.$time_from;
|
||||
$sql_filters[] = sprintf(
|
||||
' AND te.utimestamp >= %d',
|
||||
strtotime($from)
|
||||
);
|
||||
}
|
||||
|
||||
if (isset($filter['date_to']) === true
|
||||
&& empty($filter['date_to']) === false
|
||||
&& $filter['date_to'] !== '0000-00-00'
|
||||
) {
|
||||
$date_to = $filter['date_to'];
|
||||
}
|
||||
|
||||
if (isset($filter['time_to']) === true) {
|
||||
$time_to = (empty($filter['time_to']) === true) ? '23:59:59' : $filter['time_to'];
|
||||
}
|
||||
|
||||
if (isset($date_to) === true) {
|
||||
if (isset($time_to) === false) {
|
||||
$time_to = '23:59:59';
|
||||
}
|
||||
|
||||
$to = $date_to.' '.$time_to;
|
||||
$sql_filters[] = sprintf(
|
||||
' AND te.utimestamp <= %d',
|
||||
strtotime($to)
|
||||
);
|
||||
}
|
||||
|
||||
if (isset($from) === false) {
|
||||
if (isset($filter['event_view_hr']) === true && ($filter['event_view_hr'] > 0)) {
|
||||
$sql_filters[] = sprintf(
|
||||
' AND te.utimestamp > UNIX_TIMESTAMP(now() - INTERVAL %d HOUR) ',
|
||||
$filter['event_view_hr']
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $sql_filters;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieve all events filtered.
|
||||
*
|
||||
|
@ -700,60 +768,7 @@ function events_get_all(
|
|||
);
|
||||
}
|
||||
|
||||
if (isset($filter['date_from']) === true
|
||||
&& empty($filter['date_from']) === false
|
||||
&& $filter['date_from'] !== '0000-00-00'
|
||||
) {
|
||||
$date_from = $filter['date_from'];
|
||||
}
|
||||
|
||||
if (isset($filter['time_from']) === true) {
|
||||
$time_from = (empty($filter['time_from']) === true) ? '00:00:00' : $filter['time_from'];
|
||||
}
|
||||
|
||||
if (isset($date_from) === true) {
|
||||
if (isset($time_from) === false) {
|
||||
$time_from = '00:00:00';
|
||||
}
|
||||
|
||||
$from = $date_from.' '.$time_from;
|
||||
$sql_filters[] = sprintf(
|
||||
' AND te.utimestamp >= %d',
|
||||
strtotime($from)
|
||||
);
|
||||
}
|
||||
|
||||
if (isset($filter['date_to']) === true
|
||||
&& empty($filter['date_to']) === false
|
||||
&& $filter['date_to'] !== '0000-00-00'
|
||||
) {
|
||||
$date_to = $filter['date_to'];
|
||||
}
|
||||
|
||||
if (isset($filter['time_to']) === true) {
|
||||
$time_to = (empty($filter['time_to']) === true) ? '23:59:59' : $filter['time_to'];
|
||||
}
|
||||
|
||||
if (isset($date_to) === true) {
|
||||
if (isset($time_to) === false) {
|
||||
$time_to = '23:59:59';
|
||||
}
|
||||
|
||||
$to = $date_to.' '.$time_to;
|
||||
$sql_filters[] = sprintf(
|
||||
' AND te.utimestamp <= %d',
|
||||
strtotime($to)
|
||||
);
|
||||
}
|
||||
|
||||
if (isset($from) === false) {
|
||||
if (isset($filter['event_view_hr']) === true && ($filter['event_view_hr'] > 0)) {
|
||||
$sql_filters[] = sprintf(
|
||||
' AND te.utimestamp > UNIX_TIMESTAMP(now() - INTERVAL %d HOUR) ',
|
||||
$filter['event_view_hr']
|
||||
);
|
||||
}
|
||||
}
|
||||
$sql_filters = get_filter_date($filter);
|
||||
|
||||
if (isset($filter['id_agent']) === true && $filter['id_agent'] > 0) {
|
||||
$sql_filters[] = sprintf(
|
||||
|
@ -5132,7 +5147,7 @@ function events_page_general_acknowledged($event_id)
|
|||
*
|
||||
* @return string HTML.
|
||||
*/
|
||||
function events_page_comments($event, $ajax=false, $groupedComments=[])
|
||||
function events_page_comments($event, $groupedComments=[], $filter=null)
|
||||
{
|
||||
// Comments.
|
||||
global $config;
|
||||
|
@ -5220,11 +5235,58 @@ function events_page_comments($event, $ajax=false, $groupedComments=[])
|
|||
$comments_form .= '</div><br></div>';
|
||||
}
|
||||
|
||||
if ($ajax === true) {
|
||||
return $comments_form.html_print_table($table_comments, true);
|
||||
}
|
||||
$table_filter = new stdClass;
|
||||
$table_filter->width = '100%';
|
||||
$table_filter->class = 'databox filters no_border filter-table-adv';
|
||||
$table_filter->size = [];
|
||||
$table_filter->size[0] = '80%';
|
||||
$table_filter->data = [];
|
||||
$table_filter->data[0][0] = html_print_label_input_block(
|
||||
__('Max. hours old').ui_print_help_tip(__('Hours filter comments'), true),
|
||||
html_print_extended_select_for_time(
|
||||
'comments_events_max_hours_old',
|
||||
$filter['event_view_hr_cs'],
|
||||
'',
|
||||
__('Default'),
|
||||
-2,
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
true,
|
||||
'',
|
||||
false,
|
||||
[
|
||||
SECONDS_1HOUR => __('1 hour'),
|
||||
SECONDS_6HOURS => __('6 hours'),
|
||||
SECONDS_12HOURS => __('12 hours'),
|
||||
SECONDS_1DAY => __('24 hours'),
|
||||
SECONDS_2DAY => __('48 hours'),
|
||||
],
|
||||
'',
|
||||
false,
|
||||
0,
|
||||
[ SECONDS_1HOUR => __('hours') ],
|
||||
)
|
||||
);
|
||||
|
||||
return '<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.
|
||||
*/
|
||||
function event_get_comment($event, $mode, $event_rep)
|
||||
function event_get_comment($event, $filter=null)
|
||||
{
|
||||
$whereGrouped = [];
|
||||
if (empty($filter) === false) {
|
||||
if (isset($filter['event_view_hr_cs']) === true && ($filter['event_view_hr_cs'] > 0)) {
|
||||
$whereGrouped[] = sprintf(
|
||||
' AND tevent_comment.utimestamp > UNIX_TIMESTAMP(now() - INTERVAL %d SECOND) ',
|
||||
$filter['event_view_hr_cs']
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$mode = (int) $filter['group_rep'];
|
||||
|
||||
$eventsGrouped = [];
|
||||
// Consider if the event is grouped.
|
||||
$whereGrouped = '1=1';
|
||||
if ($mode === EVENT_GROUP_REP_EVENTS && $event_rep > 1) {
|
||||
if ($mode === EVENT_GROUP_REP_EVENTS) {
|
||||
// Default grouped message filtering (evento and estado).
|
||||
$whereGrouped = sprintf(
|
||||
'`tevento`.`evento` = "%s"',
|
||||
$whereGrouped[] = sprintf(
|
||||
'AND `tevento`.`evento` = "%s"',
|
||||
$event['evento']
|
||||
);
|
||||
|
||||
// If id_agente is reported, filter the messages by them as well.
|
||||
if ((int) $event['id_agente'] > 0) {
|
||||
$whereGrouped .= sprintf(
|
||||
$whereGrouped[] = sprintf(
|
||||
' AND `tevento`.`id_agente` = %d',
|
||||
(int) $event['id_agente']
|
||||
);
|
||||
}
|
||||
|
||||
if ((int) $event['id_agentmodule'] > 0) {
|
||||
$whereGrouped .= sprintf(
|
||||
$whereGrouped[] = sprintf(
|
||||
' AND `tevento`.`id_agentmodule` = %d',
|
||||
(int) $event['id_agentmodule']
|
||||
);
|
||||
}
|
||||
} else if ($mode === EVENT_GROUP_REP_EXTRAIDS) {
|
||||
$whereGrouped = sprintf(
|
||||
'`tevento`.`id_extra` = "%s"',
|
||||
$whereGrouped[] = sprintf(
|
||||
'AND `tevento`.`id_extra` = "%s"',
|
||||
io_safe_output($event['id_extra'])
|
||||
);
|
||||
} else {
|
||||
$whereGrouped = sprintf('`tevento`.`id_evento` = %d', $event['id_evento']);
|
||||
$whereGrouped[] = sprintf('AND `tevento`.`id_evento` = %d', $event['id_evento']);
|
||||
}
|
||||
|
||||
try {
|
||||
|
@ -5990,9 +6063,9 @@ function event_get_comment($event, $mode, $event_rep)
|
|||
FROM tevento
|
||||
INNER JOIN tevent_comment
|
||||
ON tevento.id_evento = tevent_comment.id_event
|
||||
WHERE %s
|
||||
WHERE 1=1 %s
|
||||
ORDER BY tevent_comment.utimestamp DESC',
|
||||
$whereGrouped
|
||||
implode(' ', $whereGrouped)
|
||||
);
|
||||
|
||||
// Get grouped comments.
|
||||
|
@ -6021,18 +6094,73 @@ function event_get_comment($event, $mode, $event_rep)
|
|||
/**
|
||||
* Last comment for this event.
|
||||
*
|
||||
* @param array $event Info event.
|
||||
* @param integer $mode Mode group by.
|
||||
* @param integer $event_rep Events.
|
||||
* @param array $event Info event.
|
||||
*
|
||||
* @return string Comment.
|
||||
*/
|
||||
function event_get_last_comment($event, $mode, $event_rep)
|
||||
function event_get_last_comment($event, $filter)
|
||||
{
|
||||
$comments = event_get_comment($event, (int) $mode, $event_rep);
|
||||
$comments = event_get_comment($event, $filter);
|
||||
if (empty($comments) === false) {
|
||||
return $comments[0];
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get counter events same extraid.
|
||||
*
|
||||
* @param array $event Event data.
|
||||
* @param array $filters Filters.
|
||||
*
|
||||
* @return integer Counter.
|
||||
*/
|
||||
function event_get_counter_extraId(array $event, ?array $filters)
|
||||
{
|
||||
$counters = 0;
|
||||
|
||||
$where = get_filter_date($filters);
|
||||
|
||||
$where[] = sprintf(
|
||||
'AND `te`.`id_extra` = "%s"',
|
||||
io_safe_output($event['id_extra'])
|
||||
);
|
||||
|
||||
try {
|
||||
if (is_metaconsole() === true
|
||||
&& $event['server_id'] > 0
|
||||
) {
|
||||
$node = new Node($event['server_id']);
|
||||
$node->connect();
|
||||
}
|
||||
|
||||
$sql = sprintf(
|
||||
'SELECT count(*)
|
||||
FROM tevento te
|
||||
WHERE 1=1 %s',
|
||||
implode(' ', $where)
|
||||
);
|
||||
|
||||
// Get grouped comments.
|
||||
$counters = db_get_value_sql($sql);
|
||||
} catch (\Exception $e) {
|
||||
// Unexistent agent.
|
||||
if (is_metaconsole() === true
|
||||
&& $event['server_id'] > 0
|
||||
) {
|
||||
$node->disconnect();
|
||||
}
|
||||
|
||||
$counters = 0;
|
||||
} finally {
|
||||
if (is_metaconsole() === true
|
||||
&& $event['server_id'] > 0
|
||||
) {
|
||||
$node->disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
return $counters;
|
||||
}
|
||||
|
|
|
@ -2161,7 +2161,8 @@ function html_print_extended_select_for_time(
|
|||
$custom_fields=false,
|
||||
$style_icon='',
|
||||
$no_change=false,
|
||||
$allow_zero=0
|
||||
$allow_zero=0,
|
||||
$units=null
|
||||
) {
|
||||
global $config;
|
||||
$admin = is_user_admin($config['id_user']);
|
||||
|
@ -2187,15 +2188,17 @@ function html_print_extended_select_for_time(
|
|||
$selected = 300;
|
||||
}
|
||||
|
||||
$units = [
|
||||
1 => __('seconds'),
|
||||
SECONDS_1MINUTE => __('minutes'),
|
||||
SECONDS_1HOUR => __('hours'),
|
||||
SECONDS_1DAY => __('days'),
|
||||
SECONDS_1WEEK => __('weeks'),
|
||||
SECONDS_1MONTH => __('months'),
|
||||
SECONDS_1YEAR => __('years'),
|
||||
];
|
||||
if (empty($units) === true) {
|
||||
$units = [
|
||||
1 => __('seconds'),
|
||||
SECONDS_1MINUTE => __('minutes'),
|
||||
SECONDS_1HOUR => __('hours'),
|
||||
SECONDS_1DAY => __('days'),
|
||||
SECONDS_1WEEK => __('weeks'),
|
||||
SECONDS_1MONTH => __('months'),
|
||||
SECONDS_1YEAR => __('years'),
|
||||
];
|
||||
}
|
||||
|
||||
if ($unique_name === true) {
|
||||
$uniq_name = uniqid($name);
|
||||
|
|
|
@ -484,7 +484,7 @@ function event_comment(current_event) {
|
|||
success: function() {
|
||||
$("#button-comment_button").removeAttr("disabled");
|
||||
$("#response_loading").hide();
|
||||
$("#link_comments").click();
|
||||
$("#button-filter_comments_button").click();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -1229,3 +1229,22 @@ function removeElement(name_select, id_modal) {
|
|||
.append(option);
|
||||
});
|
||||
}
|
||||
|
||||
function get_table_events_tabs(event, filter) {
|
||||
var custom_event_view_hr = $("#hidden-comments_events_max_hours_old").val();
|
||||
$.post({
|
||||
url: "ajax.php",
|
||||
data: {
|
||||
page: "include/ajax/events",
|
||||
get_comments: 1,
|
||||
event: event,
|
||||
filter: filter,
|
||||
custom_event_view_hr: custom_event_view_hr
|
||||
},
|
||||
dataType: "html",
|
||||
success: function(data) {
|
||||
$("#extended_event_comments_page").empty();
|
||||
$("#extended_event_comments_page").html(data);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -574,8 +574,7 @@ if (is_ajax() === true) {
|
|||
$tmp->user_comment = ui_print_comments(
|
||||
event_get_last_comment(
|
||||
$item,
|
||||
$filter['group_rep'],
|
||||
$item['event_rep']
|
||||
$filter
|
||||
)
|
||||
);
|
||||
|
||||
|
@ -649,11 +648,14 @@ if (is_ajax() === true) {
|
|||
|
||||
// Grouped events.
|
||||
if ((int) $filter['group_rep'] === EVENT_GROUP_REP_EXTRAIDS) {
|
||||
$evn .= '(el contador de extraid iguales) ';
|
||||
}
|
||||
|
||||
if (isset($tmp->event_rep) === true && $tmp->event_rep > 1) {
|
||||
$evn .= '('.$tmp->event_rep.') ';
|
||||
$counter_extra_id = event_get_counter_extraId($item, $filter);
|
||||
if (empty($counter_extra_id) === false && $counter_extra_id > 0) {
|
||||
$evn .= '('.$counter_extra_id.') ';
|
||||
}
|
||||
} else {
|
||||
if (isset($tmp->event_rep) === true && $tmp->event_rep > 1) {
|
||||
$evn .= '('.$tmp->event_rep.') ';
|
||||
}
|
||||
}
|
||||
|
||||
$evn .= $tmp->evento.'</a>';
|
||||
|
|
Loading…
Reference in New Issue