wip event view

This commit is contained in:
fbsanchez 2019-06-10 15:18:35 +02:00
parent bb552226a6
commit ef3d299d58
7 changed files with 418 additions and 123 deletions

View File

@ -60,96 +60,12 @@ $fields_selected = explode(',', $config['event_fields']);
$result_selected = [];
// show list of fields selected.
// Show list of fields selected.
if ($fields_selected[0] != '') {
foreach ($fields_selected as $field_selected) {
switch ($field_selected) {
case 'id_evento':
$result = __('Event Id');
break;
case 'evento':
$result = __('Event Name');
break;
case 'id_agente':
$result = __('Agent Name');
break;
case 'id_usuario':
$result = __('User');
break;
case 'id_grupo':
$result = __('Group');
break;
case 'estado':
$result = __('Status');
break;
case 'timestamp':
$result = __('Timestamp');
break;
case 'event_type':
$result = __('Event Type');
break;
case 'id_agentmodule':
$result = __('Module Name');
break;
case 'id_alert_am':
$result = __('Alert');
break;
case 'criticity':
$result = __('Severity');
break;
case 'user_comment':
$result = __('Comment');
break;
case 'tags':
$result = __('Tags');
break;
case 'source':
$result = __('Source');
break;
case 'id_extra':
$result = __('Extra Id');
break;
case 'owner_user':
$result = __('Owner');
break;
case 'ack_utimestamp':
$result = __('ACK Timestamp');
break;
case 'instructions':
$result = __('Instructions');
break;
case 'server_name':
$result = __('Server Name');
break;
case 'data':
$result = __('Data');
break;
case 'module_status':
$result = __('Module Status');
break;
}
$result_selected[$field_selected] = $result;
$result_selected[$field_selected] = events_get_column_name(
$field_selected
);
}
}
@ -177,7 +93,8 @@ $fields_available = [];
$fields_available['id_evento'] = __('Event Id');
$fields_available['evento'] = __('Event Name');
$fields_available['id_agente'] = __('Agent Name');
$fields_available['id_agente'] = __('Agent ID');
$fields_available['agent_name'] = __('Agent Name');
$fields_available['id_usuario'] = __('User');
$fields_available['id_grupo'] = __('Group');
$fields_available['estado'] = __('Status');

View File

@ -39,10 +39,11 @@ define('TIME_FORMAT', 'H:i:s');
define('TIME_FORMAT_JS', 'HH:mm:ss');
// Events state constants.
define('EVENT_ALL', -1);
define('EVENT_NEW', 0);
define('EVENT_VALIDATE', 1);
define('EVENT_PROCESS', 2);
define('EVENT_NO_VALIDATED', 3);
// Agents disabled status.

View File

