From 419a90d69c3f5615b70c11981968ab496a0e0b4d Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Fri, 7 Jun 2019 17:35:13 +0200 Subject: [PATCH] wip event list --- pandora_console/include/functions.php | 41 ++ pandora_console/include/functions_events.php | 27 +- pandora_console/include/functions_html.php | 45 +- pandora_console/include/functions_ui.php | 63 +- pandora_console/include/styles/events.css | 104 +++- pandora_console/include/styles/pandora.css | 4 + pandora_console/operation/events/events.php | 610 +++++++++++++++++-- 7 files changed, 808 insertions(+), 86 deletions(-) diff --git a/pandora_console/include/functions.php b/pandora_console/include/functions.php index f299153da6..991f5ccfcc 100644 --- a/pandora_console/include/functions.php +++ b/pandora_console/include/functions.php @@ -902,6 +902,47 @@ function set_cookie($name, $value) } +/** + * Returns database ORDER clause from datatables AJAX call. + * + * @param boolean $as_array Return as array or as string. + * + * @return string Order or empty. + */ +function get_datatable_order($as_array=false) +{ + $order = get_parameter('order'); + + if (is_array($order)) { + $column = $order[0]['column']; + $direction = $order[0]['dir']; + } + + if (!isset($column) || !isset($direction)) { + return ''; + } + + $columns = get_parameter('columns'); + + if (is_array($columns)) { + $column_name = $columns[$column]['data']; + } + + if (!isset($column_name)) { + return ''; + } + + if ($as_array) { + return [ + 'direction' => $direction, + 'field' => $column_name, + ]; + } + + return $column_name.' '.$direction; +} + + /** * Get a parameter from a request. * diff --git a/pandora_console/include/functions_events.php b/pandora_console/include/functions_events.php index 411267aa2c..f082f8611a 100644 --- a/pandora_console/include/functions_events.php +++ b/pandora_console/include/functions_events.php @@ -69,6 +69,22 @@ function events_get_all_fields() } +/** + * Creates SQL from filter (array) options. + * + * @param array $filter Filters. + * + * @return string DB sql filter for where clause. + */ +function events_sql_db_filter($filter) +{ + if (!isset($filter) || is_array($filter)) { + return ''; + } + +} + + /** * Get all rows of events from the database, that * pass the filter, and can get only some fields. @@ -251,7 +267,8 @@ function events_get_events_grouped( (SELECT criticity FROM %s WHERE id_evento = MAX(te.id_evento)) AS criticity, (SELECT ack_utimestamp FROM %s WHERE id_evento = MAX(te.id_evento)) AS ack_utimestamp, (SELECT nombre FROM tagente_modulo WHERE id_agente_modulo = te.id_agentmodule) AS module_name, - (SELECT alias FROM tagente WHERE id_agente = te.id_agente) agent_name + (SELECT alias FROM tagente WHERE id_agente = te.id_agente) agent_name, + te.id_agente FROM %s te %s WHERE 1=1 %s GROUP BY estado, evento, id_agente, id_agentmodule %s ', @@ -5321,11 +5338,15 @@ function events_get_sql_order($sort_field='timestamp', $sort='DESC', $group_rep= break; default: - // Ignore. + $sort_field_translated = $sort_field; break; } - $dir = ($sort == 'up') ? 'ASC' : 'DESC'; + if (strtolower($sort) != 'asc' && strtolower($sort) != 'desc') { + $dir = ($sort == 'up') ? 'ASC' : 'DESC'; + } else { + $dir = $sort; + } return 'ORDER BY '.$sort_field_translated.' '.$dir; } diff --git a/pandora_console/include/functions_html.php b/pandora_console/include/functions_html.php index c63ce23d3a..6fe4e7a043 100644 --- a/pandora_console/include/functions_html.php +++ b/pandora_console/include/functions_html.php @@ -1241,7 +1241,9 @@ function html_print_input_text_extended($name, $value, $id, $alt, $size, $maxlen $maxlength = 255; } - if ($size == 0) { + if ($size === false) { + $size = ''; + } else if ($size == 0) { $size = 10; } @@ -1441,7 +1443,9 @@ function html_print_input_password( $maxlength = 255; } - if ($size == 0) { + if ($size === false) { + $size = false; + } else if ($size == 0) { $size = 10; } @@ -1479,7 +1483,9 @@ function html_print_input_text($name, $value, $alt='', $size=50, $maxlength=255, $maxlength = 255; } - if ($size == 0) { + if ($size === false) { + $size = false; + } else if ($size == 0) { $size = 10; } @@ -2730,20 +2736,22 @@ function html_html2rgb($htmlcolor) /** * Print a magic-ajax control to select the module. * - * @param string $name The name of ajax control, by default is "module". - * @param string $default The default value to show in the ajax control. - * @param array $id_agents The array list of id agents as array(1,2,3), by default is false and the function use all agents (if the ACL desactive). - * @param boolean $ACL Filter the agents by the ACL list of user. - * @param string $scriptResult The source code of script to call, by default is - * empty. And the example is: - * function (e, data, formatted) { - * ... - * } + * @param string $name The name of ajax control, by default is "module". + * @param string $default The default value to show in the ajax control. + * @param array $id_agents The array list of id agents as array(1,2,3), by default is false and the function use all agents (if the ACL desactive). + * @param boolean $ACL Filter the agents by the ACL list of user. + * @param string $scriptResult The source code of script to call, by default is + * empty. And the example is: + * function (e, data, formatted) { + * ... + * } * - * And the formatted is the select item as string. + * And the formatted is the select item as string. * - * @param array $filter Other filter of modules. - * @param boolean $return If it is true return a string with the output instead to echo the output. + * @param array $filter Other filter of modules. + * @param boolean $return If it is true return a string with the output instead to echo the output. + * @param integer $id_agent_module Id agent module. + * @param string $size Size. * * @return mixed If the $return is true, return the output as string. */ @@ -2755,7 +2763,8 @@ function html_print_autocomplete_modules( $scriptResult='', $filter=[], $return=false, - $id_agent_module=0 + $id_agent_module=0, + $size='30' ) { global $config; @@ -2796,7 +2805,7 @@ function html_print_autocomplete_modules( $default, 'text-'.$name, '', - 30, + $size, 100, false, '', @@ -3055,4 +3064,4 @@ function html_print_link_with_params($text, $params=[], $type='text', $style='') $html .= ''; return $html; -} \ No newline at end of file +} diff --git a/pandora_console/include/functions_ui.php b/pandora_console/include/functions_ui.php index 17519d8eed..827a432b1a 100755 --- a/pandora_console/include/functions_ui.php +++ b/pandora_console/include/functions_ui.php @@ -2769,8 +2769,13 @@ function ui_progress( * 'id' => datatable id. * 'class' => datatable class. * 'style' => datatable style. - * 'order' => '9, "desc"'. Column index (starting by 1) and sort direction. + * 'order' => [ + * 'field' => column name + * 'direction' => asc or desc + * ], + * 'default_pagination' => integer, default pagination is set to block_size * 'ajax_url' => 'include/ajax.php' ajax_url. + * 'ajax_data' => [ operation => 1 ] extra info to be sent. * 'ajax_postprocess' => a javscript function to postprocess data received * by ajax call. It is applied foreach row and must * use following format: @@ -2781,7 +2786,7 @@ function ui_progress( * * item.name = tmp; * * } * * [/code] - * 'columns' => [ + * 'columns_names' => [ * 'column1' :: Used as th text. Direct text entry. It could be array: * OR * [ @@ -2791,7 +2796,7 @@ function ui_progress( * 'text' => 'column1'. * ] * ], - * 'datacolumns' => [ + * 'columns' => [ * 'column1', * 'column2', * ... @@ -2824,18 +2829,43 @@ function ui_progress( */ function ui_print_datatable(array $parameters) { + global $config; + if (isset($parameters['id'])) { $table_id = $parameters['id']; } else { $table_id = uniqid('datatable_'); } - if (!isset($parameters['order'])) { - $parameters['order'] = '0, "asc"'; + if (!isset($parameters['columns']) || !is_array($parameters['columns'])) { + throw new Exception('[ui_print_datatable]: You must define columns for datatable'); } if (!isset($parameters['ajax_url'])) { - throw new Exception('Parameter ajax_url is required'); + throw new Exception('[ui_print_datatable]: Parameter ajax_url is required'); + } + + if (!isset($parameters['default_pagination'])) { + $parameters['default_pagination'] = $config['block_size']; + } + + if (!is_array($parameters['order'])) { + $order = '0, "asc"'; + } else { + if (!isset($parameters['order']['direction'])) { + $direction = 'asc'; + } + + if (!isset($parameters['order']['field'])) { + $order = 1; + } else { + $order = array_search( + $parameters['order']['field'], + $parameters['columns'] + ); + } + + $order .= ', "'.$parameters['order']['direction'].'"'; } if (!isset($parameters['ajax_data'])) { @@ -2852,6 +2882,7 @@ function ui_print_datatable(array $parameters) } else { $pagination_options = [ [ + $parameters['default_pagination'], 10, 25, 100, @@ -2861,6 +2892,7 @@ function ui_print_datatable(array $parameters) -1, ], [ + $parameters['default_pagination'], 10, 25, 100, @@ -2970,20 +3002,21 @@ function ui_print_datatable(array $parameters) ); } - if (!isset($parameters['columns']) || !is_array($parameters['columns'])) { - throw new Exception('[ui_print_datatable]: You must define columns for datatable'); - } - // Base table. $table = ''; $table .= ''; - if (!is_array($parameters['columns'])) { - throw new Exception('[ui_print_datatable]: Parameter columns is required.'); + + if (isset($parameters['column_names']) + && is_array($parameters['column_names']) + ) { + $names = $parameters['column_names']; + } else { + $names = $parameters['columns']; } - foreach ($parameters['columns'] as $column) { + foreach ($names as $column) { if (is_array($column)) { $table .= '
'.__($column['text']); @@ -3004,7 +3037,7 @@ function ui_print_datatable(array $parameters) processing: true, serverSide: true, paging: true, - pageLength: 10, + pageLength: '.$parameters['default_pagination'].', searching: false, responsive: true, dom: "lBfrtip", @@ -3071,7 +3104,7 @@ function ui_print_datatable(array $parameters) $js .= ' ], - order: [[ '.$parameters['order'].' ]] + order: [[ '.$order.' ]] }); $("#'.$form_id.'_search_bt").click(function (){ diff --git a/pandora_console/include/styles/events.css b/pandora_console/include/styles/events.css index 61379d2641..648f8a706e 100644 --- a/pandora_console/include/styles/events.css +++ b/pandora_console/include/styles/events.css @@ -19,8 +19,16 @@ div.mini-criticity { display: inline-block; } -form.flex-row > div.filter_input, -form.flex-row > ul { +div.mini-criticity.h100p { + height: 100%; +} + +.flex-row.event { + align-items: center; +} + +form.flex-row div.filter_input, +form.flex-row ul { width: 30%; min-width: 300px; display: flex; @@ -28,16 +36,40 @@ form.flex-row > ul { align-items: baseline; flex-wrap: wrap; align-content: center; + justify-content: space-between; flex: 1; - - margin: 1em 0.3em; + margin: 0.5em 3em 0.5em 0; } + +div.filter_input_little { + flex: 1; + display: flex; + flex-direction: row; + align-items: baseline; + flex-wrap: nowrap; + margin: 0.5em 0 0.5em 1em; +} + +form.flex-row div.filter_input.large { + flex: 1; + min-width: 650px; +} + +div.filter_input > label, +div.filter_input_little > label { + width: 10em; +} + form.flex-row > ul, form.flex-row > ul > li, form.flex-row > .box-shadow.white_table_graph { width: 100%; } +form.flex-row > .box-shadow.white_table_graph { + margin-top: 2em; +} + form.flex-row > ul input[type="submit"] { float: right; } @@ -45,3 +77,67 @@ form.flex-row > ul input[type="submit"] { form.flex-row > div > label { margin-right: 1em; } + +table.dataTable tbody th, +table.dataTable tbody td { + padding: 8px 10px; +} + +.info_table.events tr > th { + padding-left: 1em; + font-size: 1.3em; + font-weight: 400; + border-bottom: 2px solid #878787; + cursor: pointer; +} + +.info_table.events tr > td { + height: 2.5em; +} + +.sorting_desc { + background: url(http://localhost/pandora_console/images/sort_down_green.png) + no-repeat; + background-position-x: left; + background-position-y: center; +} +.sorting_asc { + background: url(http://localhost/pandora_console/images/sort_up_green.png) + no-repeat; + background-position-x: left; + background-position-y: center; +} + +.info_table.events > tbody > tr > td { + -moz-border-radius: 0px; + -webkit-border-radius: 0px; + border-radius: 0px; + border: none; + padding-left: 0px; + padding-right: 9px; + padding-top: 7px; + padding-bottom: 7px; + border-bottom: 2px solid #dedede; +} + +.info_table.events tr > td:first-child { + padding-left: 5px; + padding-top: 0; + vertical-align: middle; + padding-bottom: 0; +} + +.filter_input { + align-items: center; +} + +.filter_input_little > select, +.filter_input_little > input, +.filter_input > select, +.filter_input > input { + flex: 1; +} + +fieldset { + margin: 0 auto; +} diff --git a/pandora_console/include/styles/pandora.css b/pandora_console/include/styles/pandora.css index 88122fbe94..5034d60069 100644 --- a/pandora_console/include/styles/pandora.css +++ b/pandora_console/include/styles/pandora.css @@ -504,6 +504,10 @@ select:-internal-list-box { align-content: center; } +.nowrap { + flex-wrap: nowrap; +} + .padding-2 { padding: 2em; } diff --git a/pandora_console/operation/events/events.php b/pandora_console/operation/events/events.php index 59f5c0bebb..606eab7804 100644 --- a/pandora_console/operation/events/events.php +++ b/pandora_console/operation/events/events.php @@ -80,10 +80,7 @@ $event_view_hr = get_parameter('filter[event_view_hr]', 8); $id_user_ack = get_parameter('filter[id_user_ack]'); $group_rep = get_parameter('filter[group_rep]'); $tag_with = get_parameter('filter[tag_with]', io_json_mb_encode([])); -$tag_without = get_parameter( - 'filter[tag_without]', - io_json_mb_encode([]) -); +$tag_without = get_parameter('filter[tag_without]', io_json_mb_encode([])); $filter_only_alert = get_parameter('filter[filter_only_alert]'); $id_group_filter = get_parameter('filter[id_group_filter]'); $date_from = get_parameter('filter[date_from]'); @@ -92,6 +89,182 @@ $source = get_parameter('filter[source]'); $id_extra = get_parameter('filter[id_extra]'); $user_comment = get_parameter('filter[user_comment]'); + +// TAGS. +$tags_select_with = []; +$tags_select_without = []; +$tag_with_temp = []; +$tag_without_temp = []; +foreach ($tags as $id_tag => $tag) { + if ((array_search($id_tag, $tag_with) === false) + || (array_search($id_tag, $tag_with) === null) + ) { + $tags_select_with[$id_tag] = ui_print_truncate_text($tag, 50, true); + } else { + $tag_with_temp[$id_tag] = ui_print_truncate_text($tag, 50, true); + } + + if ((array_search($id_tag, $tag_without) === false) + || (array_search($id_tag, $tag_without) === null) + ) { + $tags_select_without[$id_tag] = ui_print_truncate_text($tag, 50, true); + } else { + $tag_without_temp[$id_tag] = ui_print_truncate_text($tag, 50, true); + } +} + +$add_with_tag_disabled = empty($tags_select_with); +$remove_with_tag_disabled = empty($tag_with_temp); +$add_without_tag_disabled = empty($tags_select_without); +$remove_without_tag_disabled = empty($tag_without_temp); + +$tabletags_with = html_get_predefined_table('transparent', 2); +$tabletags_with->id = 'filter_events_tags_with'; +$tabletags_with->width = '100%'; +$tabletags_with->cellspacing = 4; +$tabletags_with->cellpadding = 4; +$tabletags_with->class = 'noshadow'; +$tabletags_with->styleTable = 'border: 0px;'; +if (defined('METACONSOLE')) { + $tabletags_with->class = 'nobady'; + $tabletags_with->cellspacing = 0; + $tabletags_with->cellpadding = 0; +} + + +$data = []; + +$data[0] = html_print_select( + $tags_select_with, + 'select_with', + '', + '', + '', + 0, + true, + true, + true, + '', + false, + 'width: 200px;' +); + +$data[1] = html_print_image( + 'images/darrowright.png', + true, + [ + 'id' => 'button-add_with', + 'style' => 'cursor: pointer;', + 'title' => __('Add'), + ] +); + +$data[1] .= html_print_input_hidden( + 'tag_with', + $tag_with_base64, + true +); + +$data[1] .= '

'.html_print_image( + 'images/darrowleft.png', + true, + [ + 'id' => 'button-remove_with', + 'style' => 'cursor: pointer;', + 'title' => __('Remove'), + ] +); + +$data[2] = html_print_select( + $tag_with_temp, + 'tag_with_temp', + [], + '', + '', + 0, + true, + true, + true, + '', + false, + 'width: 200px;' +); + +$tabletags_with->data[] = $data; +$tabletags_with->rowclass[] = ''; + + +$tabletags_without = html_get_predefined_table('transparent', 2); +$tabletags_without->id = 'filter_events_tags_without'; +$tabletags_without->width = '100%'; +$tabletags_without->cellspacing = 4; +$tabletags_without->cellpadding = 4; +$tabletags_without->class = 'noshadow'; +if (defined('METACONSOLE')) { + $tabletags_without->class = 'nobady'; + $tabletags_without->cellspacing = 0; + $tabletags_without->cellpadding = 0; +} + +$tabletags_without->styleTable = 'border: 0px;'; + +$data = []; +$data[0] = html_print_select( + $tags_select_without, + 'select_without', + '', + '', + '', + 0, + true, + true, + true, + '', + false, + 'width: 200px;' +); +$data[1] = html_print_image( + 'images/darrowright.png', + true, + [ + 'id' => 'button-add_without', + 'style' => 'cursor: pointer;', + 'title' => __('Add'), + ] +); +$data[1] .= html_print_input_hidden( + 'tag_without', + $tag_without_base64, + true +); +$data[1] .= '

'.html_print_image( + 'images/darrowleft.png', + true, + [ + 'id' => 'button-remove_without', + 'style' => 'cursor: pointer;', + 'title' => __('Remove'), + ] +); +$data[2] = html_print_select( + $tag_without_temp, + 'tag_without_temp', + [], + '', + '', + 0, + true, + true, + true, + '', + false, + 'width: 200px;' +); +$tabletags_without->data[] = $data; +$tabletags_without->rowclass[] = ''; + + +// END OF TAGS. // Datatables offset, limit. $start = get_parameter('start', 0); $length = get_parameter('length', $config['block_size']); @@ -111,8 +284,11 @@ if (is_ajax()) { $update_event_filter = get_parameter('update_event_filter', 0); $get_event_filters = get_parameter('get_event_filters', 0); $get_events = get_parameter('get_events', 0); + $filter = get_parameter('filter', []); if ($get_events) { + $order = get_datatable_order(true); + $sql_post = ' AND te.utimestamp > UNIX_TIMESTAMP(now() - INTERVAL '.$event_view_hr.' hour)'; $events = events_get_events_grouped( // Sql_post. @@ -126,7 +302,13 @@ if (is_ajax()) { // History. false, // Total. - false + false, + // History db. + false, + // Order. + $order['direction'], + // Sort field. + $order['field'] ); if ($events) { @@ -380,7 +562,10 @@ if (is_metaconsole() !== true) { } } -// Load filter form. +/* + * Load filter form. + */ + // Group. $user_groups_array = users_get_groups_for_select( $config['id_user'], @@ -483,7 +668,7 @@ $in .= $data.''; $inputs[] = $in; // Source. -$data = html_print_input_text('source', $source, '', 35, 255, true); +$data = html_print_input_text('source', $source, '', '', 255, true); $in = '
'; $in .= $data.'
'; $inputs[] = $in; @@ -500,7 +685,7 @@ $data = html_print_input_text( 'user_comment', $user_comment, '', - 35, + '', 255, true ); @@ -509,10 +694,229 @@ $in .= $data.''; $inputs[] = $in; -// Advanced filter. -$adv_filter = ''; +/* + * Advanced filter. + */ + +$adv_inputs = []; + +// Free search. +$data = html_print_input_text('search', $search, '', '', 255, true); +$in = '
'; +$in .= $data.'
'; +$adv_inputs[] = $in; + +// Agent search. +$params = []; +$params['show_helptip'] = true; +$params['input_name'] = 'text_agent'; +$params['value'] = $text_agent; +$params['return'] = true; + +if ($meta) { + $params['javascript_page'] = 'enterprise/meta/include/ajax/events.ajax'; +} + +$params['print_hidden_input_idagent'] = true; +$params['hidden_input_idagent_name'] = 'id_agent'; +$params['hidden_input_idagent_value'] = $id_agent; +$params['size'] = ''; + +$data = ui_print_agent_autocomplete_input($params); +$in = '
'; +$in .= $data.'
'; +$adv_inputs[] = $in; + +// Mixed. Metaconsole => server, Console => module. +if (is_metaconsole()) { + $title = __('Server'); + $data = html_print_select_from_sql( + 'SELECT id, server_name FROM tmetaconsole_setup', + 'server_id', + $server_id, + 'script', + __('All'), + '0', + true + ); +} else { + $title = __('Module search'); + $data = html_print_autocomplete_modules( + 'module_search', + $text_module, + false, + true, + '', + [], + true, + $id_agent_module, + '' + ); +} + +$in = '
'; +$in .= $data.'
'; +$adv_inputs[] = $in; + +// User ack. +$user_users = users_get_user_users( + $config['id_user'], + $access, + users_can_manage_group_all() +); + +$data = html_print_select( + $user_users, + 'id_user_ack', + $id_user_ack, + '', + __('Any'), + 0, + true +); +$in = '
'; +$in .= $data.'
'; +$adv_inputs[] = $in; + +// Only alert events. +$data = html_print_select( + [ + '-1' => __('All'), + '0' => __('Filter alert events'), + '1' => __('Only alert events'), + ], + 'filter_only_alert', + $filter_only_alert, + '', + '', + '', + true +); +$in = '
'; +$in .= $data.'
'; +$adv_inputs[] = $in; + +// Gap. +$adv_inputs[] = '
'; + +// Date from. +$data = html_print_input_text( + 'date_from', + $date_from, + '', + false, + 10, + true, + // Disabled. + false, + // Required. + false, + // Function. + '', + // Class. + '', + // OnChange. + '', + // Autocomplete. + 'off' +); +$in = '
'; +$in .= '
'; +$in .= $data.'
'; + +// Time from. +$data = html_print_input_text( + 'time_from', + $time_from, + '', + false, + 10, + true, + // Disabled. + false, + // Required. + false, + // Function. + '', + // Class. + '', + // OnChange. + '', + // Autocomplete. + 'off' +); +$in .= '
'; +$in .= $data.'
'; +$in .= '
'; +$adv_inputs[] = $in; + +// Date to. +$data = html_print_input_text( + 'date_to', + $date_to, + '', + false, + 10, + true, + // Disabled. + false, + // Required. + false, + // Function. + '', + // Class. + '', + // OnChange. + '', + // Autocomplete. + 'off' +); +$in = '
'; +$in .= '
'; +$in .= $data.'
'; + +// Time to. +$data = html_print_input_text( + 'time_to', + $time_to, + '', + false, + 10, + true, + // Disabled. + false, + // Required. + false, + // Function. + '', + // Class. + '', + // OnChange. + '', + // Autocomplete. + 'off' +); +$in .= '
'; +$in .= $data.'
'; +$in .= '
'; +$adv_inputs[] = $in; + + +// Tags. +if (is_metaconsole()) { + $data = '
'.__('Events with following tags').''.html_print_table($tabletags_with, true).'
'; + $data .= '
'.__('Events without following tags').''.html_print_table($tabletags_without, true).'
'; +} else { + $data = '
'.__('Events with following tags').''.html_print_table($tabletags_with, true).'
'; + $data .= '
'.__('Events without following tags').''.html_print_table($tabletags_without, true).'
'; +} + +$in = '
'; +$in .= $data.'
'; +$adv_inputs[] = $in; // Load view. +$adv_filter = join('', $adv_inputs); $filter = join('', $inputs); $filter .= ui_toggle( $adv_filter, @@ -522,14 +926,55 @@ $filter .= ui_toggle( true, true, 'white_box white_box_opened', - 'no-border' + 'no-border flex-row' ); try { + $column_names = [ + __('Event'), + __('Event ID'), + __('Agent name'), + __('Timestamp'), + __('Severity'), + __('Options'), + ]; + $fields = [ + 'evento', + 'id_evento', + // 'id_agente', + // 'id_usuario', + // 'id_grupo', + // 'estado', + 'agent_name', + 'timestamp', + // 'utimestamp', + // 'event_type', + // 'id_agentmodule', + // 'id_alert_am', + 'event_type', + // 'user_comment', + // 'tags', + // 'source', + // 'id_extra', + // 'critical_instructions', + // 'warning_instructions', + // 'unknown_instructions', + // 'owner_user', + // 'ack_utimestamp', + // 'custom_data', + // 'data', + // 'module_status', + // 'similar_ids', + // 'event_rep', + // 'timestamp_rep', + // 'timestamp_rep_min', + // 'module_name', + 'options', + ]; ui_print_datatable( [ 'id' => 'events', - 'class' => 'info_table', + 'class' => 'info_table events', 'style' => 'width: 100%;', 'ajax_url' => 'operation/events/events', 'ajax_data' => ['get_events' => 1], @@ -560,38 +1005,12 @@ try { 'html' => $filter, 'inputs' => [], ], - 'columns' => [ - 'id_evento', - 'id_agente', - // 'id_usuario', - // 'id_grupo', - // 'estado', - 'evento', - 'agent_name', - 'timestamp', - // 'utimestamp', - // 'event_type', - // 'id_agentmodule', - // 'id_alert_am', - 'criticity', - 'user_comment', - 'tags', - // 'source', - // 'id_extra', - // 'critical_instructions', - // 'warning_instructions', - // 'unknown_instructions', - // 'owner_user', - // 'ack_utimestamp', - // 'custom_data', - // 'data', - // 'module_status', - // 'similar_ids', - // 'event_rep', - // 'timestamp_rep', - // 'timestamp_rep_min', - // 'module_name', + 'order' => [ + 'field' => 'timestamp', + 'direction' => 'desc', ], + 'column_names' => $column_names, + 'columns' => $fields, 'ajax_postprocess' => ' function (item) { item.id_evento = "#"+item.id_evento; @@ -632,10 +1051,78 @@ try { text = "WARNING"; color = "'.COL_WARNING.'"; break; - } - item.criticity = \'
\' + text + "
"; + output = \'
\'; + output += \'
\'; + + evn = \'
\'; + evn += \'
\'+item.evento+\'
\'; + evn += output; + evn += \'
\' + + item.evento = evn; + + + // Event type. + switch (item.event_type) { + case "'.EVENTS_ALERT_FIRED.'": + case "'.EVENTS_ALERT_RECOVERED.'": + case "'.EVENTS_ALERT_CEASED.'": + case "'.EVENTS_ALERT_MANUAL_VALIDATION.'": + text = "'.__('ALERT').'"; + color = "'.COL_ALERTFIRED.'"; + break; + + case "'.EVENTS_RECON_HOST_DETECTED.'": + case "'.EVENTS_SYSTEM.'": + case "'.EVENTS_ERROR.'": + case "'.EVENTS_NEW_AGENT.'": + case "'.EVENTS_CONFIGURATION_CHANGE.'": + text = "'.__('SYSTEM').'"; + color = "'.COL_MAINTENANCE.'"; + break; + + case "'.EVENTS_GOING_UP_WARNING.'": + case "'.EVENTS_GOING_DOWN_WARNING.'": + $tex = "'.__('WARNING').'"; + color = "'.COL_WARNING.'"; + break; + + case "'.EVENTS_GOING_DOWN_NORMAL.'": + case "'.EVENTS_GOING_UP_NORMAL.'": + text = "'.__('NORMAL').'"; + color = "'.COL_NORMAL.'"; + break; + + case "'.EVENTS_GOING_DOWN_CRITICAL.'": + case "'.EVENTS_GOING_UP_CRITICAL.'": + text = "'.__('CRITICAL').'"; + color = "'.COL_CRITICAL.'"; + break; + + case "'.EVENTS_UNKNOWN.'": + case "'.EVENTS_GOING_UNKNOWN.'": + default: + text = "'.__('UNKNOWN').'"; + color = "'.COL_UNKNOWN.'"; + break; + } + + item.event_type = \'
\' + text + "
"; + + console.log(item); + + if (item.id_agente > 0) { + item.agent_name = \'\' + item.agent_name + \'\'; + } + + + item.options = \'button\'; }', ] ); @@ -645,3 +1132,34 @@ try { // Close viewer. enterprise_hook('close_meta_frame'); + +// Datepicker requirements. +ui_require_css_file('datepicker'); +ui_include_time_picker(); +ui_require_jquery_file( + 'ui.datepicker-'.get_user_language(), + 'include/javascript/i18n/' +); +?> +