diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index 22e256acea..154d001bae 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,16 @@ +2013-01-18 Sergio Martin + + * operation/events/events_rss.php + operation/events/export_csv.php + operation/events/events_list.php + operation/events/events.php + operation/events/events.build_query.php: Fixed tag filters in + event view and other filter elements missed in the csv and rss + tools. Merged from 4.0.3 + + Now the code of query conditions for events is common for + all of the pages where is retrieved + 2013-01-17 Juan Manuel Ramon * include/functions_graph.php diff --git a/pandora_console/operation/events/events.build_query.php b/pandora_console/operation/events/events.build_query.php new file mode 100755 index 0000000000..d84fb32fed --- /dev/null +++ b/pandora_console/operation/events/events.build_query.php @@ -0,0 +1,181 @@ + 0 && in_array ($ev_group, array_keys ($groups))) { + + if($meta) { + // In metaconsole the group search is performed by name + $group_name = groups_get_name ($ev_group); + $sql_post = " AND group_name = '$group_name'"; + } + else { + //If a group is selected and it's in the groups allowed + $sql_post = " AND id_grupo = $ev_group"; + } +} +else { + if (is_user_admin ($id_user)) { + //Do nothing if you're admin, you get full access + $sql_post = ""; + } + else { + //Otherwise select all groups the user has rights to. + $sql_post = " AND id_grupo IN (" . + implode (",", array_keys ($groups)) . ")"; + } +} + +// Skip system messages if user is not PM +if (!check_acl ($id_user, 0, "PM")) { + $sql_post .= " AND id_grupo != 0"; +} + +switch ($status) { + case 0: + case 1: + case 2: + $sql_post .= " AND estado = " . $status; + break; + case 3: + $sql_post .= " AND (estado = 0 OR estado = 2)"; + break; +} + +if ($search != "") { + $sql_post .= " AND evento LIKE '%" . io_safe_input($search) . "%'"; +} + +if ($event_type != "") { + // If normal, warning, could be several (going_up_warning, going_down_warning... too complex + // for the user so for him is presented only "warning, critical and normal" + if ($event_type == "warning" || $event_type == "critical" + || $event_type == "normal") { + $sql_post .= " AND event_type LIKE '%$event_type%' "; + } + elseif ($event_type == "not_normal") { + $sql_post .= " AND event_type LIKE '%warning%' OR event_type LIKE '%critical%' OR event_type LIKE '%unknown%' "; + } + elseif ($event_type != "all") { + $sql_post .= " AND event_type = '" . $event_type."'"; + } + +} + +if ($severity != -1) { + switch($severity) { + case EVENT_CRIT_WARNING_OR_CRITICAL: + $sql_post .= " AND (criticity = " . EVENT_CRIT_WARNING . " OR + criticity = " . EVENT_CRIT_CRITICAL . ")"; + break; + case EVENT_CRIT_NOT_NORMAL: + $sql_post .= " AND criticity != " . EVENT_CRIT_NORMAL; + break; + default: + $sql_post .= " AND criticity = $severity"; + break; + } +} + +// In metaconsole mode the agent search is performed by name +if($meta) { + if($text_agent != __('All')) { + $sql_post .= " AND agent_name LIKE '%$text_agent%'"; + } +} +else { + switch ($id_agent) { + case 0: + break; + case -1: + // Agent doesnt exist. No results will returned + $sql_post .= " AND 1 = 0"; + break; + default: + $sql_post .= " AND id_agente = " . $id_agent; + break; + } +} + +if ($id_user_ack != "0") + $sql_post .= " AND id_usuario = '" . $id_user_ack . "'"; + + +if ($event_view_hr > 0) { + $unixtime = get_system_time () - ($event_view_hr * SECONDS_1HOUR); + $sql_post .= " AND (utimestamp > " . $unixtime . ")"; +} + +//Search by tag +if (!empty($tag_with)) { + $sql_post .= ' AND ( '; + $first = true; + foreach ($tag_with as $id_tag) { + if ($first) $first = false; + else $sql_post .= " OR "; + $sql_post .= "tags LIKE '%" . tags_get_name($id_tag) . "%'"; + } + $sql_post .= ' ) '; +} +if (!empty($tag_without)) { + $sql_post .= ' AND ( '; + $first = true; + foreach ($tag_without as $id_tag) { + if ($first) $first = false; + else $sql_post .= " OR "; + $sql_post .= "tags NOT LIKE '%" . tags_get_name($id_tag) . "%'"; + } + $sql_post .= ' ) '; +} + +// Filter/Only alerts +if (isset($filter_only_alert)) { + if ($filter_only_alert == 0) + $sql_post .= " AND event_type NOT LIKE '%alert%'"; + else if ($filter_only_alert == 1) + $sql_post .= " AND event_type LIKE '%alert%'"; +} + +// Tags ACLS +if ($ev_group > 0 && in_array ($ev_group, array_keys ($groups))) { + $group_array = (array) $ev_group; +} +else { + $group_array = array_keys($groups); +} + +$tags_acls_condition = tags_get_acl_tags($id_user, $group_array, 'ER', 'event_condition', 'AND'); + +$sql_post .= $tags_acls_condition; + +// Metaconsole fitlers +if($meta) { + $enabled_nodes = db_get_all_rows_sql('SELECT id FROM tmetaconsole_setup WHERE disabled = 0'); + + if(empty($enabled_nodes)) { + $sql_post .= ' AND 1 = 0'; + } + else { + $enabled_nodes_id = array(); + foreach($enabled_nodes as $en) { + $enabled_nodes_id[] = $en['id']; + } + $sql_post .= ' AND server_id IN ('.implode(',',$enabled_nodes_id).')'; + } +} + +?> diff --git a/pandora_console/operation/events/events.php b/pandora_console/operation/events/events.php index 3060d149aa..4779810b98 100644 --- a/pandora_console/operation/events/events.php +++ b/pandora_console/operation/events/events.php @@ -169,12 +169,11 @@ if (is_ajax ()) { $offset = (int) get_parameter ("offset", 0); -$ev_group = (int) get_parameter ("ev_group", 0); //0 = all +$ev_group = (int) get_parameter ("ev_group", 0); //0 all $event_type = get_parameter ("event_type", ''); // 0 all $severity = (int) get_parameter ("severity", -1); // -1 all $status = (int) get_parameter ("status", 3); // -1 all, 0 only new, 1 only validated, 2 only in process, 3 only not validated, $id_agent = (int) get_parameter ("id_agent", 0); -$id_event = (int) get_parameter ("id_event", -1); $pagination = (int) get_parameter ("pagination", $config["block_size"]); $event_view_hr = (int) get_parameter ("event_view_hr", $history ? 0 : $config["event_view_hr"]); $id_user_ack = get_parameter ("id_user_ack", 0); @@ -188,22 +187,59 @@ $filter_id = (int) get_parameter('filter_id', 0); $id_name = (string) get_parameter('id_name', ''); $id_group = (int) get_parameter('id_group', 0); +$text_agent = (string) get_parameter("text_agent", __("All")); + +$tag_with_json = base64_decode(get_parameter("tag_with", '')) ; +$tag_with_json_clean = io_safe_output($tag_with_json); +$tag_with_base64 = base64_encode($tag_with_json_clean); +$tag_with = json_decode($tag_with_json_clean, true); +if (empty($tag_with)) $tag_with = array(); +$tag_with = array_diff($tag_with, array(0 => 0)); + +$tag_without_json = base64_decode(get_parameter("tag_without", '')); +$tag_without_json_clean = io_safe_output($tag_without_json); +$tag_without_base64 = base64_encode($tag_without_json_clean); +$tag_without = json_decode($tag_without_json_clean, true); +if (empty($tag_without)) $tag_without = array(); +$tag_without = array_diff($tag_without, array(0 => 0)); + $search = io_safe_output(preg_replace ("/&([A-Za-z]{0,4}\w{2,3};|#[0-9]{2,3};)/", "&", rawurldecode (get_parameter ("search")))); users_get_groups ($config["id_user"], "ER"); $ids = (array) get_parameter ("eventid", -1); -$url = "index.php?sec=eventos&sec2=operation/events/events&search=" . - io_safe_input($search) . "&event_type=" . $event_type . - "&severity=" . $severity . "&status=" . $status . "&ev_group=" . - $ev_group . "&refr=" . $config["refr"] . "&id_agent=" . - $id_agent . "&id_event=" . $id_event . "&pagination=" . - $pagination . "&group_rep=" . $group_rep . "&event_view_hr=" . - $event_view_hr . "&id_user_ack=" . $id_user_ack; +$params = "search=" . rawurlencode(io_safe_input($search)) . + "&event_type=" . $event_type . + "&severity=" . $severity . + "&status=" . $status . + "&ev_group=" . $ev_group . + "&refr=" . $config["refr"] . + "&id_agent=" . $id_agent . + "&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 . + "&id_group=" . $id_group . + "&history=" . (int)$history . + "&section=" . $section . + "&pure=" . $config["pure"]; +if($meta) { + $params .= "&text_agent=" . $text_agent; +} + +$url = "index.php?sec=eventos&sec2=operation/events/events&" . $params; + // Header -if ($config["pure"] == 0 || defined ('METACONSOLE')) { +if ($config["pure"] == 0 || $meta) { $pss = get_user_info($config['id_user']); $hashup = md5($config['id_user'] . $pss['password']); @@ -224,8 +260,7 @@ if ($config["pure"] == 0 || defined ('METACONSOLE')) { // RSS $rss['active'] = false; - $rss['text'] = '' . + $rss['text'] = '' . html_print_image("images/rss.png", true, array ("title" => __('RSS Events'))) .''; // Marquee @@ -235,8 +270,7 @@ if ($config["pure"] == 0 || defined ('METACONSOLE')) { // CSV $csv['active'] = false; - $csv['text'] = '' . + $csv['text'] = '' . html_print_image("images/disk.png", true, array ("title" => __('Export to CSV file'))) .''; // Sound events @@ -800,4 +834,4 @@ $(document).ready( function() { } ?> /* ]]> */ - \ No newline at end of file + diff --git a/pandora_console/operation/events/events_list.php b/pandora_console/operation/events/events_list.php index d7d63df937..9c538a99a1 100644 --- a/pandora_console/operation/events/events_list.php +++ b/pandora_console/operation/events/events_list.php @@ -36,11 +36,6 @@ if (! check_acl ($config["id_user"], 0, "ER")) { return; } -$meta = false; -if(enterprise_installed() && defined("METACONSOLE")) { - $meta = true; -} - if (is_ajax()) { $get_filter_values = get_parameter('get_filter_values', 0); $save_event_filter = get_parameter('save_event_filter', 0); @@ -135,196 +130,21 @@ $tags = tags_get_user_tags($config['id_user'], 'ER'); echo "
"; echo "
"; -$tag_with_json = io_safe_output(get_parameter("tag_with")); -$tag_with = json_decode($tag_with_json, true); -if (empty($tag_with)) $tag_with = array(); -$tag_without_json = io_safe_output(get_parameter("tag_without")); -$tag_without = json_decode($tag_without_json, true); -if (empty($tag_without)) $tag_without = array(); - -$text_agent = (string) get_parameter("text_agent", __("All")); - if ($id_agent == 0 && $text_agent != __('All')) { $id_agent = -1; } -$groups = users_get_groups($config['id_user'], 'ER'); +///////////////////////////////////////////// +// Build the condition of the events query -//Group selection -if ($ev_group > 0 && in_array ($ev_group, array_keys ($groups))) { - if($meta) { - // In metaconsole the group search is performed by name - $group_name = groups_get_name ($ev_group); - $sql_post = " AND group_name = '$group_name'"; - } - else { - //If a group is selected and it's in the groups allowed - $sql_post = " AND id_grupo = $ev_group"; - } -} -else { - if (is_user_admin ($config["id_user"])) { - //Do nothing if you're admin, you get full access - $sql_post = ""; - } - else { - //Otherwise select all groups the user has rights to. - $sql_post = " AND id_grupo IN (" . - implode (",", array_keys ($groups)) . ")"; - } -} +$sql_post = ""; -// Skip system messages if user is not PM -if (!check_acl ($config["id_user"], 0, "PM")) { - $sql_post .= " AND id_grupo != 0"; -} +$id_user = $config['id_user']; -switch ($status) { - case 0: - case 1: - case 2: - $sql_post .= " AND estado = " . $status; - break; - case 3: - $sql_post .= " AND (estado = 0 OR estado = 2)"; - break; -} +require('events.build_query.php'); -if ($search != "") { - $sql_post .= " AND evento LIKE '%" . io_safe_input($search) . "%'"; -} - -if ($event_type != "") { - // If normal, warning, could be several (going_up_warning, going_down_warning... too complex - // for the user so for him is presented only "warning, critical and normal" - if ($event_type == "warning" || $event_type == "critical" - || $event_type == "normal") { - $sql_post .= " AND event_type LIKE '%$event_type%' "; - } - elseif ($event_type == "not_normal") { - $sql_post .= " AND event_type LIKE '%warning%' OR event_type LIKE '%critical%' OR event_type LIKE '%unknown%' "; - } - else { - $sql_post .= " AND event_type = '" . $event_type."'"; - } - -} -if ($severity != -1) { - switch($severity) { - case EVENT_CRIT_WARNING_OR_CRITICAL: - $sql_post .= " AND (criticity = " . EVENT_CRIT_WARNING . " OR - criticity = " . EVENT_CRIT_CRITICAL . ")"; - break; - case EVENT_CRIT_NOT_NORMAL: - $sql_post .= " AND criticity != " . EVENT_CRIT_NORMAL; - break; - default: - $sql_post .= " AND criticity = $severity"; - break; - } -} - -// In metaconsole mode the agent search is performed by name -if($meta) { - if($text_agent != __('All')) { - $sql_post .= " AND agent_name LIKE '%$text_agent%'"; - } -} -else { - switch ($id_agent) { - case 0: - break; - case -1: - // Agent doesnt exist. No results will returned - $sql_post .= " AND 1 = 0"; - break; - default: - $sql_post .= " AND id_agente = " . $id_agent; - break; - } -} - -if ($id_event != -1) - $sql_post .= " AND id_evento = " . $id_event; - -if ($id_user_ack != "0") - $sql_post .= " AND id_usuario = '" . $id_user_ack . "'"; - - -if ($event_view_hr > 0) { - $unixtime = get_system_time () - ($event_view_hr * SECONDS_1HOUR); - $sql_post .= " AND (utimestamp > " . $unixtime . ")"; -} - -//Search by tag -if (!empty($tag_with)) { - $sql_post .= ' AND ( '; - $first = true; - foreach ($tag_with as $id_tag) { - if ($first) $first = false; - else $sql_post .= " OR "; - $sql_post .= "tags LIKE '%" . tags_get_name($id_tag) . "%'"; - } - $sql_post .= ' ) '; -} -if (!empty($tag_without)) { - $sql_post .= ' AND ( '; - $first = true; - foreach ($tag_without as $id_tag) { - if ($first) $first = false; - else $sql_post .= " OR "; - $sql_post .= "tags NOT LIKE '%" . tags_get_name($id_tag) . "%'"; - } - $sql_post .= ' ) '; -} - -// Filter/Only alerts -if (isset($filter_only_alert)) { - if ($filter_only_alert == 0) - $sql_post .= " AND event_type NOT LIKE '%alert%'"; - else if ($filter_only_alert == 1) - $sql_post .= " AND event_type LIKE '%alert%'"; -} - -// Tags ACLS -if ($ev_group > 0 && in_array ($ev_group, array_keys ($groups))) { - $group_array = (array) $ev_group; -} -else { - $group_array = array_keys($groups); -} - -$tags_acls_condition = tags_get_acl_tags($config['id_user'], $group_array, 'ER', 'event_condition', 'AND'); - -$sql_post .= $tags_acls_condition; - -$url = "index.php?sec=eventos&sec2=operation/events/events&search=" . - rawurlencode(io_safe_input($search)) . - "&event_type=" . $event_type . - "&severity=" . $severity . - "&status=" . $status . - "&ev_group=" . $ev_group . - "&refr=" . $config["refr"] . - "&id_agent=" . $id_agent . - "&id_event=" . $id_event . - "&pagination=" . $pagination . - "&group_rep=" . $group_rep . - "&event_view_hr=" . $event_view_hr . - "&id_user_ack=" . $id_user_ack . - "&tag_with=" . $tag_with . - "&tag_without=" . $tag_without . - "&filter_only_alert=" . $filter_only_alert . - "&offset=" . $offset . - "&toogle_filter=no" . - "&filter_id=" . $filter_id . - "&id_name=" . $id_name . - "&id_group=" . $id_group . - "&history=" . (int)$history . - "&section=" . $section; - -if($meta) { - $url .= "&text_agent=" . $text_agent; -} +// Now $sql_post have all the where condition +///////////////////////////////////////////// echo "
"; //Link to toggle filter @@ -450,10 +270,6 @@ html_print_select ($repeated_sel, "group_rep", $group_rep, ''); echo ""; - - - - echo ""; echo "" . __('Events with following tags') . ""; echo "" . __('Events without following tags') . ""; @@ -506,7 +322,7 @@ echo ""; html_print_select ($tag_with_temp, 'tag_with_temp', array(), '', '', 0, false, true, true, '', false, "width: 120px; height: 50px;"); -html_print_input_hidden('tag_with', json_encode($tag_with)); +html_print_input_hidden('tag_with', $tag_with_base64); echo ""; echo ""; html_print_button(__('Remove'), 'remove_whith', $remove_with_tag_disabled, @@ -516,7 +332,7 @@ echo ""; html_print_select ($tag_without_temp, 'tag_without_temp', array(), '', '', 0, false, true, true, '', false, "width: 120px; height: 50px;"); -html_print_input_hidden('tag_without', json_encode($tag_without)); +html_print_input_hidden('tag_without', $tag_without_base64); echo ""; echo ""; html_print_button(__('Remove'), 'remove_whithout', $remove_without_tag_disabled, @@ -524,11 +340,6 @@ html_print_button(__('Remove'), 'remove_whithout', $remove_without_tag_disabled, echo ""; echo ""; - - - - - echo ""; echo ""; @@ -589,32 +400,7 @@ echo ''; echo '
 
'; echo ''; -// Choose the table where search if metaconsole or not -if($meta) { - if($history) { - $event_table = 'tmetaconsole_event_history'; - } - else { - $event_table = 'tmetaconsole_event'; - } - - // Show only the events of enabled nodes - $enabled_nodes = db_get_all_rows_sql('SELECT id FROM tmetaconsole_setup WHERE disabled = 0'); - - if(empty($enabled_nodes)) { - $sql_post .= ' AND 1 = 0'; - } - else { - $enabled_nodes_id = array(); - foreach($enabled_nodes as $en) { - $enabled_nodes_id[] = $en['id']; - } - $sql_post .= ' AND server_id IN ('.implode(',',$enabled_nodes_id).')'; - } -} -else { - $event_table = 'tevento'; -} +$event_table = events_get_events_table($meta, $history); if ($group_rep == 0) { switch ($config["dbtype"]) { @@ -1109,7 +895,7 @@ foreach ($result as $event) { echo '
'; if (!empty ($table->data)) { echo '
'; - ui_pagination ($total_events, $url."&pure=".$config["pure"], $offset, $pagination); + ui_pagination ($total_events, $url, $offset, $pagination); echo '
'; echo ""; @@ -1584,7 +1370,7 @@ function replace_hidden_tags(what_button) { value_store.push(val); }); - $(id_hidden).val(jQuery.toJSON(value_store)); + $(id_hidden).val(Base64.encode(jQuery.toJSON(value_store))); } function reorder_tags_inputs() { diff --git a/pandora_console/operation/events/events_rss.php b/pandora_console/operation/events/events_rss.php index 8f8dd5f9ba..ed9e784f8a 100644 --- a/pandora_console/operation/events/events_rss.php +++ b/pandora_console/operation/events/events_rss.php @@ -19,9 +19,10 @@ require_once "../../include/config.php"; require_once "../../include/functions.php"; require_once "../../include/functions_db.php"; require_once "../../include/functions_api.php"; -require_once("../../include/functions_agents.php"); - -ini_set ('display_errors', 0); //Don't display other errors, messes up XML +require_once "../../include/functions_agents.php"; +require_once "../../include/functions_users.php"; +require_once "../../include/functions_tags.php"; +require_once "../../include/functions_groups.php"; $ipOrigin = $_SERVER['REMOTE_ADDR']; @@ -44,8 +45,6 @@ if ($hashup != $hashup2) { header("Content-Type: application/xml; charset=UTF-8"); //Send header before starting to output function rss_error_handler ($errno, $errstr, $errfile, $errline) { - global $config; - $url = ui_get_full_url(false); $selfurl = ui_get_full_url('?' . $_SERVER['QUERY_STRING'], false, true); @@ -66,140 +65,51 @@ function rss_error_handler ($errno, $errstr, $errfile, $errline) { set_error_handler ('rss_error_handler', E_ALL); //Errors output as RSS $ev_group = get_parameter ("ev_group", 0); // group -$search = get_parameter ("search", ""); // free search $event_type = get_parameter ("event_type", ''); // 0 all $severity = (int) get_parameter ("severity", -1); // -1 all $status = (int) get_parameter ("status", 0); // -1 all, 0 only red, 1 only green $id_agent = (int) get_parameter ("id_agent", -1); + $id_event = (int) get_parameter ("id_event", -1); //This will allow to select only 1 event (eg. RSS) $event_view_hr = (int) get_parameter ("event_view_hr", 0); +$id_user_ack = get_parameter ("id_user_ack", 0); +$search = io_safe_output(preg_replace ("/&([A-Za-z]{0,4}\w{2,3};|#[0-9]{2,3};)/", "&", rawurldecode (get_parameter ("search")))); +$text_agent = (string) get_parameter("text_agent", __("All")); +$tag_with_json = base64_decode(get_parameter("tag_with", '')) ; +$tag_with_json_clean = io_safe_output($tag_with_json); +$tag_with_base64 = base64_encode($tag_with_json_clean); +$tag_with = json_decode($tag_with_json_clean, true); +if (empty($tag_with)) $tag_with = array(); +$tag_with = array_diff($tag_with, array(0 => 0)); + +$tag_without_json = base64_decode(get_parameter("tag_without", '')); +$tag_without_json_clean = io_safe_output($tag_without_json); +$tag_without_base64 = base64_encode($tag_without_json_clean); +$tag_without = json_decode($tag_without_json_clean, true); +if (empty($tag_without)) $tag_without = array(); +$tag_without = array_diff($tag_without, array(0 => 0)); + +$filter_only_alert = (int)get_parameter('filter_only_alert', -1); + +///////////////////////////////////////////// +// Build the condition of the events query $sql_post = ""; +$meta = false; -if ($event_view_hr > 0) { - $unixtime = (int) (get_system_time () - ($event_view_hr * SECONDS_1HOUR)); //Put hours in seconds - $sql_post .= " AND tevento.utimestamp > ".$unixtime; -} -if ($ev_group > 1) - $sql_post .= " AND tevento.id_grupo = $ev_group"; +$id_user = $user; - -switch($status) { - case 0: - case 1: - case 2: - $sql_post .= " AND tevento.estado = ".$status; - break; - case 3: - $sql_post .= " AND (tevento.estado = 0 OR tevento.estado = 2)"; - break; -} +require('events.build_query.php'); +// Now $sql_post have all the where condition +///////////////////////////////////////////// -if ($search != "") - $sql_post .= " AND tevento.evento LIKE '%$search%'"; -if ($event_type != "") { - // If normal, warning, could be several (going_up_warning, going_down_warning... too complex - // for the user so for him is presented only "warning, critical and normal" - if ($event_type == "warning" || $event_type == "critical" || $event_type == "normal") { - $sql_post .= " AND tevento.event_type LIKE '%$event_type%' "; - } - elseif ($event_type == "not_normal") { - $sql_post .= " AND tevento.event_type LIKE '%warning%' OR tevento.event_type LIKE '%critical%' OR tevento.event_type LIKE '%unknown%' "; - } - else - $sql_post .= " AND tevento.event_type = '".$event_type."'"; -} -if ($severity != -1) - $sql_post .= " AND tevento.criticity >= ".$severity; - +$sql = "SELECT * + FROM tevento + WHERE 1=1 ".$sql_post." + ORDER BY utimestamp DESC"; - -if ($id_agent == -2) { - $text_agent = (string) get_parameter("text_agent", __("All")); - - switch ($text_agent) - { - case __('All'): - $id_agent = -1; - break; - case __('Server'): - $id_agent = 0; - break; - default: - $id_agent = agents_get_agent_id($text_agent); - break; - } -} -else { - switch ($id_agent) - { - case -1: - $text_agent = __('All'); - break; - case 0: - $text_agent = __('Server'); - break; - default: - $text_agent = agents_get_name($id_agent); - break; - } -} - - - -if ($id_agent != -1) - $sql_post .= " AND tevento.id_agente = ".$id_agent; -if ($id_event != -1) - $sql_post .= " AND id_evento = ".$id_event; - -// Avoid to show system events to not administrators -if(!check_acl($user, 0, "PM")) - $sql_post .= " AND tevento.event_type <> 'system'"; - -switch ($config["dbtype"]) { - case "mysql": - $sql="SELECT tevento.id_evento AS event_id, - tevento.id_agente AS id_agent, - tevento.id_usuario AS validated_by, - tevento.id_grupo AS id_group, - tevento.estado AS validated, - tevento.evento AS event_descr, - tevento.utimestamp AS unix_timestamp, - tevento.event_type AS event_type - FROM tevento - WHERE 1 = 1" . $sql_post . " - ORDER BY utimestamp DESC LIMIT 0 , 30"; - break; - case "postgresql": - $sql="SELECT tevento.id_evento AS event_id, - tevento.id_agente AS id_agent, - tevento.id_usuario AS validated_by, - tevento.id_grupo AS id_group, - tevento.estado AS validated, - tevento.evento AS event_descr, - tevento.utimestamp AS unix_timestamp, - tevento.event_type AS event_type - FROM tevento - WHERE 1 = 1" . $sql_post . " - ORDER BY utimestamp DESC LIMIT 30 OFFSET 0"; - break; - case "oracle": - $sql="SELECT tevento.id_evento AS event_id, - tevento.id_agente AS id_agent, - tevento.id_usuario AS validated_by, - tevento.id_grupo AS id_group, - tevento.estado AS validated, - tevento.evento AS event_descr, - tevento.utimestamp AS unix_timestamp, - tevento.event_type AS event_type - FROM tevento - WHERE (1 = 1" . $sql_post . ") AND rownum <= 30 - ORDER BY utimestamp DESC"; - break; -} - -$result= db_get_all_rows_sql ($sql); +$result = db_get_all_rows_sql ($sql); $url = ui_get_full_url(false); $selfurl = ui_get_full_url('?' . $_SERVER['QUERY_STRING'], false, true); @@ -208,7 +118,7 @@ if (empty ($result)) { $lastbuild = 0; //Last build in 1970 } else { - $lastbuild = (int) $result[0]['unix_timestamp']; + $lastbuild = (int) $result[0]['utimestamp']; } $rss_feed = '' . "\n"; // ' 0) { + elseif ($row["id_agente"] > 0) { // Agent name - $agent_name = agents_get_name ($row["id_agent"]); + $agent_name = agents_get_name ($row["id_agente"]); } else { $agent_name = __('Alert').__('SNMP'); @@ -244,20 +154,20 @@ foreach ($result as $row) { //This is mandatory $rss_feed .= ''; - $rss_feed .= io_safe_input($url . "/index.php?sec=eventos&sec2=operation/events/events&id_event=" . $row['event_id']); + $rss_feed .= io_safe_input($url . "/index.php?sec=eventos&sec2=operation/events/events&id_event=" . $row['id_evento']); $rss_feed .= ''; $rss_feed .= $agent_name; $rss_feed .= ''; - $rss_feed .= $row['event_descr']; - if($row['validated'] == 1) { - $rss_feed .= io_safe_input('

'.'Validated by ' . $row['validated_by']); + $rss_feed .= $row['evento']; + if($row['estado'] == 1) { + $rss_feed .= io_safe_input('

'.'Validated by ' . $row['id_usuario']); } $rss_feed .= '
'; - $rss_feed .= io_safe_input($url . "/index.php?sec=eventos&sec2=operation/events/events&id_event=" . $row["event_id"]); + $rss_feed .= io_safe_input($url . "/index.php?sec=eventos&sec2=operation/events/events&id_event=" . $row["id_evento"]); $rss_feed .= ''; //The rest is optional - $rss_feed .= '' . date(DATE_RFC822, $row['unix_timestamp']) . ''; + $rss_feed .= '' . date(DATE_RFC822, $row['utimestamp']) . ''; //This is mandatory again $rss_feed .= '
' . "\n"; diff --git a/pandora_console/operation/events/export_csv.php b/pandora_console/operation/events/export_csv.php index 565f95bc50..5ebaf6fbac 100644 --- a/pandora_console/operation/events/export_csv.php +++ b/pandora_console/operation/events/export_csv.php @@ -33,9 +33,15 @@ if (! check_acl ($config["id_user"], 0, "ER") && ! check_acl ($config["id_user"] global $config; +// loading l10n tables, because of being invoked not through index.php. +$l10n = NULL; +if (file_exists ($config['homedir'].'/include/languages/'.$user_language.'.mo')) { + $l10n = new gettext_reader (new CachedFileReader ($config['homedir'].'/include/languages/'.$user_language.'.mo')); + $l10n->load_tables(); +} + $offset = (int) get_parameter ("offset"); $ev_group = (int) get_parameter ("ev_group"); // group -//$search = (int) get_parameter ("search"); // free search $event_type = (string) get_parameter ("event_type", "all"); // 0 all $severity = (int) get_parameter ("severity", -1); // -1 all $status = (int) get_parameter ("status", -1); // -1 all, 0 only red, 1 only green @@ -46,108 +52,61 @@ $event_view_hr = (int) get_parameter ("event_view_hr", $config["event_view_hr"]) $id_user_ack = get_parameter ("id_user_ack", 0); $search = io_safe_output(preg_replace ("/&([A-Za-z]{0,4}\w{2,3};|#[0-9]{2,3};)/", "&", rawurldecode (get_parameter ("search")))); $text_agent = (string)get_parameter('text_agent', __("All")); -$tag = get_parameter("tag", ""); -$filter = array (); -if ($ev_group > 1) - $filter['id_grupo'] = $ev_group; +$tag_with_json = base64_decode(get_parameter("tag_with", '')) ; +$tag_with_json_clean = io_safe_output($tag_with_json); +$tag_with_base64 = base64_encode($tag_with_json_clean); +$tag_with = json_decode($tag_with_json_clean, true); +if (empty($tag_with)) $tag_with = array(); +$tag_with = array_diff($tag_with, array(0 => 0)); -$filter_state = ''; -switch ($status) { - case 0: - case 1: - case 2: - $filter_state = " AND estado = " . $status; - break; - case 3: - $filter_state = " AND (estado = 0 OR estado = 2)"; +$tag_without_json = base64_decode(get_parameter("tag_without", '')); +$tag_without_json_clean = io_safe_output($tag_without_json); +$tag_without_base64 = base64_encode($tag_without_json_clean); +$tag_without = json_decode($tag_without_json_clean, true); +if (empty($tag_without)) $tag_without = array(); +$tag_without = array_diff($tag_without, array(0 => 0)); + +$filter_only_alert = (int)get_parameter('filter_only_alert', -1); + +///////////////////////////////////////////// +// Build the condition of the events query + +$sql_post = ""; +$meta = false; + +$id_user = $config['id_user']; + +require('events.build_query.php'); + +// Now $sql_post have all the where condition +///////////////////////////////////////////// + +switch ($config["dbtype"]) { + case "mysql": + case "postgresql": + case "oracle": + $sql = "SELECT * + FROM tevento + WHERE 1=1 ".$sql_post." + ORDER BY utimestamp DESC"; break; } -if ($search != "") - $filter[] = 'evento LIKE "%'.io_safe_input($search).'%"'; -if (($event_type != "all") OR ($event_type != 0)) - $filter['event_type'] = $event_type; -if ($severity != -1) - $filter[] = 'criticity >= '.$severity; -if ($id_agent == -2) { - $text_agent = (string) get_parameter("text_agent", __("All")); - - switch ($text_agent) - { - case __('All'): - $id_agent = -1; - break; - case __('Server'): - $id_agent = 0; - break; - default: - $id_agent = agents_get_agent_id($text_agent); - break; - } -} -else { - switch ($id_agent) - { - case -1: - $text_agent = __('All'); - break; - case 0: - $text_agent = __('Server'); - break; - default: - $text_agent = agents_get_name($id_agent); - break; - } -} - - -if ($id_agent != -1) - $filter['id_agente'] = $id_agent; - -if ($id_event != -1) - $filter['id_evento'] = $id_event; - -$timestamp_filter = ''; -if ($event_view_hr > 0) { - $unixtime = get_system_time () - ($event_view_hr * SECONDS_1HOUR); //Put hours in seconds - $timestamp_filter = " AND (utimestamp > $unixtime OR estado = 2)"; -} - -if ($id_user_ack != "0") - $filter['id_usuario'] = $id_user_ack; - -//Search by tag -if ($tag != "") { - $filter['tags'] = "%".io_safe_input($tag)."%"; -} - -//$filter['order'] = 'timestamp DESC'; $now = date ("Y-m-d"); -// Show contentype header +// Show contentype header Header ("Content-type: text/txt"); header ('Content-Disposition: attachment; filename="pandora_export_event'.$now.'.txt"'); echo "timestamp, agent, group, event, status, user, event_type, severity"; echo chr (13); -$fields = array ('id_grupo', 'id_agente', 'evento', 'estado', 'id_usuario', - 'event_type', 'criticity', 'timestamp'); - -$sql = db_get_all_rows_filter('tevento', $filter, $fields, 'AND', true, true); - -// If filter is empty and there are others filters not empty append "WHERE" clause -if (empty($filter) and (!empty($filter_state) or !empty($timestamp_filter))) - $sql .= ' WHERE 1=1 '; - -$sql .= $filter_state . $timestamp_filter . ' ORDER BY timestamp DESC'; - $new = true; while ($event = db_get_all_row_by_steps_sql($new, $result, $sql)) { $new = false; if (!check_acl($config["id_user"], $event["id_grupo"], "ER") || - (!check_acl($config["id_user"], 0, "PM") && $event["event_type"] == 'system')) + (!check_acl($config["id_user"], 0, "PM") && $event["event_type"] == 'system')) continue; echo $event["timestamp"]; @@ -167,4 +126,5 @@ while ($event = db_get_all_row_by_steps_sql($new, $result, $sql)) { echo $event["criticity"]; echo chr (13); } -?> \ No newline at end of file +?> +