@ -70,17 +70,112 @@ function events_get_all_fields()
/**
* Creates SQL from filter (array) options.
* Same as events_get_column_names but retrieving only one result.
*
* @param array $filter Filters.
* @param string $field Raw field name.
*
* @return string DB sql filter for where clause.
* @return string Traduction.
*/
function events_sql_db_filter($filter)
function events_get_column_name($field)
{
if (!isset($filter) || is_array($filter)) {
return '';
switch ($field) {
case 'id_evento':
return __('Event Id');
case 'evento':
return __('Event Name');
case 'id_agente':
return __('Agent ID');
case 'agent_name':
return __('Agent name');
case 'agent_alias':
return __('Agent alias');
case 'id_usuario':
return __('User');
case 'id_grupo':
return __('Group');
case 'estado':
return __('Status');
case 'timestamp':
return __('Timestamp');
case 'event_type':
return __('Event Type');
case 'id_agentmodule':
return __('Module Name');
case 'id_alert_am':
return __('Alert');
case 'criticity':
return __('Severity');
case 'user_comment':
return __('Comment');
case 'tags':
return __('Tags');
case 'source':
return __('Source');
case 'id_extra':
return __('Extra Id');
case 'owner_user':
return __('Owner');
case 'ack_utimestamp':
return __('ACK Timestamp');
case 'instructions':
return __('Instructions');
case 'server_name':
return __('Server Name');
case 'data':
return __('Data');
case 'module_status':
return __('Module Status');
case 'options':
return __('Options');
default:
return __($field);
}
}
/**
* Return column names from fields selected.
*
* @param array $fields Array of fields.
*
* @return array Names array.
*/
function events_get_column_names($fields)
{
if (!isset($fields) || !is_array($fields)) {
return [];
}
$names = [];
foreach ($fields as $f) {
$names[] = events_get_column_name($f);
}
return $names;
}
@ -123,7 +218,7 @@ function events_get_all(
}
$sql_filters = [];
if (isset($filter['event_view_hr'])) {
if (isset($filter['event_view_hr']) && ($filter['event_view_hr'] > 0)) {
$sql_filters[] = sprintf(
' AND utimestamp > UNIX_TIMESTAMP(now() - INTERVAL %d HOUR) ',
$filter['event_view_hr']
@ -153,12 +248,79 @@ function events_get_all(
}
if (isset($filter['severity']) && $filter['severity'] > 0) {
switch ($filter['severity']) {
case EVENT_CRIT_MAINTENANCE:
case EVENT_CRIT_INFORMATIONAL:
case EVENT_CRIT_NORMAL:
case EVENT_CRIT_MINOR:
case EVENT_CRIT_WARNING:
case EVENT_CRIT_MAJOR:
case EVENT_CRIT_CRITICAL:
default:
$sql_filters[] = sprintf(
' AND criticity = %d ',
$filter['severity']
);
break;
case EVENT_CRIT_WARNING_OR_CRITICAL:
$sql_filters[] = sprintf(
' AND (criticity = %d OR criticity = %d)',
EVENT_CRIT_WARNING,
EVENT_CRIT_CRITICAL
);
break;
case EVENT_CRIT_NOT_NORMAL:
$sql_filters[] = sprintf(
' AND criticity != %d',
EVENT_CRIT_NORMAL
);
break;
case EVENT_CRIT_OR_NORMAL:
$sql_filters[] = sprintf(
' AND (criticity = %d OR criticity = %d)',
EVENT_CRIT_NORMAL,
EVENT_CRIT_CRITICAL
);
break;
}
}
if (isset($filter['id_group']) && $filter['id_group'] > 0) {
$sql_filters[] = sprintf(
' AND criticity = %d ',
$filter['severity']
' AND id_group = %d ',
$filter['id_group']
);
}
if (isset($filter['status'])) {
switch ($filter['status']) {
case EVENT_ALL:
default:
// Do not filter.
break;
case EVENT_NEW:
case EVENT_VALIDATE:
case EVENT_PROCESS:
$sql_filters[] = sprintf(
' AND estado = %d',
$filter['status']
);
break;
case EVENT_NO_VALIDATED:
$sql_filters[] = sprintf(
' AND (estado = %d OR estado = %d)',
EVENT_NEW,
EVENT_PROCESS
);
break;
}
}
$table = events_get_events_table($meta, $history);
$tevento = sprintf(
'(SELECT *
@ -170,14 +332,28 @@ function events_get_all(
// Reset array sql filters.
$sql_filters = [];
$agent_join_filters = [];
if (!empty($filter['agent_alias'])) {
$sql_filters[] = sprintf(
$agent_join_filters[] = sprintf(
' AND ta.alias = "%s" ',
$filter['agent_alias']
);
}
if (!empty($filter['search'])) {
$sql_filters[] = sprintf(
' AND (lower(ta.alias) like lower("%%%s%%")
OR lower(te.evento) like lower("%%%s%%")
OR lower(te.user_comment) like lower("%%%s%%")
OR lower(te.id_extra) like lower("%%%s%%")
OR lower(te.source) like lower("%%%s%%") )',
$filter['search'],
$filter['search'],
$filter['search']
);
}
$order_by = '';
if (isset($order, $sort_field)) {
$order_by = events_get_sql_order($sort_field, $order);
@ -216,6 +392,15 @@ function events_get_all(
break;
}
$tgrupo_join = 'LEFT';
if (isset($filter['id_group_filter']) && $filter['id_group_filter'] > 0) {
$tgrupo_join = 'INNER';
$tgrupo_join_filters[] = sprintf(
' AND tg.id_grupo = %s',
$filter['id_group_filter']
);
}
// Secondary groups.
db_process_sql('SET group_concat_max_len = 9999999');
$event_lj = events_get_secondary_groups_left_join($table);
@ -223,19 +408,26 @@ function events_get_all(
$sql = sprintf(
'SELECT %s
FROM %s
%s
%s JOIN tagente ta
ON ta.id_agente = te.id_agente
%s
%s
%s
%s JOIN tgrupo tg
ON te.id_grupo = tg.id_grupo
%s
WHERE 1=1
%s
%s
%s
%s
',
join(',', $fields),
$tevento,
$tagente_join,
$event_lj,
$tagente_join,
join(' ', $agent_join_filters),
$tgrupo_join,
join(' ', $tgrupo_join_filters),
join(' ', $sql_filters),
$group_by,
$order_by,

View File

@ -2821,6 +2821,7 @@ function ui_progress(
* ]
* ]
* ],
* 'extra_html' => HTML content to be placed after 'filter' section.
* ]
* End.
*
@ -2863,6 +2864,10 @@ function ui_print_datatable(array $parameters)
$parameters['order']['field'],
$parameters['columns']
);
if (empty($order)) {
$order = 1;
}
}
$order .= ', "'.$parameters['order']['direction'].'"';
@ -3002,6 +3007,12 @@ function ui_print_datatable(array $parameters)
);
}
// Extra html.
$extra = '';
if (isset($parameters['extra_html']) && !empty($parameters['extra_html'])) {
$extra = $parameters['extra_html'];
}
// Base table.
$table = '<table id="'.$table_id.'" ';
$table .= 'class="'.$parameters['class'].'"';
@ -3118,7 +3129,8 @@ function ui_print_datatable(array $parameters)
});
</script>';
$output = $filter.$table.$js;
// Order.
$output = $filter.$extra.$table.$js;
ui_require_css_file('datatables.min', 'include/styles/js/');
ui_require_javascript_file('datatables.min');

