diff --git a/pandora_console/include/functions_events.php b/pandora_console/include/functions_events.php index 27f2bf52fc..5bf57062ce 100644 --- a/pandora_console/include/functions_events.php +++ b/pandora_console/include/functions_events.php @@ -165,137 +165,8 @@ function events_get_events_grouped($sql_post, $offset = 0, (SELECT nombre FROM tagente_modulo WHERE id_agente_modulo = te.id_agentmodule) AS module_name FROM $table te LEFT JOIN tagent_secondary_group tasg ON te.id_agente = tasg.id_agent WHERE 1=1 " . $sql_post . " - GROUP BY estado, evento, id_agente, id_agentmodule" . $groupby_extra . " - ORDER BY "; - - if (!empty($sort_field)) { - switch ($sort_field) { - case 'event_id': - if ($order=='up') - $sql .= "id_evento" . " ASC"; - if ($order=='down') - $sql .= "id_evento" . " DESC"; - break; - case 'event_name': - if ($order=='up') - $sql .= "evento" . " ASC"; - if ($order=='down') - $sql .= "evento" . " DESC"; - break; - case 'event_id': - if ($order=='up') - $sql .= "id_evento" . " ASC"; - if ($order=='down') - $sql .= "id_evento" . " DESC"; - break; - case 'status': - if ($order=='up') - $sql .= "estado" . " ASC"; - if ($order=='down') - $sql .= "estado" . " DESC"; - break; - case 'agent_id': - if ($order=='up') - $sql .= "id_agente" . " ASC"; - if ($order=='down') - $sql .= "id_agente" . " DESC"; - break; - case 'timestamp': - if ($order=='up') - $sql .= "timestamp_rep" . " ASC"; - if ($order=='down') - $sql .= "timestamp_rep" . " DESC"; - break; - case 'user_id': - if ($order=='up') - $sql .= "id_usuario" . " ASC"; - if ($order=='down') - $sql .= "id_usuario" . " DESC"; - break; - case 'owner': - if ($order=='up') - $sql .= "owner_user" . " ASC"; - if ($order=='down') - $sql .= "owner_user" . " DESC"; - break; - case 'group_id': - if ($order=='up') - $sql .= "id_grupo" . " ASC"; - if ($order=='down') - $sql .= "id_grupo" . " DESC"; - break; - case 'module_name': - if ($order=='up') - $sql .= "module_name" . " ASC"; - if ($order=='down') - $sql .= "module_name" . " DESC"; - break; - case 'event_type': - if ($order=='up') - $sql .= "event_type" . " ASC"; - if ($order=='down') - $sql .= "event_type" . " DESC"; - break; - case 'alert_id': - if ($order=='up') - $sql .= "id_alert_am" . " ASC"; - if ($order=='down') - $sql .= "id_alert_am" . " DESC"; - break; - case 'criticity': - if ($order=='up') - $sql .= "criticity" . " ASC"; - if ($order=='down') - $sql .= "criticity" . " DESC"; - break; - case 'comment': - if ($order=='up') - $sql .= "user_comment" . " ASC"; - if ($order=='down') - $sql .= "user_comment" . " DESC"; - break; - case 'tags': - if ($order=='up') - $sql .= "tags" . " ASC"; - if ($order=='down') - $sql .= "tags" . " DESC"; - break; - case 'source': - if ($order=='up') - $sql .= "source" . " ASC"; - if ($order=='down') - $sql .= "source" . " DESC"; - break; - case 'extra_id': - if ($order=='up') - $sql .= "id_extra" . " ASC"; - if ($order=='down') - $sql .= "id_extra" . " DESC"; - break; - case 'ack_timestamp': - if ($order=='up') - $sql .= "ack_utimestamp" . " ASC"; - if ($order=='down') - $sql .= "ack_utimestamp" . " DESC"; - break; - case 'data': - if ($order=='up') - $sql .= "data" . " ASC"; - if ($order=='down') - $sql .= "data" . " DESC"; - break; - case 'module_status': - if ($order=='up') - $sql .= "module_status" . " ASC"; - if ($order=='down') - $sql .= "module_status" . " DESC"; - break; - default: - $sql .= "timestamp_rep" . " DESC"; - } - } - - + GROUP BY estado, evento, id_agente, id_agentmodule" . $groupby_extra; + $sql .= " " . events_get_sql_order($sort_field, $order, 2); $sql .= " LIMIT " . $offset . "," . $pagination; } @@ -4328,7 +4199,48 @@ function events_list_events_grouped_agents($sql) { return html_print_table($table,true); } +function events_get_sql_order($sort_field = "timestamp", $sort = "DESC", $group_rep = 0) { + $sort_field_translated = $sort_field; + switch ($sort_field) { + case 'event_id': + $sort_field_translated = "id_evento"; + break; + case 'event_name': + $sort_field_translated = "evento"; + break; + case 'status': + $sort_field_translated = "estado"; + break; + case 'agent_id': + $sort_field_translated = "id_agente"; + break; + case 'timestamp': + $sort_field_translated = ($group_rep == 0) ? "timestamp" : "timestamp_rep"; + break; + case 'user_id': + $sort_field_translated = "id_usuario"; + break; + case 'owner': + $sort_field_translated = "owner_user"; + break; + case 'group_id': + $sort_field_translated = "id_grupo"; + break; + case 'alert_id': + $sort_field_translated = "id_alert_am"; + break; + case 'comment': + $sort_field_translated = "user_comment"; + break; + case 'extra_id': + $sort_field_translated = "id_extra"; + break; + } + $dir = ($sort == "up") ? "ASC" : "DESC"; + + return "ORDER BY $sort_field_translated $dir"; +} ?> diff --git a/pandora_console/include/functions_html.php b/pandora_console/include/functions_html.php index af43ecf3e4..83e49c5b43 100644 --- a/pandora_console/include/functions_html.php +++ b/pandora_console/include/functions_html.php @@ -2477,4 +2477,31 @@ function html_print_result_div ($text) { return $enclose; } +/** + * Print order arrows links + * + * @param array Base tags to build url + * @param string Order key to add to URL + * @param string Value to sort ascendent + * @param string Value to sort descendent + * + * @return string HTML code to display both arrows. + */ +function html_print_sort_arrows ($params, $order_tag, $up = 'up', $down = 'down') { + // Build the queries + $params[$order_tag] = $up; + $url_up = "index.php?" . http_build_query($params, '', '&'); + $params[$order_tag] = $down; + $url_down = "index.php?" . http_build_query($params, '', '&'); + + // Build the links + return ' ' . + '' . + html_print_image("images/sort_up.png", true) . + '' . + '' . + html_print_image("images/sort_down.png", true) . + '' + ; +} ?> diff --git a/pandora_console/operation/events/events.build_query.php b/pandora_console/operation/events/events.build_query.php index 5fbb42881c..7716257cc4 100755 --- a/pandora_console/operation/events/events.build_query.php +++ b/pandora_console/operation/events/events.build_query.php @@ -81,6 +81,7 @@ switch ($status) { $events_wi_cdata = db_get_all_rows_sql('SELECT id_evento,custom_data from tevento WHERE custom_data != ""'); $count_events = 0; $events_wi_cdata_id = 'OR id_evento IN ('; +if ($events_wi_cdata === false) $events_wi_cdata = array(); foreach ($events_wi_cdata as $key => $value) { $needle = base64_decode($value['custom_data']); if (($needle != "") && ($search != "")) { diff --git a/pandora_console/operation/events/events.build_table.php b/pandora_console/operation/events/events.build_table.php index ff2c030e80..394791fd8d 100644 --- a/pandora_console/operation/events/events.build_table.php +++ b/pandora_console/operation/events/events.build_table.php @@ -20,7 +20,6 @@ require_once ($config["homedir"] . "/include/functions_ui.php"); $sort_field = get_parameter("sort_field", "timestamp"); $sort = get_parameter("sort", "down"); - $table = new stdClass(); if(!isset($table->width)) { $table->width = '100%'; @@ -34,37 +33,54 @@ if(!isset($table->class)) { $table->head = array (); $table->data = array (); +$params = array ( + // Pandora sections + "sec" => "eventos", + "sec2" => "operation/events/events", + + // Events query params + "search" => io_safe_input($search), + "severity" => $severity, + "status" => $status, + "id_group" => $id_group, + "recursion" => $recursion, + "refr" => (int)get_parameter("refr", 0), + "id_agent_module" => $id_agent_module, + "pagination" => $pagination, + "group_rep" => $group_rep, + "event_view_hr" => $event_view_hr, + "id_user_ack" => $id_user_ack, + "tag_with" => $tag_with_base64, + "tag_without" => $tag_without_base64, + "filter_only_alert" => $filter_only_alert, + "offset" => $offset, + "toogle_filter" => "no", + "filter_id" => $filter_id, + "id_name" => $id_name, + "history" => (int)$history, + "section" => $section, + "open_filter" => $open_filter, + "date_from" => $date_from, + "date_to" => $date_to, + "pure" => $config["pure"], + + // Display params + "offset" => $offset, + "disabled" => $disabled, + "sort" => $sort, + "sort_field" => $sort_field +); + if ($group_rep == 2) { $table->class = "databox filters data"; $table->head[1] = __('Agent'); $table->head[5] = __('More detail'); - - $params = "search=" . io_safe_input($search) . - "&severity=" . $severity . - "&status=" . $status . - "&id_group=" . $id_group . - "&recursion=" . $recursion . - "&refr=" . (int)get_parameter("refr", 0) . - "&id_agent_module=" . $id_agent_module . - "&pagination=" . $pagination . - "&group_rep=2" . - "&event_view_hr=" . $event_view_hr . - "&id_user_ack=" . $id_user_ack . - "&tag_with=". $tag_with_base64 . - "&tag_without=" . $tag_without_base64 . - "&filter_only_alert" . $filter_only_alert . - "&offset=" . $offset . - "&toogle_filter=no" . - "&filter_id=" . $filter_id . - "&id_name=" . $id_name . - "&history=" . (int)$history . - "&section=" . $section . - "&open_filter=" . $open_filter . - "&date_from=" . $date_from . - "&date_to=" . $date_to . - "&pure=" . $config["pure"]; - $url = "index.php?sec=eventos&sec2=operation/events/events&" . $params; + $url = html_print_sort_arrows( + array_merge($params, array('sort_field' => 'status')), + 'sort' + ); + foreach ($result as $key => $res) { if ($res['event_type'] == 'alert_fired') { @@ -122,7 +138,6 @@ if ($group_rep == 2) { } } else { - //fields that the user has selected to show if ($meta) { $show_fields = events_meta_get_custom_fields_user(); @@ -133,7 +148,10 @@ else { //headers $i = 0; - $table->head[$i] = __('ID') . ' ' . '' . html_print_image("images/sort_up.png", true, array("style" => $selectNameUp)) . '' . '' . html_print_image("images/sort_down.png", true, array("style" => $selectNameDown)) . ''; + $table->head[$i] = __('ID') . html_print_sort_arrows( + array_merge($params, array('sort_field' => 'event_id')), + 'sort' + ); $table->align[$i] = 'left'; @@ -144,104 +162,154 @@ else { $i++; } if (in_array('estado', $show_fields)) { - $table->head[$i] = __('Status') . ' ' . '' . html_print_image("images/sort_up.png", true, array("style" => $selectNameUp)) . '' . '' . html_print_image("images/sort_down.png", true, array("style" => $selectNameDown)) . ''; + $table->head[$i] = __('Status') . html_print_sort_arrows( + array_merge($params, array('sort_field' => 'status')), + 'sort' + ); $table->align[$i] = 'left'; $i++; } if (in_array('id_evento', $show_fields)) { - $table->head[$i] = __('Event ID') . ' ' . '' . html_print_image("images/sort_up.png", true, array("style" => $selectNameUp)) . '' . '' . html_print_image("images/sort_down.png", true, array("style" => $selectNameDown)) . ''; + $table->head[$i] = __('Event ID') . html_print_sort_arrows( + array_merge($params, array('sort_field' => 'event_id')), + 'sort' + ); $table->align[$i] = 'left'; $i++; } if (in_array('evento', $show_fields)) { - $table->head[$i] = __('Event Name') . ' ' . '' . html_print_image("images/sort_up.png", true, array("style" => $selectNameUp)) . '' . '' . html_print_image("images/sort_down.png", true, array("style" => $selectNameDown)) . ''; + $table->head[$i] = __('Event Name') . html_print_sort_arrows( + array_merge($params, array('sort_field' => 'event_name')), + 'sort' + ); $table->align[$i] = 'left'; $table->style[$i] = 'min-width: 200px; max-width: 350px; word-break: break-all;'; $i++; } if (in_array('id_agente', $show_fields)) { - $table->head[$i] = __('Agent name') . ' ' . '' . html_print_image("images/sort_up.png", true, array("style" => $selectNameUp)) . '' . '' . html_print_image("images/sort_down.png", true, array("style" => $selectNameDown)) . ''; + $table->head[$i] = __('Agent name') . html_print_sort_arrows( + array_merge($params, array('sort_field' => 'agent_id')), + 'sort' + ); $table->align[$i] = 'left'; $table->style[$i] = 'max-width: 350px; word-break: break-all;'; $i++; } if (in_array('timestamp', $show_fields)) { - $table->head[$i] = __('Timestamp') . ' ' . '' . html_print_image("images/sort_up.png", true, array("style" => $selectNameUp)) . '' . '' . html_print_image("images/sort_down.png", true, array("style" => $selectNameDown)) . ''; + $table->head[$i] = __('Timestamp') . html_print_sort_arrows( + array_merge($params, array('sort_field' => 'timestamp')), + 'sort' + ); $table->align[$i] = 'left'; $i++; } if (in_array('id_usuario', $show_fields)) { - $table->head[$i] = __('User') . ' ' . '' . html_print_image("images/sort_up.png", true, array("style" => $selectNameUp)) . '' . '' . html_print_image("images/sort_down.png", true, array("style" => $selectNameDown)) . ''; + $table->head[$i] = __('User') . html_print_sort_arrows( + array_merge($params, array('sort_field' => 'user_id')), + 'sort' + ); $table->align[$i] = 'left'; $i++; } if (in_array('owner_user', $show_fields)) { - $table->head[$i] = __('Owner') . ' ' . '' . html_print_image("images/sort_up.png", true, array("style" => $selectNameUp)) . '' . '' . html_print_image("images/sort_down.png", true, array("style" => $selectNameDown)) . ''; + $table->head[$i] = __('Owner') . html_print_sort_arrows( + array_merge($params, array('sort_field' => 'owner')), + 'sort' + ); $table->align[$i] = 'left'; $i++; } if (in_array('id_grupo', $show_fields)) { - $table->head[$i] = __('Group') . ' ' . '' . html_print_image("images/sort_up.png", true, array("style" => $selectNameUp)) . '' . '' . html_print_image("images/sort_down.png", true, array("style" => $selectNameDown)) . ''; + $table->head[$i] = __('Group') . html_print_sort_arrows( + array_merge($params, array('sort_field' => 'group_id')), + 'sort' + ); $table->align[$i] = 'left'; $i++; } if (in_array('event_type', $show_fields)) { - $table->head[$i] = __('Event Type') . ' ' . '' . html_print_image("images/sort_up.png", true, array("style" => $selectNameUp)) . '' . '' . html_print_image("images/sort_down.png", true, array("style" => $selectNameDown)) . ''; + $table->head[$i] = __('Event Type') . html_print_sort_arrows( + array_merge($params, array('sort_field' => 'event_type')), + 'sort' + ); $table->align[$i] = 'left'; $table->style[$i] = 'min-width: 85px;'; $i++; } if (in_array('id_agentmodule', $show_fields)) { - $table->head[$i] = __('Module Name') . ' ' . '' . html_print_image("images/sort_up.png", true, array("style" => $selectNameUp)) . '' . '' . html_print_image("images/sort_down.png", true, array("style" => $selectNameDown)) . ''; + $table->head[$i] = __('Module Name') . html_print_sort_arrows( + array_merge($params, array('sort_field' => 'module_name')), + 'sort' + ); $table->align[$i] = 'left'; $i++; } if (in_array('id_alert_am', $show_fields)) { - $table->head[$i] = __('Alert') . ' ' . '' . html_print_image("images/sort_up.png", true, array("style" => $selectNameUp)) . '' . '' . html_print_image("images/sort_down.png", true, array("style" => $selectNameDown)) . ''; + $table->head[$i] = __('Alert') . html_print_sort_arrows( + array_merge($params, array('sort_field' => 'alert_id')), + 'sort' + ); $table->align[$i] = 'left'; $i++; } if (in_array('criticity', $show_fields)) { - $table->head[$i] = __('Severity') . ' ' . '' . html_print_image("images/sort_up.png", true, array("style" => $selectNameUp)) . '' . '' . html_print_image("images/sort_down.png", true, array("style" => $selectNameDown)) . ''; + $table->head[$i] = __('Severity') . html_print_sort_arrows( + array_merge($params, array('sort_field' => 'criticity')), + 'sort' + ); $table->align[$i] = 'left'; $i++; } if (in_array('user_comment', $show_fields)) { - $table->head[$i] = __('Comment') . ' ' . '' . html_print_image("images/sort_up.png", true, array("style" => $selectNameUp)) . '' . '' . html_print_image("images/sort_down.png", true, array("style" => $selectNameDown)) . ''; + $table->head[$i] = __('Comment') . html_print_sort_arrows( + array_merge($params, array('sort_field' => 'comment')), + 'sort' + ); $table->align[$i] = 'left'; $i++; } if (in_array('tags', $show_fields)) { - $table->head[$i] = __('Tags') . ' ' . '' . html_print_image("images/sort_up.png", true, array("style" => $selectNameUp)) . '' . '' . html_print_image("images/sort_down.png", true, array("style" => $selectNameDown)) . ''; + $table->head[$i] = __('Tags') . html_print_sort_arrows( + array_merge($params, array('sort_field' => 'tags')), + 'sort' + ); $table->align[$i] = 'left'; $i++; } if (in_array('source', $show_fields)) { - $table->head[$i] = __('Source') . ' ' . '' . html_print_image("images/sort_up.png", true, array("style" => $selectNameUp)) . '' . '' . html_print_image("images/sort_down.png", true, array("style" => $selectNameDown)) . ''; - $table->align[$i] = 'left'; + $table->head[$i] = __('Source') . html_print_sort_arrows( + array_merge($params, array('sort_field' => 'source')), + 'sort' + );$table->align[$i] = 'left'; $i++; } if (in_array('id_extra', $show_fields)) { - $table->head[$i] = __('Extra ID') . ' ' . '' . html_print_image("images/sort_up.png", true, array("style" => $selectNameUp)) . '' . '' . html_print_image("images/sort_down.png", true, array("style" => $selectNameDown)) . ''; + $table->head[$i] = __('Extra ID') . html_print_sort_arrows( + array_merge($params, array('sort_field' => 'extra_id')), + 'sort' + ); $table->align[$i] = 'left'; $i++; } if (in_array('ack_utimestamp', $show_fields)) { - $table->head[$i] = __('ACK Timestamp') . ' ' . '' . html_print_image("images/sort_up.png", true, array("style" => $selectNameUp)) . '' . '' . html_print_image("images/sort_down.png", true, array("style" => $selectNameDown)) . ''; + $table->head[$i] = __('ACK Timestamp') . html_print_sort_arrows( + array_merge($params, array('sort_field' => 'ack_utimestamp')), + 'sort' + ); $table->align[$i] = 'left'; $i++; @@ -253,14 +321,19 @@ else { $i++; } if (in_array('data', $show_fields)) { - $table->head[$i] = __('Data') . ' ' . '' . html_print_image("images/sort_up.png", true, array("style" => $selectNameUp)) . '' . '' . html_print_image("images/sort_down.png", true, array("style" => $selectNameDown)) . ''; + $table->head[$i] = __('Data') . html_print_sort_arrows( + array_merge($params, array('sort_field' => 'data')), + 'sort' + ); $table->align[$i] = 'left'; $i++; } if (in_array('module_status', $show_fields)) { - $table->head[$i] = __('Module Status') . ' ' . '' . html_print_image("images/sort_up.png", true, array("style" => $selectNameUp)) . '' . '' . html_print_image("images/sort_down.png", true, array("style" => $selectNameDown)) . '';; - $table->align[$i] = 'left'; + $table->head[$i] = __('Module Status') . html_print_sort_arrows( + array_merge($params, array('sort_field' => 'module_status')), + 'sort' + );$table->align[$i] = 'left'; $i++; } @@ -772,7 +845,10 @@ else { if (!empty ($table->data)) { if ($allow_pagination) { - ui_pagination ($total_events, "index.php?sec=eventos&sec2=operation/events/events&sort_field=$sort_field&sort=$sort&disabled=$disabled", $offset, $pagination); + $params_to_paginate = $params; + unset($params_to_paginate['offset']); + $url_paginate = "index.php?" . http_build_query($params_to_paginate, '', '&'); + ui_pagination ($total_events, $url_paginate, $offset, $pagination); } if ($allow_action) { diff --git a/pandora_console/operation/events/events_list.php b/pandora_console/operation/events/events_list.php index 783383daa5..883179d646 100644 --- a/pandora_console/operation/events/events_list.php +++ b/pandora_console/operation/events/events_list.php @@ -29,7 +29,6 @@ enterprise_include_once('include/functions_events.php'); check_login (); $sort_field = get_parameter("sort_field", "timestamp"); - $sort_order = get_parameter("sort", "down"); $event_a = check_acl ($config['id_user'], 0, "ER"); @@ -743,11 +742,13 @@ echo ""; $event_table = events_get_events_table($meta, $history); if ($group_rep == 0) { - $sql = "SELECT DISTINCT te.*, 1 event_rep + $order_sql = events_get_sql_order($sort_field, $sort_order, $group_rep); + $sql = "SELECT DISTINCT te.*, 1 event_rep, + (SELECT nombre FROM tagente_modulo WHERE id_agente_modulo = te.id_agentmodule) AS module_name FROM $event_table te LEFT JOIN tagent_secondary_group tasg ON te.id_agente = tasg.id_agent WHERE 1=1 " . $sql_post . " - ORDER BY utimestamp DESC LIMIT ".$offset.",".$pagination; + $order_sql LIMIT ".$offset.",".$pagination; //Extract the events by filter (or not) from db $result = db_get_all_rows_sql ($sql);