diff --git a/pandora_console/godmode/events/custom_events.php b/pandora_console/godmode/events/custom_events.php index 0bf3b223e2..317a80a57c 100644 --- a/pandora_console/godmode/events/custom_events.php +++ b/pandora_console/godmode/events/custom_events.php @@ -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'); diff --git a/pandora_console/include/constants.php b/pandora_console/include/constants.php index e320db6367..b9feaf5d40 100644 --- a/pandora_console/include/constants.php +++ b/pandora_console/include/constants.php @@ -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. diff --git a/pandora_console/include/functions_events.php b/pandora_console/include/functions_events.php index ee6ec185a5..a534b9e715 100644 --- a/pandora_console/include/functions_events.php +++ b/pandora_console/include/functions_events.php @@ -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, diff --git a/pandora_console/include/functions_ui.php b/pandora_console/include/functions_ui.php index 18ac7a0382..6200ab63e2 100755 --- a/pandora_console/include/functions_ui.php +++ b/pandora_console/include/functions_ui.php @@ -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 = ''; - $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'); diff --git a/pandora_console/include/styles/events.css b/pandora_console/include/styles/events.css index f98e3ff365..13bafabca3 100644 --- a/pandora_console/include/styles/events.css +++ b/pandora_console/include/styles/events.css @@ -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; +} diff --git a/pandora_console/include/styles/tables.css b/pandora_console/include/styles/tables.css index 5450465638..6ded48262b 100644 --- a/pandora_console/include/styles/tables.css +++ b/pandora_console/include/styles/tables.css @@ -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; +} diff --git a/pandora_console/operation/events/events.php b/pandora_console/operation/events/events.php index c2e8f84a34..fdc4d4e4a1 100644 --- a/pandora_console/operation/events/events.php +++ b/pandora_console/operation/events/events.php @@ -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 = '
'; + // Event status. + $active_filters_div .= '
'; + $active_filters_div .= '
'.__('Event status').'
'; + $active_filters_div .= '
'; + 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 .= '
'; + $active_filters_div .= '
'; + + // Max. hours old. + $active_filters_div .= '
'; + $active_filters_div .= '
'.__('Max. hours old').'
'; + $active_filters_div .= '
'; + 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 .= '
'; + $active_filters_div .= '
'; + + // Duplicates. + $active_filters_div .= '
'; + $active_filters_div .= '
'.__('Duplicated').'
'; + $active_filters_div .= '
'; + 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 .= '
'; + $active_filters_div .= '
'; + + // Close. + $active_filters_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 += \'\'; evn = \'
\'; - evn += \'
\'+item.evento+\'
\'; + evn += \'
\'; + evn += item.evento+\'
\'; evn += output; evn += \'
\' item.evento = evn; + item.criticity = \'
\' + text + "
"; // Event type. @@ -1108,9 +1188,19 @@ try { if (item.id_agente > 0) { item.agent_name = \'\' + item.agent_name + \'\'; } - + + if (item.id_agente > 0) { + item.id_agente = \'\' + item.id_agente + \'\'; + } + + if (item.id_grupo == "0") { + item.id_grupo = "'.__('All').'"; + } else { + item.id_grupo = item.group_name; + } item.options = \'button\'; + 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 "
"; +echo "
"; +echo "
"; ?>