View File

@ -146,3 +146,41 @@ fieldset {
.event.flex-row.h100p.nowrap div {
max-width: 98%;
}
.filter_summary {
margin-bottom: 3em;
height: 3em;
}
.filter_summary div.label {
background: #878787;
color: #fff;
font-weight: bolder;
border-radius: 5px;
padding: 0.5em;
}
.filter_summary div.content {
padding: 0.5em;
}
.filter_summary > div {
border: 1px solid #eee;
border-radius: 5px;
}
.filter_summary div {
float: left;
margin-right: 2em;
text-align: center;
background: #fff;
}
#events_processing {
background: #dedede;
font-size: 3em;
height: auto;
padding: 2em;
color: #777;
border: none;
margin-top: -2em;
}

View File

@ -250,3 +250,14 @@ tr.disabled_row_user * {
table.dataTable.info_table.no-footer {
border-bottom: none;
}
/* Datatables pagination */
.dataTables_paginate.paging_simple_numbers {
}
.dataTables_wrapper .dataTables_paginate .paginate_button.current,
.dataTables_wrapper .dataTables_paginate .paginate_button.current:hover {
color: #fff;
background-color: #82b92e;
border-color: #82b92e;
}

View File

@ -66,17 +66,20 @@ $access = ($event_a == true) ? 'ER' : (($event_w == true) ? 'EW' : (($event_m ==
// Load specific stylesheet.
ui_require_css_file('events');
// Load extra javascript.
ui_require_javascript_file('pandora_events');
// Get requests.
$id_group = get_parameter('filter[id_group]');
$event_type = get_parameter('filter[event_type]');
$severity = get_parameter('filter[severity]');
$status = get_parameter('filter[status]');
$status = get_parameter('filter[status]', EVENT_NO_VALIDATED);
$search = get_parameter('filter[search]');
$text_agent = get_parameter('filter[text_agent]');
$id_agent = get_parameter('filter[id_agent]');
$id_agent_module = get_parameter('filter[id_agent_module]');
$pagination = get_parameter('filter[pagination]');
$event_view_hr = get_parameter('filter[event_view_hr]', 8);
$event_view_hr = get_parameter('filter[event_view_hr]', 1);
$id_user_ack = get_parameter('filter[id_user_ack]');
$group_rep = get_parameter('filter[group_rep]');
$tag_with = get_parameter('filter[tag_with]', []);
@ -108,6 +111,7 @@ if (is_ajax()) {
[
'te.*',
'ta.alias as agent_name',
'tg.nombre as group_name',
],
$filter,
// Offset.
@ -920,15 +924,7 @@ $filter .= ui_toggle(
);
try {
$column_names = [
__('Event'),
__('Event ID'),
__('Agent name'),
__('Timestamp'),
__('Severity'),
__('Options'),
];
$fields = [
$default_fields = [
'evento',
'id_evento',
// 'id_agente',
@ -961,6 +957,86 @@ try {
// 'module_name',
'options',
];
$fields = explode(',', $config['event_fields']);
// Always check something is shown.
if (empty($fields)) {
$fields = $default_fields;
}
// Always add options column.
$fields = array_merge($fields, ['options']);
// Get column names.
$column_names = events_get_column_names($fields);
// Open current filter quick reference.
$active_filters_div = '<div class="filter_summary">';
// Event status.
$active_filters_div .= '<div>';
$active_filters_div .= '<div class="label box-shadow">'.__('Event status').'</div>';
$active_filters_div .= '<div id="summary_status" class="content">';
switch ($status) {
case EVENT_ALL:
default:
$active_filters_div .= __('Any status.');
break;
case EVENT_NEW:
$active_filters_div .= __('New events.');
break;
case EVENT_VALIDATE:
$active_filters_div .= __('Validated.');
break;
case EVENT_PROCESS:
$active_filters_div .= __('In proccess.');
break;
case EVENT_NO_VALIDATED:
$active_filters_div .= __('Not validated.');
break;
}
$active_filters_div .= '</div>';
$active_filters_div .= '</div>';
// Max. hours old.
$active_filters_div .= '<div>';
$active_filters_div .= '<div class="label box-shadow">'.__('Max. hours old').'</div>';
$active_filters_div .= '<div id="summary_hours" class="content">';
if ($event_view_hr == 0) {
$active_filters_div .= __('Any time.');
} else if ($event_view_hr == 1) {
$active_filters_div .= __('Last hour.');
} else if ($event_view_hr == 2) {
$active_filters_div .= __('Last %d hours.', $event_view_hr);
}
$active_filters_div .= '</div>';
$active_filters_div .= '</div>';
// Duplicates.
$active_filters_div .= '<div>';
$active_filters_div .= '<div class="label box-shadow">'.__('Duplicated').'</div>';
$active_filters_div .= '<div id="summary_duplicates" class="content">';
if ($group_rep == 0) {
$active_filters_div .= __('All events.');
} else if ($group_rep == 1) {
$active_filters_div .= __('Group events');
} else if ($group_rep == 2) {
$active_filters_div .= __('Group agents.');
}
$active_filters_div .= '</div>';
$active_filters_div .= '</div>';
// Close.
$active_filters_div .= '</div>';
// Print datatable.
ui_print_datatable(
[
'id' => 'events',
@ -968,6 +1044,12 @@ try {
'style' => 'width: 100%;',
'ajax_url' => 'operation/events/events',
'ajax_data' => ['get_events' => 1],
'form' => [
'class' => 'flex-row',
'html' => $filter,
'inputs' => [],
],
'extra_html' => $active_filters_div,
'pagination_options' => [
[
$config['block_size'],
@ -990,11 +1072,6 @@ try {
'All',
],
],
'form' => [
'class' => 'flex-row',
'html' => $filter,
'inputs' => [],
],
'order' => [
'field' => 'timestamp',
'direction' => 'desc',
@ -1003,7 +1080,6 @@ try {
'columns' => $fields,
'ajax_postprocess' => '
function (item) {
item.id_evento = "#"+item.id_evento;
var color = "'.COL_UNKNOWN.'";
var text = "UNKNOWN";
switch (item.criticity) {
@ -1050,11 +1126,15 @@ try {
output += \'</div>\';
evn = \'<div class="event flex-row h100p nowrap">\';
evn += \'<div>\'+item.evento+\'</div>\';
evn += \'<div><a href="javascript:" onclick="show_event_dialog(\';
evn += item.id_evento+\');">\';
evn += item.evento+\'</a></div>\';
evn += output;
evn += \'</div>\'
item.evento = evn;
item.criticity = \'<div class="criticity" style="background: \';
item.criticity += color + \'">\' + text + "</div>";
// Event type.
@ -1108,9 +1188,19 @@ try {
if (item.id_agente > 0) {
item.agent_name = \'<a href="'.ui_get_full_url('index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente=').'\'+item.id_agente+\'">\' + item.agent_name + \'</a>\';
}
if (item.id_agente > 0) {
item.id_agente = \'<a href="'.ui_get_full_url('index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente=').'\'+item.id_agente+\'">\' + item.id_agente + \'</a>\';
}
if (item.id_grupo == "0") {
item.id_grupo = "'.__('All').'";
} else {
item.id_grupo = item.group_name;
}
item.options = \'<a href="#">button</a>\';
item.id_evento = "#"+item.id_evento;
}',
]
);
@ -1130,6 +1220,18 @@ ui_require_jquery_file(
);
// End. Load required JS.
html_print_input_hidden('meta', (int) is_metaconsole());
html_print_input_hidden('history', (int) $history);
html_print_input_hidden('filterid', $is_filter);
html_print_input_hidden(
'ajax_file',
ui_get_full_url('ajax.php', false, false, false)
);
// AJAX call options responses.
echo "<div id='event_details_window'></div>";
echo "<div id='event_response_window'></div>";
echo "<div id='event_response_command_window' title='".__('Parameters')."'></div>";
?>
<script type="text/javascript">
@ -1143,6 +1245,28 @@ var text_none = "<?php echo __('None'); ?>";
var group_agents_id = false;
$(document).ready( function() {
/* Update summary */
$("#status").on("change",function(){
$('#summary_status').html($("#status option:selected").text());
});
$("#text-event_view_hr").on("keyup",function(){
hours = $('#text-event_view_hr').val();
if (hours == '' || hours == 0 ) {
$('#summary_hours').html('<?php echo __('Any'); ?>');
} else if (hours == 1) {
$('#summary_hours').html('<?php echo __('Last hour.'); ?>');
} else {
$('#summary_hours').html(hours + '<?php echo ' '.__('hours.'); ?>');
}
});
$('#group_rep').on("change", function(){
$('#summary_duplicates').html($("#group_rep option:selected").text());
});
/* Summary updates end. */
id_select_destiny = "#tag_with_temp";
id_hidden = "#hidden-tag_with";