From 631c38ca8468060bbc01847d56060b7870c44ca8 Mon Sep 17 00:00:00 2001 From: danielmaya Date: Thu, 27 Sep 2018 12:46:45 +0200 Subject: [PATCH 01/42] [Tags performance] Improve monitor detail (aka status_monitor) --- pandora_console/include/functions_tags.php | 45 +++++------------- pandora_console/include/functions_users.php | 46 +++++++++++++------ .../operation/agentes/status_monitor.php | 27 +++++++---- 3 files changed, 60 insertions(+), 58 deletions(-) diff --git a/pandora_console/include/functions_tags.php b/pandora_console/include/functions_tags.php index ba031c0cff..9f06b23a53 100644 --- a/pandora_console/include/functions_tags.php +++ b/pandora_console/include/functions_tags.php @@ -723,47 +723,26 @@ function tags_get_acl_tags_module_condition($acltags, $modules_table = '') { $condition = ''; $group_conditions = array(); + $has_secondary = enterprise_hook('agents_is_using_secondary_groups'); // The acltags array contains the groups with the acl propagation applied // after the changes done into the 'tags_get_user_groups_and_tags' function. foreach ($acltags as $group_id => $group_tags) { $tag_join = ''; if (!empty($group_tags)) { - $tag_join = sprintf('INNER JOIN ttag_module ttmc - ON tamc.id_agente_modulo = ttmc.id_agente_modulo - AND ttmc.id_tag IN (%s)', - is_array($group_tags) ? implode(',', $group_tags) : $group_tags); + $tag_join = sprintf('AND ttag_module.id_tag IN (%s)',is_array($group_tags) ? implode(',', $group_tags) : $group_tags); + if($has_secondary){ + $agent_condition = sprintf('((tagente.id_grupo = %d OR tasg.id_group = %d) %s)',$group_id,$group_id,$tag_join); + } else { + $agent_condition = sprintf('((tagente.id_grupo = %d %s)',$group_id,$tag_join); + } + $group_conditions[] = $agent_condition; } - // FIXME: Not properly way to increse performance - if(enterprise_hook('agents_is_using_secondary_groups')){ - $agent_condition = sprintf('SELECT tamc.id_agente_modulo - FROM tagente_modulo tamc - %s - INNER JOIN tagente tac - ON tamc.id_agente = tac.id_agente - LEFT JOIN tagent_secondary_group tasg - ON tasg.id_agent = tac.id_agente - WHERE (tac.id_grupo = %d OR tasg.id_group = %d)', - $tag_join, $group_id, $group_id); - } - else{ - $agent_condition = sprintf('SELECT tamc.id_agente_modulo - FROM tagente_modulo tamc - %s - INNER JOIN tagente tac - ON tamc.id_agente = tac.id_agente - AND tac.id_grupo = %d', - $tag_join, $group_id); - } - - $sql_condition = sprintf('(%sid_agente_modulo IN (%s))', $modules_table, $agent_condition); - - $group_conditions[] = $sql_condition; - - $i++; + } - if (!empty($group_conditions)) + if (!empty($group_conditions)) { $condition = implode(' OR ', $group_conditions); + } $condition = !empty($condition) ? "($condition)" : ''; return $condition; @@ -2446,7 +2425,7 @@ function tags_get_user_groups_and_tags ($id_user = false, $access = 'AR', $stric $return = array(); foreach ($acls as $acl) { - $return[$acl["id_grupo"]] = $acl["tags"]; + $return[$acl["id_grupo"]] = $acl["tags"][get_acl_column($access)]; } return $return; diff --git a/pandora_console/include/functions_users.php b/pandora_console/include/functions_users.php index 43603663a1..7c649409f5 100755 --- a/pandora_console/include/functions_users.php +++ b/pandora_console/include/functions_users.php @@ -207,24 +207,27 @@ function groups_combine_acl($acl_group_a, $acl_group_b){ "vconsole_management" => 1, "tags" => 1, ); + + if ($acl_group_a['tags']) users_get_explode_tags($acl_group_a); + if ($acl_group_b['tags']) users_get_explode_tags($acl_group_b); + + if (is_array($acl_group_a['tags']) && is_array($acl_group_b['tags'])) { + foreach ($acl_group_a['tags'] as $key => $value) { + $acl_group_b['tags'][$key] = implode( + ',', + array_merge( + $value, + $acl_group_b['tags'][$key] + ) + ); + } + } else if (is_array($acl_group_a['tags'])) { + $acl_group_b['tags'] = $acl_group_a['tags']; + } foreach ($acl_list as $acl => $aux) { - if($acl == "tags") { - // Mix tags - - if (isset($acl_group_a[$acl]) && ($acl_group_a[$acl] != "")) { - if (isset($acl_group_b[$acl]) && ($acl_group_b[$acl] != "")) { - if ($acl_group_b[$acl] != ($acl_group_a[$acl])) { - $acl_group_b[$acl] = $acl_group_a[$acl] . "," . $acl_group_b[$acl]; - } - } - else { - $acl_group_b[$acl] = $acl_group_a[$acl]; - } - } - continue; - } + if($acl == "tags") continue; // propagate ACL $acl_group_b[$acl] = $acl_group_a[$acl] || $acl_group_b[$acl]; } @@ -1069,4 +1072,17 @@ function users_get_strict_mode_groups($id_user, $return_group_all) { return $return_user_groups; } +function users_get_explode_tags(&$group) { + if (is_array($group['tags'])) return; + + $aux = explode(',', $group['tags']); + $group['tags'] = array(); + $group['tags']['agent_view'] = ($group['agent_view']) ? $aux : array(); + $group['tags']['agent_edit'] = ($group['agent_edit']) ? $aux : array(); + $group['tags']['agent_disable'] = ($group['agent_disable']) ? $aux : array(); + $group['tags']['event_view'] = ($group['event_view']) ? $aux : array(); + $group['tags']['event_edit'] = ($group['event_edit']) ? $aux : array(); + $group['tags']['event_management'] = ($group['event_management']) ? $aux : array(); +} + ?> diff --git a/pandora_console/operation/agentes/status_monitor.php b/pandora_console/operation/agentes/status_monitor.php index 61b4375d25..1b6cd954c5 100644 --- a/pandora_console/operation/agentes/status_monitor.php +++ b/pandora_console/operation/agentes/status_monitor.php @@ -87,16 +87,25 @@ if ($id_module) { enterprise_hook('open_meta_frame'); // Get Groups and profiles from user -$user_groups = implode (',', array_keys (users_get_groups ())); +$user_groups = implode (',', array_keys (users_get_groups (false,'AR',false))); //////////////////////////////////// // Begin Build SQL sentences -$sql_from = ' FROM ttipo_modulo,tagente LEFT JOIN tagent_secondary_group tasg ON tagente.id_agente = tasg.id_agent, tagente_modulo, tagente_estado,tmodule '; +$sql_from = " FROM tagente_modulo + INNER JOIN tagente + ON tagente_modulo.id_agente = tagente.id_agente + LEFT JOIN tagent_secondary_group tasg + ON tagente.id_agente = tasg.id_agent + INNER JOIN tagente_estado + ON tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo + INNER JOIN tmodule + ON tmodule.id_module = tagente_modulo.id_modulo + INNER JOIN ttipo_modulo + ON tagente_modulo.id_tipo_modulo = ttipo_modulo.id_tipo + LEFT JOIN ttag_module + ON tagente_modulo.id_agente_modulo = ttag_module.id_agente_modulo"; -$sql_conditions_base = ' WHERE tagente.id_agente = tagente_modulo.id_agente - AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo AND tagente_modulo.id_tipo_modulo = ttipo_modulo.id_tipo AND tmodule.id_module = tagente_modulo.id_modulo'; - -$sql_conditions = ' AND tagente.disabled = 0'; +$sql_conditions = ' WHERE tagente.disabled = 0'; if (is_numeric($ag_group)) { $id_ag_group = 0; @@ -261,8 +270,7 @@ if (!users_is_admin()) { } // Two modes of filter. All the filters and only ACLs filter -$sql_conditions_all = $sql_conditions_base . $sql_conditions . $sql_conditions_group . $sql_conditions_tags . $sql_conditions_custom_fields; -$sql_conditions_acl = $sql_conditions_base . $sql_conditions_group . $sql_conditions_tags . $sql_conditions_custom_fields; +$sql_conditions_all = $sql_conditions . $sql_conditions_group . $sql_conditions_tags . $sql_conditions_custom_fields; // Get count to paginate if (!defined('METACONSOLE')) @@ -337,8 +345,7 @@ $table->rowspan[0][6] = 2; $table->data[0][6] = html_print_submit_button (__('Show'), 'uptbutton', false, 'class="sub search" style="margin-top:0px;"',true); $modules = array(); -$modules = modules_get_modules_name ($sql_from , $sql_conditions_acl, is_metaconsole()); - +// TODO change for input text $table->data[1][0] = __('Module name'); $table->data[1][1] = html_print_select (index_array ($modules, 'nombre', 'nombre'), 'ag_modulename', $ag_modulename, '', __('All'), '', true, false, true, '', false, 'width: 150px;'); From 453fb3f67b15c0ea39bfd851da46379a62060832 Mon Sep 17 00:00:00 2001 From: danielmaya Date: Thu, 27 Sep 2018 13:30:32 +0200 Subject: [PATCH 02/42] TODO List --- .../extensions/matrix_events/ajax.php | 2 +- .../godmode/agentes/module_manager.php | 2 +- pandora_console/include/ajax/events.php | 2 +- pandora_console/include/ajax/module.php | 1 + pandora_console/include/functions_agents.php | 1 + pandora_console/include/functions_alerts.php | 1 + pandora_console/include/functions_events.php | 2 +- pandora_console/include/functions_graph.php | 3 + pandora_console/include/functions_tags.php | 104 ++++++++---------- pandora_console/mobile/operation/modules.php | 1 + .../agentes/estado_generalagente.php | 1 + .../operation/events/events.build_query.php | 1 + 12 files changed, 59 insertions(+), 62 deletions(-) diff --git a/pandora_console/extensions/matrix_events/ajax.php b/pandora_console/extensions/matrix_events/ajax.php index fc05d45f19..0dd7706784 100644 --- a/pandora_console/extensions/matrix_events/ajax.php +++ b/pandora_console/extensions/matrix_events/ajax.php @@ -30,7 +30,7 @@ if (is_ajax()) { require_once ('include/functions_tags.php'); $limit = (int) get_parameter("limit", 5); - + // TODO revision tag $tags_condition = tags_get_acl_tags($config['id_user'], 0, 'ER', 'event_condition', 'AND'); $filter = "estado<>1 $tags_condition"; diff --git a/pandora_console/godmode/agentes/module_manager.php b/pandora_console/godmode/agentes/module_manager.php index b475e29e2b..7debadbcfa 100644 --- a/pandora_console/godmode/agentes/module_manager.php +++ b/pandora_console/godmode/agentes/module_manager.php @@ -451,7 +451,7 @@ $where = sprintf("delete_pending = 0 AND id_agente = %s", $id_agente); $search_string_entities = io_safe_input($search_string); $basic_where = sprintf("(nombre LIKE '%%%s%%' OR nombre LIKE '%%%s%%' OR descripcion LIKE '%%%s%%' OR descripcion LIKE '%%%s%%') AND", $search_string, $search_string_entities, $search_string, $search_string_entities); - +// TODO revision tag $where_tags = tags_get_acl_tags($config['id_user'], 0, 'AR', 'module_condition', 'AND', 'tagente_modulo'); $paginate_module = false; diff --git a/pandora_console/include/ajax/events.php b/pandora_console/include/ajax/events.php index 7a367e8da0..5874ccc511 100644 --- a/pandora_console/include/ajax/events.php +++ b/pandora_console/include/ajax/events.php @@ -555,7 +555,7 @@ if ($table_events) { // Fix: for tag functionality groups have to be all user_groups (propagate ACL funct!) $groups = users_get_groups($config["id_user"]); - + // TODO revision tag $tags_condition = tags_get_acl_tags($config['id_user'], array_keys($groups), 'ER', 'event_condition', 'AND'); echo '
'; diff --git a/pandora_console/include/ajax/module.php b/pandora_console/include/ajax/module.php index 7f59e1f5d3..24fd4c9c78 100755 --- a/pandora_console/include/ajax/module.php +++ b/pandora_console/include/ajax/module.php @@ -551,6 +551,7 @@ if ($list_modules) { $groups = users_get_groups($config["id_user"], $access); if($cluster_list != 1){ + // TODO revision tag $tags_sql = tags_get_acl_tags($config['id_user'], array_keys($groups), $access, 'module_condition', 'AND', 'tagente_modulo', false, array(), true); diff --git a/pandora_console/include/functions_agents.php b/pandora_console/include/functions_agents.php index 45c72b2b83..ddb16d479b 100644 --- a/pandora_console/include/functions_agents.php +++ b/pandora_console/include/functions_agents.php @@ -1240,6 +1240,7 @@ function agents_get_modules ($id_agent = null, $details = false, //$where .= " AND id_policy_module = 0 "; if (tags_has_user_acl_tags($config['id_user'])){ + // TODO revision tag $where_tags = tags_get_acl_tags($config['id_user'], $id_groups, 'AR', 'module_condition', 'AND', 'tagente_modulo', false, array(), true); diff --git a/pandora_console/include/functions_alerts.php b/pandora_console/include/functions_alerts.php index 84419f5ab4..6d121d0f46 100644 --- a/pandora_console/include/functions_alerts.php +++ b/pandora_console/include/functions_alerts.php @@ -1814,6 +1814,7 @@ function get_group_alerts($id_group, $filter = '', $options = false, $groups = users_get_groups($config["id_user"]); if ($idGroup !== 0) { + // TODO revision tag $where_tags = tags_get_acl_tags($config['id_user'], $idGroup, 'AR', 'module_condition', 'AND', 'tagente_modulo', true, array(), true); } else { $where_tags = tags_get_acl_tags($config['id_user'], array_keys($groups), 'AR', 'module_condition', 'AND', 'tagente_modulo', true, array(), true); diff --git a/pandora_console/include/functions_events.php b/pandora_console/include/functions_events.php index f6b6da21cc..bfdc9e6238 100644 --- a/pandora_console/include/functions_events.php +++ b/pandora_console/include/functions_events.php @@ -3554,7 +3554,7 @@ function events_sql_events_grouped_agents($id_agent, $server_id = -1, else { $group_array = array_keys($groups); } - + // TODO revision tag $tags_acls_condition = tags_get_acl_tags($id_user, $group_array, 'ER', 'event_condition', 'AND', '', $meta, array(), true); //FORCE CHECK SQL "(TAG = tag1 AND id_grupo = 1)" diff --git a/pandora_console/include/functions_graph.php b/pandora_console/include/functions_graph.php index e8fa13df9f..53246a05f8 100644 --- a/pandora_console/include/functions_graph.php +++ b/pandora_console/include/functions_graph.php @@ -2471,6 +2471,7 @@ function graph_event_module ($width = 300, $height = 200, $id_agent) { // Fix: tag filters implemented! for tag functionality groups have to be all user_groups (propagate ACL funct!) $groups = users_get_groups($config["id_user"]); + // TODO revision tag $tags_condition = tags_get_acl_tags($config['id_user'], array_keys($groups), 'ER', 'event_condition', 'AND'); $data = array (); @@ -3350,6 +3351,7 @@ function grafico_eventos_grupo ($width = 300, $height = 200, $url = "", $meta = } // Add tags condition to filter + // TODO revision tag $tags_condition = tags_get_acl_tags($config['id_user'], 0, 'ER', 'event_condition', 'AND'); //This will give the distinct id_agente, give the id_grupo that goes @@ -3501,6 +3503,7 @@ function grafico_eventos_total($filter = "", $width = 320, $height = 200, $noWat $filter = str_replace ( "\\" , "", $filter); // Add tags condition to filter + // TODO revision tag $tags_condition = tags_get_acl_tags($config['id_user'], 0, 'ER', 'event_condition', 'AND'); $filter .= $tags_condition; diff --git a/pandora_console/include/functions_tags.php b/pandora_console/include/functions_tags.php index 9f06b23a53..b68c94dcd2 100644 --- a/pandora_console/include/functions_tags.php +++ b/pandora_console/include/functions_tags.php @@ -690,7 +690,7 @@ function tags_get_acl_tags($id_user, $id_group, $access = 'AR', case 'module_condition': // Return the condition of the tags for tagente_modulo table - $condition = tags_get_acl_tags_module_condition($acltags, + $condition = tags_get_acl_tags_module_condition_old($acltags, $query_table); if (!empty($condition)) { return " $query_prefix " . $condition; @@ -757,68 +757,54 @@ function tags_get_acl_tags_module_condition($acltags, $modules_table = '') { * @return string SQL condition for tagente_module */ function tags_get_acl_tags_module_condition_old($acltags, $modules_table = '') { - if (!empty($modules_table)) { + if (!empty($modules_table)) $modules_table .= '.'; - } - + $condition = ''; - - // Fix: Wrap SQL expression with "()" to avoid bad SQL sintax that makes Pandora retrieve all modules without taking care of id_agent => id_agent = X AND (sql_tag_expression) - $i = 0; + $group_conditions = array(); + + // The acltags array contains the groups with the acl propagation applied + // after the changes done into the 'tags_get_user_groups_and_tags' function. foreach ($acltags as $group_id => $group_tags) { - if ($condition != '') { - $condition .= ' OR '; + $tag_join = ''; + if (!empty($group_tags)) { + $tag_join = sprintf('INNER JOIN ttag_module ttmc + ON tamc.id_agente_modulo = ttmc.id_agente_modulo + AND ttmc.id_tag IN (%s)', + is_array($group_tags) ? implode(',', $group_tags) : $group_tags); } - - // Fix: Wrap SQL expression with "()" to avoid bad SQL sintax that makes Pandora retrieve all modules without taking care of id_agent => id_agent = X AND (sql_tag_expression) - if ($i == 0) - $condition .= ' ( ' . "\n"; - - // Group condition (The module belongs to an agent of the group X) - // Juanma (08/05/2014) Fix: Now group and tag is checked at the same time, before only tag was checked due to a bad condition - if (!array_key_exists(0, $acltags)) { - // Juanma (08/05/2014) Fix: get all groups recursively (Acl proc func!) - $group_condition = sprintf('%sid_agente IN (SELECT id_agente FROM tagente WHERE id_grupo IN (%s))', $modules_table, implode(',', array_values(groups_get_id_recursive($group_id)))); + // FIXME: Not properly way to increse performance + if(enterprise_hook('agents_is_using_secondary_groups')){ + $agent_condition = sprintf('SELECT tamc.id_agente_modulo + FROM tagente_modulo tamc + %s + INNER JOIN tagente tac + ON tamc.id_agente = tac.id_agente + LEFT JOIN tagent_secondary_group tasg + ON tasg.id_agent = tac.id_agente + WHERE (tac.id_grupo = %d OR tasg.id_group = %d)', + $tag_join, $group_id, $group_id); } - else { - //Avoid the user profiles with all group access. - $group_condition = " 1 = 1 "; + else{ + $agent_condition = sprintf('SELECT tamc.id_agente_modulo + FROM tagente_modulo tamc + %s + INNER JOIN tagente tac + ON tamc.id_agente = tac.id_agente + AND tac.id_grupo = %d', + $tag_join, $group_id); } - - //When the acl is only group without tags - if (empty($group_tags)) { - $condition .= "($group_condition)\n"; - } - else { - if (is_array($group_tags)) { - $group_tags_query = implode(',',$group_tags); - } else { - $group_tags_query = $group_tags; - } - // Tags condition (The module has at least one of the restricted tags) - $tags_condition = sprintf('%sid_agente_modulo IN (SELECT id_agente_modulo FROM ttag_module WHERE id_tag IN (%s))', $modules_table, $group_tags_query); - - $condition .= - " ( \n" . - " $group_condition \n" . - " AND \n" . - " $tags_condition \n" . - " )\n"; - } - + + $sql_condition = sprintf('(%sid_agente_modulo IN (%s))', $modules_table, $agent_condition); + + $group_conditions[] = $sql_condition; + $i++; } - - // Fix: Wrap SQL expression with "()" to avoid bad SQL sintax that makes Pandora retrieve all modules without taking care of id_agent => id_agent = X AND (sql_tag_expression) - if (!empty($acltags)) - $condition .= ' ) '; - - //Avoid the user profiles with all group access. - //if (!empty($condition)) { - if (!empty($condition) && - !array_key_exists(0, array_keys($acltags))) { - $condition = sprintf("\n((%s) OR %sid_agente NOT IN (SELECT id_agente FROM tagente WHERE id_grupo IN (%s)))", $condition, $modules_table, implode(',',array_keys($acltags))); - } + + if (!empty($group_conditions)) + $condition = implode(' OR ', $group_conditions); + $condition = !empty($condition) ? "($condition)" : ''; return $condition; } @@ -1042,6 +1028,7 @@ function tags_get_user_tags($id_user = false, $access = 'AR', $return_tag_any = } // Get the tags of the required access flag for each group + // TODO revision tag $tags = tags_get_acl_tags($id_user, 0, $access, 'data'); // If there are wrong parameters or fail ACL check, return false if ($tags_user === ERR_WRONG_PARAMETERS || $tags_user === ERR_ACL) { @@ -1130,6 +1117,7 @@ function tags_get_tags_for_module_search($id_user = false, $access = 'AR') { return false; } // Get the tags of the required access flag for each group + // TODO revision tag $tags = tags_get_acl_tags($id_user, 0, $access, 'data'); // If there are wrong parameters or fail ACL check, return false if ($tags_user === ERR_WRONG_PARAMETERS || $tags_user === ERR_ACL) { @@ -1213,7 +1201,7 @@ function tags_check_acl($id_user, $id_group, $access, $tags = array(), $flag_id_ $id_group[] = $parent['id_grupo']; } } - + // TODO revision tag $acls = tags_get_acl_tags($id_user, $id_group, $access, 'data'); // If there are wrong parameters or fail ACL check, return false @@ -1319,7 +1307,7 @@ function tags_check_acl_event($id_user, $id_group, $access, $tags = array(),$p = if($id_user === false) { $id_user = $config['id_user']; } - + // TODO revision tag $acls = tags_get_acl_tags($id_user, $id_group, $access, 'data'); // If there are wrong parameters or fail ACL check, return false @@ -1424,7 +1412,7 @@ function tags_checks_event_acl($id_user, $id_group, $access, $tags = array(), $c if (users_is_admin($id_user)) { return true; } - + // TODO revision tag $tags_user = tags_get_acl_tags($id_user, $id_group, $access, 'data', '', '', true, $childrens_ids, true); // If there are wrong parameters or fail ACL check, return false if ($tags_user === ERR_WRONG_PARAMETERS || $tags_user === ERR_ACL) { diff --git a/pandora_console/mobile/operation/modules.php b/pandora_console/mobile/operation/modules.php index 8971334eea..5b86254209 100644 --- a/pandora_console/mobile/operation/modules.php +++ b/pandora_console/mobile/operation/modules.php @@ -302,6 +302,7 @@ class Modules { // Part SQL for the Tag + // TODO revision tag $sql_conditions_tags = tags_get_acl_tags($user->getIdUser(), $user->getIdGroups($this->acl), $this->acl, 'module_condition', 'AND', 'tagente_modulo'); diff --git a/pandora_console/operation/agentes/estado_generalagente.php b/pandora_console/operation/agentes/estado_generalagente.php index 6dbb229c8b..73277400a5 100755 --- a/pandora_console/operation/agentes/estado_generalagente.php +++ b/pandora_console/operation/agentes/estado_generalagente.php @@ -550,6 +550,7 @@ if (!empty($network_interfaces)) { else { $group_array = $user_groups_ids; } + // TODO revision tag $acl_tags = tags_get_acl_tags($config['id_user'], $group_array, 'ER', 'event_condition', 'AND', '', true, array(), true); diff --git a/pandora_console/operation/events/events.build_query.php b/pandora_console/operation/events/events.build_query.php index 936d933143..69411d647a 100755 --- a/pandora_console/operation/events/events.build_query.php +++ b/pandora_console/operation/events/events.build_query.php @@ -310,6 +310,7 @@ if ($id_group > 0 && in_array ($id_group, array_keys ($groups))) { else { $group_array = array_keys($groups); } +// TODO revision tag if (check_acl ($id_user, 0, "ER")) $tags_acls_condition = tags_get_acl_tags($id_user, $group_array, 'ER', 'event_condition', 'AND', '', $meta, array(), true); //FORCE CHECK SQL "(TAG = tag1 AND id_grupo = 1)" From aceb67dd69930d4af5854b47f34a5a46c1186f48 Mon Sep 17 00:00:00 2001 From: danielmaya Date: Thu, 27 Sep 2018 18:11:13 +0200 Subject: [PATCH 03/42] [Tags performance] Improve event view --- pandora_console/include/functions_tags.php | 137 +++++++------------- pandora_console/include/functions_users.php | 49 ++++--- 2 files changed, 71 insertions(+), 115 deletions(-) diff --git a/pandora_console/include/functions_tags.php b/pandora_console/include/functions_tags.php index b68c94dcd2..e1f573e591 100644 --- a/pandora_console/include/functions_tags.php +++ b/pandora_console/include/functions_tags.php @@ -722,7 +722,8 @@ function tags_get_acl_tags_module_condition($acltags, $modules_table = '') { $condition = ''; $group_conditions = array(); - + + $without_tags = array(); $has_secondary = enterprise_hook('agents_is_using_secondary_groups'); // The acltags array contains the groups with the acl propagation applied // after the changes done into the 'tags_get_user_groups_and_tags' function. @@ -736,13 +737,21 @@ function tags_get_acl_tags_module_condition($acltags, $modules_table = '') { $agent_condition = sprintf('((tagente.id_grupo = %d %s)',$group_id,$tag_join); } $group_conditions[] = $agent_condition; + } else { + $without_tags[] = $group_id; } - } if (!empty($group_conditions)) { $condition = implode(' OR ', $group_conditions); } + if (!empty($without_tags)) { + if (!empty($condition)) { + $condition .= ' OR '; + } + $in_group = implode(",",$without_tags); + $condition .= sprintf('(tagente.id_grupo IN (%s) OR tasg.id_group IN (%s))',$in_group,$in_group); + } $condition = !empty($condition) ? "($condition)" : ''; return $condition; @@ -824,102 +833,50 @@ function tags_get_acl_tags_event_condition($acltags, $meta = false, $force_group // Get all tags of the system $all_tags = tags_get_all_tags(false); - - // Juanma (08/05/2014) Fix : Will have all groups retrieved (also propagated ones) - $_groups_not_in = ''; + $without_tags = array(); foreach ($acltags as $group_id => $group_tags) { - // Group condition (The module belongs to an agent of the group X) - $group_condition = sprintf('id_grupo IN (%s)', implode(',', array_values(groups_get_id_recursive($group_id, true)))); - //$_groups_not_in .= implode(',', array_values(groups_get_id_recursive($group_id))) . ','; - - // Tags condition (The module has at least one of the restricted tags) - $tags_condition = ''; + // NO check if there is not tag associated with groups if (empty($group_tags)) { - // FIXME: Not properly way to increse performance - if(enterprise_hook('agents_is_using_secondary_groups')){ - $tags_condition = "id_grupo = ".$group_id . " OR id_group = " . $group_id; - } - else{ - $tags_condition = "id_grupo = ".$group_id; - } - } - else { - if (!is_array($group_tags)) { - $group_tags = explode(',', $group_tags); - } - - foreach ($group_tags as $tag) { - // If the tag ID doesnt exist, ignore - if (!isset($all_tags[$tag])) { - continue; - } - - if ($tags_condition != '') { - $tags_condition .= " OR \n"; - } - - //~ // Add as condition all the posibilities of the serialized tags - //~ $tags_condition .= sprintf('tags LIKE "%s,%%"',io_safe_input($all_tags[$tag])); - //~ $tags_condition .= sprintf(' OR tags LIKE "%%,%s,%%"',io_safe_input($all_tags[$tag])); - //~ $tags_condition .= sprintf(' OR tags LIKE "%%,%s"',io_safe_input($all_tags[$tag])); - //~ $tags_condition .= sprintf(' OR tags LIKE "%s %%"',io_safe_input($all_tags[$tag])); - //~ $tags_condition .= sprintf(' OR tags LIKE "%%,%s %%"',io_safe_input($all_tags[$tag])); - - if ($force_group_and_tag) { - if (!empty($all_tags[$tag])) { - if ($force_equal) { - $tags_condition .= sprintf('(tags = "%s"',io_safe_input($all_tags[$tag])); - } else { - $tags_condition .= "(tags LIKE '%".io_safe_input($all_tags[$tag])."%'"; - } - $childrens = groups_get_childrens($group_id, null, true); - - if (empty($childrens)) { - $tags_condition .= sprintf(' AND id_grupo = %d )', $group_id); - } else { - $childrens_ids[] = $group_id; - foreach ($childrens as $child) { - $childrens_ids[] = (int)$child['id_grupo']; - } - $ids_str = implode(',', $childrens_ids); - - $tags_condition .= sprintf(' AND id_grupo IN (%s) )', $ids_str); - } - } else { - $tags_condition .= "id_grupo = ".$group_id; - } - } else { - if ($force_equal) { - $tags_condition .= sprintf('tags = "%s"',io_safe_input($all_tags[$tag])); - } else { - $tags_condition .= "tags LIKE '%".io_safe_input($all_tags[$tag])."%'"; - } - } - } - } - - // If there is not tag condition ignore - if (empty($tags_condition)) { + $without_tags []= $group_id; continue; } - - if ($condition != '') { - $condition .= ' OR '; + + // Group condition (The module belongs to an agent of the group X) + //$group_condition = sprintf('id_grupo IN (%s)', implode(',', array_values(groups_get_id_recursive($group_id, true)))); + $group_condition = "(id_grupo = $group_id OR id_group = $group_id)"; + + // Tags condition (The module has at least one of the restricted tags) + $tags_condition = ''; + $tags_condition_array = array(); + + foreach ($group_tags as $tag) { + // If the tag ID doesnt exist, ignore + if (!isset($all_tags[$tag])) continue; + + $tags_condition_array[] = $force_equal + ? sprintf('tags = "%s"',io_safe_input($all_tags[$tag])) + : "tags LIKE '%".io_safe_input($all_tags[$tag])."%'"; } - $condition .= "($tags_condition)\n"; + // If there is not tag currently in Pandora, block the group info + if (empty($tags_condition_array)) { + $tags_condition_array[] = "1=0"; + } + + $tags_condition = $group_condition . " AND (" . implode(" OR ", $tags_condition_array) . ")"; + $condition[] = "($tags_condition)\n"; } - - //Commented because ACLs propagation don't work -/* - if (!empty($condition)) { - // Juanma (08/05/2014) Fix : Also add events of other groups (taking care of propagate ACLs func!) - if (!empty($_groups_not_in)) - $condition = sprintf("\n((%s) OR id_grupo NOT IN (%s))", $condition, rtrim($_groups_not_in, ',')); + if (empty($condition)) { + return " 1=1 "; + } + $condition = implode(' OR ', $condition); + + if (!empty($without_tags)) { + $condition .= ' OR '; + $in_group = implode(",",$without_tags); + $condition .= sprintf('(id_grupo IN (%s) OR id_group IN (%s))',$in_group,$in_group); } -*/ - return $condition; } @@ -2413,7 +2370,7 @@ function tags_get_user_groups_and_tags ($id_user = false, $access = 'AR', $stric $return = array(); foreach ($acls as $acl) { - $return[$acl["id_grupo"]] = $acl["tags"][get_acl_column($access)]; + $return[$acl["id_grupo"]] = implode(",",$acl["tags"][get_acl_column($access)]); } return $return; diff --git a/pandora_console/include/functions_users.php b/pandora_console/include/functions_users.php index 7c649409f5..6c609006c5 100755 --- a/pandora_console/include/functions_users.php +++ b/pandora_console/include/functions_users.php @@ -207,22 +207,9 @@ function groups_combine_acl($acl_group_a, $acl_group_b){ "vconsole_management" => 1, "tags" => 1, ); - - if ($acl_group_a['tags']) users_get_explode_tags($acl_group_a); - if ($acl_group_b['tags']) users_get_explode_tags($acl_group_b); - if (is_array($acl_group_a['tags']) && is_array($acl_group_b['tags'])) { - foreach ($acl_group_a['tags'] as $key => $value) { - $acl_group_b['tags'][$key] = implode( - ',', - array_merge( - $value, - $acl_group_b['tags'][$key] - ) - ); - } - } else if (is_array($acl_group_a['tags'])) { - $acl_group_b['tags'] = $acl_group_a['tags']; + foreach ($acl_group_a['tags'] as $key => $value) { + $acl_group_b['tags'][$key] = array_merge($value, $acl_group_b['tags'][$key]); } foreach ($acl_list as $acl => $aux) { @@ -289,6 +276,8 @@ function users_get_groups ($id_user = false, $privilege = "AR", $returnAllGroup foreach ($raw_forest as $g) { // XXX, following code must be remade (TAG) + users_get_explode_tags($g); + if (!isset($forest_acl[$g["id_grupo"]] )) { $forest_acl[$g["id_grupo"]] = $g; } @@ -1073,16 +1062,26 @@ function users_get_strict_mode_groups($id_user, $return_group_all) { } function users_get_explode_tags(&$group) { - if (is_array($group['tags'])) return; - - $aux = explode(',', $group['tags']); - $group['tags'] = array(); - $group['tags']['agent_view'] = ($group['agent_view']) ? $aux : array(); - $group['tags']['agent_edit'] = ($group['agent_edit']) ? $aux : array(); - $group['tags']['agent_disable'] = ($group['agent_disable']) ? $aux : array(); - $group['tags']['event_view'] = ($group['event_view']) ? $aux : array(); - $group['tags']['event_edit'] = ($group['event_edit']) ? $aux : array(); - $group['tags']['event_management'] = ($group['event_management']) ? $aux : array(); + + if (empty($group['tags'])) { + $group['tags'] = array(); + $group['tags']['agent_view'] = array(); + $group['tags']['agent_edit'] = array(); + $group['tags']['agent_disable'] = array(); + $group['tags']['event_view'] = array(); + $group['tags']['event_edit'] = array(); + $group['tags']['event_management'] = array(); + } else { + $aux = explode(',', $group['tags']); + $group['tags'] = array(); + $group['tags']['agent_view'] = ($group['agent_view']) ? $aux : array(); + $group['tags']['agent_edit'] = ($group['agent_edit']) ? $aux : array(); + $group['tags']['agent_disable'] = ($group['agent_disable']) ? $aux : array(); + $group['tags']['event_view'] = ($group['event_view']) ? $aux : array(); + $group['tags']['event_edit'] = ($group['event_edit']) ? $aux : array(); + $group['tags']['event_management'] = ($group['event_management']) ? $aux : array(); + } + } ?> From 81e15c4dc9708b65433d7125c219e8e27424222e Mon Sep 17 00:00:00 2001 From: fermin831 Date: Fri, 28 Sep 2018 09:37:16 +0200 Subject: [PATCH 04/42] Fixed tags on Tree view --- pandora_console/include/class/Tree.class.php | 3 --- pandora_console/include/class/TreeTag.class.php | 4 ++++ 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/pandora_console/include/class/Tree.class.php b/pandora_console/include/class/Tree.class.php index b72e3ec216..11f7fa56c5 100644 --- a/pandora_console/include/class/Tree.class.php +++ b/pandora_console/include/class/Tree.class.php @@ -909,9 +909,6 @@ class Tree { tam.id_tipo_modulo, tam.id_modulo, tae.estado, tae.datos, tam.parent_module_id AS parent, tatm.id AS alerts'; - // has any of this tags. - $tag_join = ''; - $sql = "SELECT $columns FROM tagente_modulo tam $tag_join diff --git a/pandora_console/include/class/TreeTag.class.php b/pandora_console/include/class/TreeTag.class.php index c6562db725..516dceb3db 100644 --- a/pandora_console/include/class/TreeTag.class.php +++ b/pandora_console/include/class/TreeTag.class.php @@ -48,6 +48,10 @@ class TreeTag extends Tree { $this->getThirdLevel(); } } + + protected function getTagJoin () { + return ''; + } } ?> From 015d7eea093eba93ae2633533159962d3dfc1c90 Mon Sep 17 00:00:00 2001 From: fermin831 Date: Fri, 28 Sep 2018 12:37:11 +0200 Subject: [PATCH 05/42] [Tags performance] Fixed acl propagation in child groups --- pandora_console/include/functions_users.php | 1 + 1 file changed, 1 insertion(+) diff --git a/pandora_console/include/functions_users.php b/pandora_console/include/functions_users.php index 6c609006c5..e368a52b4a 100755 --- a/pandora_console/include/functions_users.php +++ b/pandora_console/include/functions_users.php @@ -306,6 +306,7 @@ function users_get_groups ($id_user = false, $privilege = "AR", $returnAllGroup } else { // add group to user ACL forest + users_get_explode_tags($group); $tmp = groups_combine_acl($forest_acl[$parent], $group); } if ($tmp !== null) { From debf8db577ad86439da08a59c27c9a3c77473f70 Mon Sep 17 00:00:00 2001 From: fermin831 Date: Fri, 28 Sep 2018 12:39:23 +0200 Subject: [PATCH 06/42] [Tags performance] Added some TODOs --- pandora_console/include/functions_tags.php | 1 + pandora_console/operation/agentes/tactical.php | 1 + 2 files changed, 2 insertions(+) diff --git a/pandora_console/include/functions_tags.php b/pandora_console/include/functions_tags.php index e1f573e591..7bd6d8d216 100644 --- a/pandora_console/include/functions_tags.php +++ b/pandora_console/include/functions_tags.php @@ -698,6 +698,7 @@ function tags_get_acl_tags($id_user, $id_group, $access = 'AR', break; case 'event_condition': // Return the condition of the tags for tevento table + // TODO event tag revision $condition = tags_get_acl_tags_event_condition($acltags, $meta, $force_group_and_tag); if (!empty($condition)) { diff --git a/pandora_console/operation/agentes/tactical.php b/pandora_console/operation/agentes/tactical.php index 578c0c6af4..82b0368b66 100755 --- a/pandora_console/operation/agentes/tactical.php +++ b/pandora_console/operation/agentes/tactical.php @@ -180,6 +180,7 @@ echo ' operator $operatorDistin = false; if (strlen($value) > 2) { @@ -1163,111 +1140,77 @@ function agents_get_modules ($id_agent = null, $details = false, $operatorDistin = true; } } - + if ($value[0] == '%') { - switch ($config['dbtype']) { - case "mysql": - case "postgresql": - array_push ($fields, - $field . ' LIKE "' . $value . '"'); - break; - case "oracle": - array_push ($fields, - $field . ' LIKE \'' . $value . '\''); - break; - } + array_push ($fields, + $field . ' LIKE "' . $value . '"'); } else if ($operatorDistin) { array_push($fields, $field.' <> ' . substr($value, 2)); } else if (substr($value, -1) == '%') { - switch ($config['dbtype']) { - case "mysql": - case "postgresql": - array_push ($fields, $field.' LIKE "'.$value.'"'); - break; - case "oracle": - array_push ($fields, $field.' LIKE \''.$value.'\''); - break; - } + array_push ($fields, $field.' LIKE "'.$value.'"'); } - //else if (strstr($value, '666=666', true) == '') { else if (strncmp($value, '666=666', 7) == 0) { - switch ($config['dbtype']) { - case "mysql": - case "postgresql": - array_push ($fields, ' '.$value); - break; - case "oracle": - array_push ($fields, ' '.$value); - break; - } + array_push ($fields, ' '.$value); } else if (preg_match('/\bin\b/i',$field)) { array_push ($fields, $field.' '.$value); } else { - switch ($config["dbtype"]) { - case "mysql": - array_push ($fields, $field.' = "'.$value.'"'); - break; - case "postgresql": - array_push ($fields, $field.' = \''.$value.'\''); - break; - case "oracle": - if (is_int ($value) || is_float ($value) || is_double ($value)) - array_push ($fields, $field.' = '.$value.''); - else - array_push ($fields, $field.' = \''.$value.'\''); - break; - } + array_push ($fields, 'tagente_modulo.' . $field.' = "'.$value.'"'); } } - $where .= implode (' AND ', $fields); + $where .= implode (' AND ', $fields); } else { $where .= $filter; } } - + if (empty ($details)) { - $details = "nombre"; + $details = "tagente_modulo.nombre"; } - else { + else { + $details = (array)$details; $details = io_safe_input ($details); + $details = array_map(function ($a) { return 'tagente_modulo.' . $a;}, $details); } - - //$where .= " AND id_policy_module = 0 "; - + + $sql_tags_join = ""; if (tags_has_user_acl_tags($config['id_user'])){ - // TODO revision tag $where_tags = tags_get_acl_tags($config['id_user'], $id_groups, 'AR', 'module_condition', 'AND', 'tagente_modulo', false, array(), - true); - + true); $where .= "\n\n" . $where_tags; + $sql_tags_join = "INNER JOIN ttag_module + ON ttag_module.id_agente_modulo = tagente_modulo.id_agente_modulo"; } - + $sql = sprintf ('SELECT %s%s FROM tagente_modulo - WHERE - %s - ORDER BY nombre', - ($details != '*' && $indexed) ? 'id_agente_modulo,' : '', + %s + INNER JOIN tagente + ON tagente.id_agente = tagente_modulo.id_agente + LEFT JOIN tagent_secondary_group tasg + ON tagente.id_agente = tasg.id_agent + WHERE tagente_modulo.delete_pending = 0 + AND %s + GROUP BY tagente_modulo.id_agente_modulo + ORDER BY tagente_modulo.nombre', + ($details != 'tagente_modulo.*' && $indexed) ? 'tagente_modulo.id_agente_modulo,' : '', io_safe_output(implode (",", (array) $details)), + $sql_tags_join, $where); - - $result = db_get_all_rows_sql ($sql); - - + if (empty ($result)) { return array (); } - + if (! $indexed) return $result; - + $modules = array (); foreach ($result as $module) { if ($get_not_init_modules || modules_get_agentmodule_is_init($module['id_agente_modulo'])) { @@ -2589,75 +2532,67 @@ function agents_get_agent_custom_field ($agent_id, $custom_field_name) { return db_get_value_sql($sql); } -function select_modules_for_agent_group($id_group, $id_agents, - $selection, $return = true) { - +function select_modules_for_agent_group( + $id_group, $id_agents, $selection, $return = true +) { + global $config; $agents = implode(",", $id_agents); + $filter_agent_group = ""; $filter_group = ""; $filter_agent = ""; + $selection_filter = ""; + $sql_conditions_tags = ""; + $sql_tags_inner = ""; + + $groups = array_keys(users_get_groups(false, "AR", false)); if ($id_group != 0) { - $filter_group = " AND id_module_group = ". $id_group; + $filter_group = " AND tagente_modulo.id_module_group = ". $id_group; } if ($agents != null) { - $filter_agent = " AND id_agente IN (" . $agents . ")"; + $filter_agent = " AND tagente.id_agente IN (" . $agents . ")"; + } + if (!users_can_manage_group_all("AR")) { + $group_string = implode(',', $groups); + $filter_agent_group = " AND ( + tagente.id_grupo IN ($group_string) + OR tasg.id_group IN ($group_string) + )"; + } + if (!$selection && $agents != null) { + $number_agents = count($id_agents); + $selection_filter = "HAVING COUNT(tagente_modulo.id_agente_modulo) = $number_agents"; } - if ($selection == 1 || (count($id_agents) == 1)) { - $modules = db_get_all_rows_sql("SELECT DISTINCT nombre, id_agente_modulo - FROM tagente_modulo - WHERE 1 = 1" . $filter_agent . $filter_group); - - if (empty($modules)) $modules = array(); - - $found = array(); - foreach ($modules as $i=>$row) { - $check = $row['nombre']; - if (@$found[$check]++) { - unset($modules[$i]); - } - } + if (tags_has_user_acl_tags(false)){ + $sql_conditions_tags = tags_get_acl_tags( + $config['id_user'], $groups, 'AR', + 'module_condition', 'AND', 'tagente_modulo', true, array(), + false); + $sql_tags_inner = "INNER JOIN ttag_module + ON ttag_module.id_agente_modulo = tagente_modulo.id_agente_modulo"; } - else { - $modules = db_get_all_rows_sql("SELECT nombre, id_agente_modulo - FROM tagente_modulo - WHERE 1 = 1" . $filter_agent . $filter_group); - if (empty($modules)) $modules = array(); + $sql = "SELECT DISTINCT(tagente_modulo.id_agente_modulo), tagente_modulo.nombre + FROM tagente_modulo + $sql_tags_inner + INNER JOIN tagente + ON tagente.id_agente = tagente_modulo.id_agente + LEFT JOIN tagent_secondary_group tasg + ON tagente.id_agente = tasg.id_agent + WHERE tagente.disabled = 0 + AND tagente_modulo.disabled = 0 + $filter_agent_group + $filter_group + $filter_agent + $sql_conditions_tags + GROUP BY tagente_modulo.nombre + $selection_filter"; - foreach ($modules as $m) { - $is_in_all_agents = true; - $module_name = $m['nombre']; - foreach ($id_agents as $a) { - $module_in_agent = db_get_value_filter('id_agente_modulo', - 'tagente_modulo', array('id_agente' => $a, 'nombre' => $module_name)); - if (!$module_in_agent) { - $is_in_all_agents = false; - } - } - if ($is_in_all_agents) { - $modules_to_report[] = $m; - } - } - $modules = $modules_to_report; + $modules = db_get_all_rows_sql($sql); + if ($modules === false) $modules = array(); - $found = array(); - if (is_array($modules) || is_object($modules)){ - foreach ($modules as $i=>$row) { - $check = $row['nombre']; - if (@$found[$check]++) { - unset($modules[$i]); - } - } - } - } - if (is_array($modules) || is_object($modules)){ - foreach ($modules as $k => $v) { - $modules[$k] = io_safe_output($v); - } - } - if($return == false){ foreach ($modules as $value) { $modules_array[$value['id_agente_modulo']] = $value['nombre']; diff --git a/pandora_console/include/functions_tags.php b/pandora_console/include/functions_tags.php index 7bd6d8d216..c785ee1297 100644 --- a/pandora_console/include/functions_tags.php +++ b/pandora_console/include/functions_tags.php @@ -690,7 +690,7 @@ function tags_get_acl_tags($id_user, $id_group, $access = 'AR', case 'module_condition': // Return the condition of the tags for tagente_modulo table - $condition = tags_get_acl_tags_module_condition_old($acltags, + $condition = tags_get_acl_tags_module_condition($acltags, $query_table); if (!empty($condition)) { return " $query_prefix " . $condition; @@ -698,7 +698,6 @@ function tags_get_acl_tags($id_user, $id_group, $access = 'AR', break; case 'event_condition': // Return the condition of the tags for tevento table - // TODO event tag revision $condition = tags_get_acl_tags_event_condition($acltags, $meta, $force_group_and_tag); if (!empty($condition)) { @@ -868,16 +867,20 @@ function tags_get_acl_tags_event_condition($acltags, $meta = false, $force_group $tags_condition = $group_condition . " AND (" . implode(" OR ", $tags_condition_array) . ")"; $condition[] = "($tags_condition)\n"; } - if (empty($condition)) { - return " 1=1 "; + if (!empty($condition)) { + $condition = implode(' OR ', $condition); } - $condition = implode(' OR ', $condition); if (!empty($without_tags)) { - $condition .= ' OR '; + if (!empty($condition)) { + $condition .= ' OR '; + } $in_group = implode(",",$without_tags); $condition .= sprintf('(id_grupo IN (%s) OR id_group IN (%s))',$in_group,$in_group); } + + $condition = !empty($condition) ? "($condition)" : ''; + return $condition; } @@ -898,15 +901,14 @@ function tags_has_user_acl_tags($id_user = false) { if(is_user_admin($id_user)) { return false; } - - $query = sprintf("SELECT count(*) - FROM tusuario_perfil, tperfil - WHERE tperfil.id_perfil = tusuario_perfil.id_perfil AND - tusuario_perfil.id_usuario = '%s' AND tags != ''", - $id_user); - + + $query = "SELECT count(*) + FROM tusuario_perfil + WHERE tusuario_perfil.id_usuario = '$id_user' + AND tags != '' AND tags !='0'"; + $user_tags = db_get_value_sql($query); - + return (bool)$user_tags; } diff --git a/pandora_console/operation/agentes/tactical.php b/pandora_console/operation/agentes/tactical.php index 82b0368b66..43d0127ce7 100755 --- a/pandora_console/operation/agentes/tactical.php +++ b/pandora_console/operation/agentes/tactical.php @@ -177,16 +177,15 @@ echo '1"; if (!empty($tags_condition)) { - $events = events_print_event_table ("estado<>1 AND ($tags_condition)", 10, "100%",true,false,true); - ui_toggle($events, __('Latest events'),false,false); + $event_filter .= " AND ($tags_condition)"; } + $events = events_print_event_table ($event_filter, 10, "100%",true,false,true); + ui_toggle($events, __('Latest events'),false,false); } // --------------------------------------------------------------------- From 995bfe0fad907b7b9e322c45948b326d28412f4d Mon Sep 17 00:00:00 2001 From: fermin831 Date: Mon, 1 Oct 2018 17:04:00 +0200 Subject: [PATCH 08/42] Removed unused code --- pandora_console/extensions/agents_modules.php | 25 +++++-------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/pandora_console/extensions/agents_modules.php b/pandora_console/extensions/agents_modules.php index 98dacdc7e5..790a16ec15 100644 --- a/pandora_console/extensions/agents_modules.php +++ b/pandora_console/extensions/agents_modules.php @@ -70,7 +70,7 @@ function mainAgentsModules() { $hor_offset = (int)get_parameter('hor_offset', 0); $block = $config['block_size']; if(get_parameter('modulegroup') != null){ - $agents_id = (array)get_parameter('id_agents2', -1); + $agents_id = (array)get_parameter('id_agents2', -1); } $selection_a_m = (int)get_parameter('selection_agent_module'); $modules_selected = (array)get_parameter('module', 0); @@ -100,6 +100,9 @@ function mainAgentsModules() { if($agents_id[0] != -1 ){ serialize_in_temp($agents_id, $config['id_user']."_agents", 1); } + + + //if($agents_id != -1) $agents_id = null; if ($config["pure"] == 0) { if($modules_selected[0] && $agents_id[0]){ @@ -144,18 +147,7 @@ function mainAgentsModules() { $filter_module_groups_label = ''.__('Module group').''; $filter_module_groups = html_print_select_from_sql ("SELECT * FROM tmodule_group ORDER BY name", 'modulegroup', $modulegroup, '',__('All'), 0, true, false, true, false, 'width: auto;'); - - $agents_select = array(); - if (is_array($id_agents) || is_object($id_agents)){ - foreach ($id_agents as $id) { - foreach ($agents as $key => $a) { - if ($key == (int)$id) { - $agents_select[$key] = $key; - } - } - } - } - + //agent $agents = agents_get_group_agents($group_id); if ((empty($agents)) || $agents == -1) $agents = array(); @@ -301,7 +293,6 @@ function mainAgentsModules() { $count++; } $total_pagination = count($agents); - if($agents_id[0] != -1){ $all_modules = array(); foreach ($modules_selected as $key => $value) { @@ -332,8 +323,7 @@ function mainAgentsModules() { foreach ($result_sql as $key => $value) { $all_modules[$value['id_agente_modulo']] = io_safe_output($name); } - } - // $all_modules[$value] = modules_get_agentmodule_name($value); + } } } else { @@ -346,7 +336,6 @@ function mainAgentsModules() { $modules_by_name = array(); $name = ''; $cont = 0; - foreach ($all_modules as $key => $module) { if ($module == $name) { $modules_by_name[$cont-1]['id'][] = $key; @@ -358,7 +347,6 @@ function mainAgentsModules() { $cont ++; } } - if ($config["pure"] == 1) { $block = count($modules_by_name); } @@ -502,7 +490,6 @@ function mainAgentsModules() { $agent_modules = agents_get_modules($agent['id_agente'], false, $filter_module_group, true, true); $nmodules = 0; - foreach ($modules_by_name as $module) { $nmodules++; From 28b879f0585f80573407225fa541b115e57cbaed Mon Sep 17 00:00:00 2001 From: fermin831 Date: Tue, 2 Oct 2018 09:48:29 +0200 Subject: [PATCH 09/42] [Tags performance] Added TODOS to revise agents_get_modules --- pandora_console/extensions/agents_modules.php | 3 +++ pandora_console/extensions/insert_data.php | 1 + pandora_console/extras/pandora_diag.php | 2 +- .../godmode/alerts/alert_list.builder.php | 1 + .../godmode/massive/massive_add_tags.php | 1 + .../godmode/massive/massive_copy_modules.php | 1 + .../godmode/massive/massive_delete_alerts.php | 1 + .../massive/massive_delete_modules.php | 4 +++- .../godmode/massive/massive_edit_modules.php | 2 +- .../visual_console_builder.elements.php | 1 + .../reporting/visual_console_builder.php | 2 +- .../ajax/visual_console_builder.ajax.php | 3 +++ pandora_console/include/functions_agents.php | 12 +++++++---- pandora_console/include/functions_graph.php | 2 ++ pandora_console/include/functions_modules.php | 4 ++-- .../include/functions_networkmap.php | 20 ++++++------------- .../include/functions_reporting.php | 8 ++++---- .../include/functions_reporting_html.php | 1 + .../agentes/estado_generalagente.php | 1 - .../operation/agentes/estado_monitores.php | 3 --- .../operation/agentes/exportdata.php | 1 + pandora_console/operation/agentes/graphs.php | 6 +++--- .../agentes/pandora_networkmap.view.php | 2 +- .../operation/agentes/ver_agente.php | 5 ++--- 24 files changed, 48 insertions(+), 39 deletions(-) diff --git a/pandora_console/extensions/agents_modules.php b/pandora_console/extensions/agents_modules.php index 790a16ec15..8e33c4180e 100644 --- a/pandora_console/extensions/agents_modules.php +++ b/pandora_console/extensions/agents_modules.php @@ -285,6 +285,7 @@ function mainAgentsModules() { $count = 0; foreach ($agents as $agent) { + // TODO TAGS agents_get_modules $module = agents_get_modules($agent, false, $filter_module_group, true, true); if ($module == false) { @@ -327,6 +328,7 @@ function mainAgentsModules() { } } else { + // TODO TAGS agents_get_modules $all_modules = agents_get_modules($agents, false, $filter_module_group, true, true); } @@ -487,6 +489,7 @@ function mainAgentsModules() { " . $alias['alias'] . ""; + // TODO TAGS agents_get_modules $agent_modules = agents_get_modules($agent['id_agente'], false, $filter_module_group, true, true); $nmodules = 0; diff --git a/pandora_console/extensions/insert_data.php b/pandora_console/extensions/insert_data.php index 5cfcc331d0..698938aa63 100644 --- a/pandora_console/extensions/insert_data.php +++ b/pandora_console/extensions/insert_data.php @@ -174,6 +174,7 @@ function mainInsertData() { $table->data[1][0] = __('Module'); $modules = array (); if ($agent_id){ + // TODO TAGS agents_get_modules $modules = agents_get_modules ($agent_id, false, array("delete_pending" => 0)); } $table->data[1][1] = html_print_select ($modules, 'id_agent_module', $id_agent_module, true, diff --git a/pandora_console/extras/pandora_diag.php b/pandora_console/extras/pandora_diag.php index 4c851238ad..0b4be02ae1 100644 --- a/pandora_console/extras/pandora_diag.php +++ b/pandora_console/extras/pandora_diag.php @@ -612,7 +612,7 @@ echo "data[0][0] = __('Module'); $modules = array (); +// TODO TAGS agents_get_modules if ($id_agente) $modules = agents_get_modules ($id_agente, false, array("delete_pending" => 0)); diff --git a/pandora_console/godmode/massive/massive_add_tags.php b/pandora_console/godmode/massive/massive_add_tags.php index 6d97f0d9e9..729f2dcfcb 100755 --- a/pandora_console/godmode/massive/massive_add_tags.php +++ b/pandora_console/godmode/massive/massive_add_tags.php @@ -55,6 +55,7 @@ function process_manage_add ($id_agents, $modules, $id_tags) { if (count($modules) == 1 && $modules[0] == '0') { foreach ($id_agents as $id_agent) { + // TODO TAGS agents_get_modules $modules_temp = agents_get_modules($id_agent); foreach ($modules_temp as $id_module => $name_module) { $modules_id[] = $id_module; diff --git a/pandora_console/godmode/massive/massive_copy_modules.php b/pandora_console/godmode/massive/massive_copy_modules.php index aae7d4e2df..23739110d1 100755 --- a/pandora_console/godmode/massive/massive_copy_modules.php +++ b/pandora_console/godmode/massive/massive_copy_modules.php @@ -120,6 +120,7 @@ $table->class = 'databox filters'; $table->data = array (); $modules = array (); +// TODO TAGS agents_get_modules if ($source_id_agent) $modules = agents_get_modules ($source_id_agent, 'nombre'); diff --git a/pandora_console/godmode/massive/massive_delete_alerts.php b/pandora_console/godmode/massive/massive_delete_alerts.php index eb0fd60dc3..f96f467672 100755 --- a/pandora_console/godmode/massive/massive_delete_alerts.php +++ b/pandora_console/godmode/massive/massive_delete_alerts.php @@ -120,6 +120,7 @@ function process_manage_delete ($id_alert_template, $id_agents, $module_names) { $modules_id = array(); foreach ($id_agents as $id_agent) { + // TODO TAGS agents_get_modules $current_modules_agent = agents_get_modules($id_agent, 'id_agente_modulo', array ('disabled' => 0)); if ($current_modules_agent != false) { // And their modules diff --git a/pandora_console/godmode/massive/massive_delete_modules.php b/pandora_console/godmode/massive/massive_delete_modules.php index d1dd485db2..26bcb7ec19 100755 --- a/pandora_console/godmode/massive/massive_delete_modules.php +++ b/pandora_console/godmode/massive/massive_delete_modules.php @@ -137,6 +137,7 @@ function process_manage_delete ($module_name, $id_agents, $module_status = 'all' } } else { + // TODO TAGS agents_get_modules $modules = agents_get_modules ($id_agents, 'id_agente_modulo', $filter_for_module_deletion, true); } @@ -212,6 +213,7 @@ function process_manage_delete ($module_name, $id_agents, $module_status = 'all' } } else { + // TODO TAGS agents_get_modules $modules = agents_get_modules ($id_agents, 'id_agente_modulo', sprintf('nombre IN ("%s")', implode('","',$module_name)), true); } @@ -439,7 +441,7 @@ if ($module_type != '') { else { $filter = false; } - +// TODO TAGS agents_get_modules $names = agents_get_modules (array_keys ($agents), 'DISTINCT(nombre)', $filter, false); foreach ($names as $name) { diff --git a/pandora_console/godmode/massive/massive_edit_modules.php b/pandora_console/godmode/massive/massive_edit_modules.php index e7f92d4594..4d326a8e22 100755 --- a/pandora_console/godmode/massive/massive_edit_modules.php +++ b/pandora_console/godmode/massive/massive_edit_modules.php @@ -276,7 +276,7 @@ if ($module_type != '') { else { $filter = false; } - +// TODO TAGS agents_get_modules $names = agents_get_modules (array_keys ($agents), 'DISTINCT(nombre)', $filter, false); foreach ($names as $name) { diff --git a/pandora_console/godmode/reporting/visual_console_builder.elements.php b/pandora_console/godmode/reporting/visual_console_builder.elements.php index c7e63358fa..3bd89eba92 100755 --- a/pandora_console/godmode/reporting/visual_console_builder.elements.php +++ b/pandora_console/godmode/reporting/visual_console_builder.elements.php @@ -416,6 +416,7 @@ foreach ($layoutDatas as $layoutData) { } if ($cell_content_enterprise === false) { if (!defined('METACONSOLE')) { + // TODO TAGS agents_get_modules $modules = agents_get_modules($layoutData['id_agent']); } else { diff --git a/pandora_console/godmode/reporting/visual_console_builder.php b/pandora_console/godmode/reporting/visual_console_builder.php index 6e3654f914..bfe7c3228a 100755 --- a/pandora_console/godmode/reporting/visual_console_builder.php +++ b/pandora_console/godmode/reporting/visual_console_builder.php @@ -560,7 +560,7 @@ switch ($activeTab) { foreach ($name_modules as $mod) { foreach ($id_agents as $ag) { - + // TODO TAGS agents_get_modules $id_module = agents_get_modules($ag, array('id_agente_modulo'), array('nombre' => $mod)); diff --git a/pandora_console/include/ajax/visual_console_builder.ajax.php b/pandora_console/include/ajax/visual_console_builder.ajax.php index 98be4f174b..1226e2a09c 100755 --- a/pandora_console/include/ajax/visual_console_builder.ajax.php +++ b/pandora_console/include/ajax/visual_console_builder.ajax.php @@ -960,6 +960,7 @@ switch ($action) { //Make the html of select box of modules about id_agent. if (($elementFields['id_agent'] != 0) &&($elementFields['id_layout_linked'] == 0)) { + // TODO TAGS agents_get_modules $modules = agents_get_modules( $elementFields['id_agent'], false, array('disabled' => 0, @@ -1022,6 +1023,7 @@ switch ($action) { $elementFields['id_agent_string'] = $elementFields['id_agent']; if (($elementFields['id_agent_string'] != 0) && ($elementFields['id_layout_linked'] == 0)) { + // TODO TAGS agents_get_modules $modules = agents_get_modules( $elementFields['id_agent'], false, array('disabled' => 0, @@ -1050,6 +1052,7 @@ switch ($action) { $elementFields['id_agent_string'] = $elementFields['id_agent']; if (($elementFields['id_agent_string'] != 0) && ($elementFields['id_layout_linked'] == 0)) { + // TODO TAGS agents_get_modules $modules = agents_get_modules( $elementFields['id_agent'], false, array('disabled' => 0, diff --git a/pandora_console/include/functions_agents.php b/pandora_console/include/functions_agents.php index 6d16c72e7e..925ff4d6c6 100644 --- a/pandora_console/include/functions_agents.php +++ b/pandora_console/include/functions_agents.php @@ -205,6 +205,7 @@ function agents_get_alerts_simple ($id_agent = false, $filter = '', $options = f } else { $id_agent = (array) $id_agent; + // TODO TAGS agents_get_modules $id_modules = array_keys (agents_get_modules ($id_agent, false, array('delete_pending' => 0))); if (empty ($id_modules)) @@ -592,7 +593,7 @@ function agents_process_manage_config ($source_id_agent, $destiny_id_agents, $co $module = modules_get_agentmodule ($id_agent_module); if ($module === false) return false; - + // TODO TAGS agents_get_modules $modules = agents_get_modules ($id_destiny_agent, false, array ('nombre' => $module['nombre'], 'disabled' => false)); @@ -1349,6 +1350,7 @@ function agents_get_modules_data_count ($id_agent = 0) { foreach ($id_agent as $agent_id) { //Init value $count[$agent_id] = 0; + // TODO TAGS agents_get_modules $modules = array_keys (agents_get_modules ($agent_id)); foreach ($query as $sql) { //Add up each table's data @@ -1679,6 +1681,7 @@ function agents_get_status($id_agent = 0, $noACLs = false) { global $config; if (!$noACLs) { + // TODO TAGS agents_get_modules $modules = agents_get_modules ($id_agent, 'id_agente_modulo', array('disabled' => 0), true, false); } @@ -2126,7 +2129,7 @@ function agents_monitor_total ($id_agent, $filter = '', $disabled = false) { //Get alert fired for this agent function agents_get_alerts_fired ($id_agent, $filter="") { - + // TODO TAGS agents_get_modules $modules_agent = agents_get_modules($id_agent, "id_agente_modulo", $filter); if (empty($modules_agent)) { @@ -2374,8 +2377,7 @@ function agents_get_network_interfaces ($agents = false, $agents_filter = false) else $columns[] = 'descripcion'; - $filter = " id_agente = $agent_id AND disabled = 0 AND id_tipo_modulo IN (".implode(",", $accepted_module_types).") AND (nombre LIKE '%_ifOperStatus' OR nombre LIKE 'ifOperStatus_%')"; - + $filter = " tagente_modulo.id_agente = $agent_id AND tagente_modulo.disabled = 0 AND tagente_modulo.id_tipo_modulo IN (".implode(",", $accepted_module_types).") AND (tagente_modulo.nombre LIKE '%_ifOperStatus' OR tagente_modulo.nombre LIKE 'ifOperStatus_%')"; $modules = agents_get_modules($agent_id, $columns, $filter, true, false); if (!empty($modules)) { @@ -2441,9 +2443,11 @@ function agents_get_network_interfaces ($agents = false, $agents_filter = false) ); if($type_interface){ + // TODO TAGS agents_get_modules $interface_traffic_modules = agents_get_modules($agent_id, $columns, "nombre LIKE '". $interface_name . "_if%Octets'"); } else{ + // TODO TAGS agents_get_modules $interface_traffic_modules = agents_get_modules($agent_id, $columns, "nombre LIKE 'if%Octets_$interface_name'"); } diff --git a/pandora_console/include/functions_graph.php b/pandora_console/include/functions_graph.php index 53246a05f8..b268751fd4 100644 --- a/pandora_console/include/functions_graph.php +++ b/pandora_console/include/functions_graph.php @@ -2641,6 +2641,7 @@ function grafico_db_agentes_purge ($id_agent, $width = 380, $height = 300) { $query = ""; } else { + // TODO TAGS agents_get_modules $modules = agents_get_modules($id_agent); $module_ids = array_keys($modules); @@ -4836,6 +4837,7 @@ function graph_monitor_wheel ($width = 550, $height = 600, $filter = false) { $module_groups = modules_get_modulegroups(); $module_groups[0] = __('Not assigned'); + // TODO TAGS agents_get_modules $modules = agents_get_modules(array_keys($agents), '*'); $data_agents = array(); diff --git a/pandora_console/include/functions_modules.php b/pandora_console/include/functions_modules.php index f8e632dad4..c2e037b444 100755 --- a/pandora_console/include/functions_modules.php +++ b/pandora_console/include/functions_modules.php @@ -142,14 +142,14 @@ function modules_copy_agent_module_to_agent ($id_agent_module, $id_destiny_agent if ($forced_name !== false) $module['nombre'] = $forced_name; - + // TODO TAGS agents_get_modules $modules = agents_get_modules ($id_destiny_agent, false, array ('nombre' => $module['nombre'], 'disabled' => false)); // The module already exist in the target if (! empty ($modules)) return array_pop (array_keys ($modules)); - + // TODO TAGS agents_get_modules $modulesDisabled = agents_get_modules ($id_destiny_agent, false, array ('nombre' => $module['nombre'], 'disabled' => true)); diff --git a/pandora_console/include/functions_networkmap.php b/pandora_console/include/functions_networkmap.php index 4e4ad37cee..9ea4e9ef11 100644 --- a/pandora_console/include/functions_networkmap.php +++ b/pandora_console/include/functions_networkmap.php @@ -390,15 +390,11 @@ function networkmap_generate_dot ($pandora_name, $group = 0, $filter = array(); $filter['disabled'] = 0; - + // Get agent modules data - if ($strict_user) { - $modules = tags_get_agent_modules ($agent['id_agente'], false, $acltags, false, $filter, false); - } - else { - $modules = agents_get_modules($agent['id_agente'], '*', $filter, true, true); - } - + // TODO TAGS agents_get_modules + $modules = agents_get_modules($agent['id_agente'], '*', $filter, true, true); + if ($modules === false) $modules = array(); @@ -774,12 +770,8 @@ function networkmap_generate_dot_groups ($pandora_name, $group = 0, } // Get agent modules data - if ($strict_user) { - $filter['disabled'] = 0; - $modules = tags_get_agent_modules ($agent['id_agente'], false, $acltags, false, $filter, false); - } else { - $modules = agents_get_modules ($agent['id_agente'], false, array('disabled' => 0), true, false); - } + // TODO TAGS agents_get_modules + $modules = agents_get_modules ($agent['id_agente'], false, array('disabled' => 0), true, false); // Parse modules foreach ($modules as $key => $module) { diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index 3429840c9d..0d4ce3b09f 100755 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -1800,7 +1800,7 @@ function reporting_agent_module($report, $content) { $row = array(); $row['agent_status'][$agent] = agents_get_status($agent); $row['agent_name'] = agents_get_alias($agent); - + // TODO TAGS agents_get_modules $agent_modules = agents_get_modules($agent); $row['modules'] = array(); @@ -3079,7 +3079,7 @@ function reporting_alert_report_agent($report, $content) { $return["description"] = $content["description"]; $return["date"] = reporting_get_date_text($report, $content); $return['label'] = (isset($content['style']['label'])) ? $content['style']['label'] : ''; - + // TODO TAGS agents_get_modules $module_list = agents_get_modules($content['id_agent']); $data = array(); @@ -3669,7 +3669,7 @@ function reporting_agent_configuration($report, $content) { $agent_configuration['description'] = $agent_data['comentarios']; $agent_configuration['enabled'] = (int)!$agent_data['disabled']; $agent_configuration['group'] = $report["group"]; - + // TODO TAGS agents_get_modules $modules = agents_get_modules ($content['id_agent']); $agent_configuration['modules'] = array(); @@ -8313,7 +8313,7 @@ function reporting_get_agent_module_info ($id_agent, $filter = false) { } $filter = 'disabled = 0'; - + // TODO TAGS agents_get_modules $modules = agents_get_modules($id_agent, false, $filter, true, false); if ($modules === false) { diff --git a/pandora_console/include/functions_reporting_html.php b/pandora_console/include/functions_reporting_html.php index fd4d0a2c76..4fb6cfa4e4 100644 --- a/pandora_console/include/functions_reporting_html.php +++ b/pandora_console/include/functions_reporting_html.php @@ -3346,6 +3346,7 @@ function reporting_get_agent_monitors_table ($id_agent, $period = 0, $date = 0) function reporting_get_agent_modules_table ($id_agent, $period = 0, $date = 0) { $table->data = array (); $n_a_string = __('N/A').'(*)'; + // TODO TAGS agents_get_modules $modules = agents_get_modules ($id_agent, array ("nombre", "descripcion")); if ($modules === false) $modules = array(); diff --git a/pandora_console/operation/agentes/estado_generalagente.php b/pandora_console/operation/agentes/estado_generalagente.php index 73277400a5..f55889006f 100755 --- a/pandora_console/operation/agentes/estado_generalagente.php +++ b/pandora_console/operation/agentes/estado_generalagente.php @@ -273,7 +273,6 @@ $table_data->head_colspan[0] = 3; $data = array(); $data[0] = '' . __('Group') . ''; $data[1] = ''.groups_get_name ($agent["id_grupo"]).''; - // ACCESS RATE GRAPH $access_agent = db_get_value_sql("SELECT COUNT(id_agent) FROM tagent_access diff --git a/pandora_console/operation/agentes/estado_monitores.php b/pandora_console/operation/agentes/estado_monitores.php index 3fceedda4e..d3baf170e5 100755 --- a/pandora_console/operation/agentes/estado_monitores.php +++ b/pandora_console/operation/agentes/estado_monitores.php @@ -138,17 +138,14 @@ echo ""; ob_start(); - print_form_filter_monitors($id_agente, $status_filter_monitor, $status_text_monitor, $status_hierachy_mode); echo "
" . html_print_image('images/spinner.gif', true) . '
'; echo "
" . - "
"; - $html_toggle = ob_get_clean(); ui_toggle($html_toggle, __('List of modules'), diff --git a/pandora_console/operation/agentes/exportdata.php b/pandora_console/operation/agentes/exportdata.php index e30001fd3c..5319d700d0 100644 --- a/pandora_console/operation/agentes/exportdata.php +++ b/pandora_console/operation/agentes/exportdata.php @@ -283,6 +283,7 @@ if (empty($export_btn) || $show_form) { $table->data[2][0] .= ui_print_help_tip(__("No modules of type string. You can not calculate their average"),true); if ($agent > 0) { + // TODO TAGS agents_get_modules $modules = agents_get_modules ($agent); } else { diff --git a/pandora_console/operation/agentes/graphs.php b/pandora_console/operation/agentes/graphs.php index eaf9b4af3d..f13c92d157 100644 --- a/pandora_console/operation/agentes/graphs.php +++ b/pandora_console/operation/agentes/graphs.php @@ -47,7 +47,7 @@ $option_type = get_parameter('option_type', 0); // - others //---------------------------------------------------------------------- $list_modules = array(); - +// TODO TAGS agents_get_modules $modules_networkmap_no_proc = agents_get_modules( $id_agente, false, array( 'id_modulo' => 2, // networkmap type @@ -62,7 +62,7 @@ $modules_networkmap_no_proc = agents_get_modules( )); if (empty($modules_networkmap_no_proc)) $modules_networkmap_no_proc = array(); - +// TODO TAGS agents_get_modules $modules_others = agents_get_modules( $id_agente, false, array( 'id_tipo_modulo' => array( @@ -77,7 +77,7 @@ $modules_others = agents_get_modules( if (empty($modules_others)) $modules_others = array(); - +// TODO TAGS agents_get_modules $modules_boolean = agents_get_modules( $id_agente, false, array( 'id_tipo_modulo' => array( diff --git a/pandora_console/operation/agentes/pandora_networkmap.view.php b/pandora_console/operation/agentes/pandora_networkmap.view.php index 32225b9ad1..f15c49e28d 100644 --- a/pandora_console/operation/agentes/pandora_networkmap.view.php +++ b/pandora_console/operation/agentes/pandora_networkmap.view.php @@ -595,7 +595,7 @@ if (is_ajax ()) { if ($check_changes_num_modules) { $id = (int)get_parameter('id', 0); - + // TODO TAGS agents_get_modules $modules = agents_get_modules($id); $return = array(); diff --git a/pandora_console/operation/agentes/ver_agente.php b/pandora_console/operation/agentes/ver_agente.php index 805db88671..7f67e01c43 100644 --- a/pandora_console/operation/agentes/ver_agente.php +++ b/pandora_console/operation/agentes/ver_agente.php @@ -29,7 +29,6 @@ ui_require_javascript_file('openlayers.pandora'); enterprise_include_once ('operation/agentes/ver_agente.php'); check_login (); - if (is_ajax ()) { $get_agent_json = (bool) get_parameter ('get_agent_json'); $get_agent_modules_json = (bool) get_parameter ('get_agent_modules_json'); @@ -718,7 +717,7 @@ if (is_ajax ()) { $id_agent = array_keys( agents_get_group_agents( array_keys (users_get_groups ()), $search, "none")); - + // TODO TAGS agents_get_modules $agent_modules = agents_get_modules ($id_agent, $fields, $filter, $indexed, true, false, $tags); } // Restore db connection @@ -731,7 +730,7 @@ if (is_ajax ()) { $id_agent = array_keys( agents_get_group_agents( array_keys(users_get_groups ()), $search, "none")); - + // TODO TAGS agents_get_modules $agent_modules = agents_get_modules ($id_agent, $fields, $filter, $indexed, true, false, $tags); } From 14caf7bc0783a80e322160e0cad973d81233e2dc Mon Sep 17 00:00:00 2001 From: danielmaya Date: Tue, 2 Oct 2018 11:12:10 +0200 Subject: [PATCH 10/42] Added new search input for the module name --- .../operation/agentes/status_monitor.php | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/pandora_console/operation/agentes/status_monitor.php b/pandora_console/operation/agentes/status_monitor.php index 1b6cd954c5..2983b39138 100644 --- a/pandora_console/operation/agentes/status_monitor.php +++ b/pandora_console/operation/agentes/status_monitor.php @@ -158,8 +158,7 @@ else if ($modulegroup > -1) { // Module name selector if ($ag_modulename != '') { - $sql_conditions .= sprintf (' AND tagente_modulo.nombre = \'%s\'', - $ag_modulename); + $sql_conditions .= " AND tagente_modulo.nombre LIKE '%" .$ag_modulename. "%'"; } if ($module_option !== 0) { @@ -344,21 +343,15 @@ $table->data[0][5] = html_print_select($rows_select, 'modulegroup', $modulegroup $table->rowspan[0][6] = 2; $table->data[0][6] = html_print_submit_button (__('Show'), 'uptbutton', false, 'class="sub search" style="margin-top:0px;"',true); -$modules = array(); -// TODO change for input text + $table->data[1][0] = __('Module name'); -$table->data[1][1] = html_print_select (index_array ($modules, 'nombre', 'nombre'), 'ag_modulename', - $ag_modulename, '', __('All'), '', true, false, true, '', false, 'width: 150px;'); +$table->data[1][1] = html_print_input_text ('ag_modulename', $ag_modulename, '', 35, 50, true); $table->data[1][2] = __('Search'); $table->data[1][3] = html_print_input_text ('ag_freestring', $ag_freestring, '', 20, 30, true); -if (!is_metaconsole()) - $table->data[1][4] = __('Tags') . - ui_print_help_tip(__('Only it is show tags in use.'), true); -else - $table->data[1][4] = __('Tags') . - ui_print_help_tip(__('Only it is show tags in use.'), true); +$table->data[1][4] = __('Tags') . + ui_print_help_tip(__('Only it is show tags in use.'), true); $tags = array(); $tags = tags_get_user_tags(); From dc92a00b48dab0024c28520f509a170a7cc776ee Mon Sep 17 00:00:00 2001 From: fermin831 Date: Tue, 2 Oct 2018 13:19:17 +0200 Subject: [PATCH 11/42] [Tags performance] Fixed performance of main agent view --- pandora_console/include/ajax/module.php | 174 ++++++--------------- pandora_console/include/functions_tags.php | 37 +++++ 2 files changed, 81 insertions(+), 130 deletions(-) diff --git a/pandora_console/include/ajax/module.php b/pandora_console/include/ajax/module.php index 24fd4c9c78..a2c675fd94 100755 --- a/pandora_console/include/ajax/module.php +++ b/pandora_console/include/ajax/module.php @@ -74,7 +74,7 @@ if ($search_modules) { $id_agents = json_decode(io_safe_output(get_parameter('id_agents'))); $filter = '%' . get_parameter('q', '') . '%'; $other_filter = json_decode(io_safe_output(get_parameter('other_filter')), true); - + // TODO TAGS agents_get_modules $modules = agents_get_modules($id_agents, false, (array('nombre' => $filter) + $other_filter)); @@ -550,11 +550,15 @@ if ($list_modules) { // Fix: for tag functionality groups have to be all user_groups (propagate ACL funct!) $groups = users_get_groups($config["id_user"], $access); - if($cluster_list != 1){ - // TODO revision tag - $tags_sql = tags_get_acl_tags($config['id_user'], - array_keys($groups), $access, 'module_condition', 'AND', - 'tagente_modulo', false, array(), true); + $tags_join = ""; + $tags_sql = ""; + if($cluster_list != 1) { + $tags = tags_get_user_applied_agent_tags ($id_agent, $access); + if (is_array($tags)) { + $tags_sql = " AND ttag_module.id_tag IN (" . implode(',', $tags) . ")"; + $tags_join = "LEFT JOIN ttag_module + ON ttag_module.id_agente_modulo = tagente_modulo.id_agente_modulo"; + } } $status_filter_monitor = (int)get_parameter('status_filter_monitor', -1); @@ -572,10 +576,10 @@ if ($list_modules) { } if ($status_module_group != -1) { - $status_module_group_filter = 'id_module_group = ' . $status_module_group; + $status_module_group_filter = 'tagente_modulo.id_module_group = ' . $status_module_group; } else { - $status_module_group_filter = 'id_module_group >= 0'; + $status_module_group_filter = 'tagente_modulo.id_module_group >= 0'; } $status_text_monitor_sql = '%'; @@ -591,66 +595,22 @@ if ($list_modules) { } //Count monitors/modules - switch ($config["dbtype"]) { - case "mysql": - $sql = sprintf(" - SELECT COUNT(*) - FROM tagente_estado, - (SELECT * - FROM tagente_modulo - WHERE id_agente = %d AND nombre LIKE \"%s\" AND delete_pending = 0 - AND disabled = 0 AND %s) tagente_modulo - LEFT JOIN tmodule_group - ON tagente_modulo.id_module_group = tmodule_group.id_mg - WHERE tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo - AND %s %s - AND tagente_estado.estado != %d - AND tagente_modulo.%s - ORDER BY tagente_modulo.id_module_group , %s %s", - $id_agente, $status_text_monitor_sql,$status_module_group_filter,$status_filter_sql, $tags_sql, $monitor_filter, - $status_module_group_filter, $order['field'], $order['order']); - break; - case "postgresql": - $sql = sprintf(" - SELECT COUNT(DISTINCT tagente_modulo.id_module_group) - FROM tagente_estado, - (SELECT * - FROM tagente_modulo - WHERE id_agente = %d AND nombre LIKE '%s' - AND delete_pending = 0 - AND disabled = 0 AND %s) tagente_modulo - LEFT JOIN tmodule_group - ON tagente_modulo.id_module_group = tmodule_group.id_mg - WHERE tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo - AND %s %s - AND tagente_estado.estado != %d - AND tagente_modulo.%s - GROUP BY tagente_modulo.id_module_group, - tagente_modulo.nombre - ORDER BY tagente_modulo.id_module_group , %s %s", - $id_agente, $status_text_monitor_sql,$status_module_group_filter,$status_filter_sql, - $tags_sql, $monitor_filter,$status_module_group_filter,$order['field'], - $order['order']); - break; - case "oracle": - $sql = sprintf (" - SELECT COUNT(*)" . - " FROM tagente_estado, tagente_modulo - LEFT JOIN tmodule_group - ON tmodule_group.id_mg = tagente_modulo.id_module_group - WHERE tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo - AND tagente_modulo.id_agente = %d - AND tagente_modulo.nombre LIKE '%s' - AND %s %s - AND tagente_modulo.delete_pending = 0 - AND tagente_modulo.disabled = 0 - AND tagente_estado.estado != %d - AND tagente_modulo.%s - ORDER BY tagente_modulo.id_module_group , %s %s - ", $id_agente, $status_text_monitor_sql, $status_filter_sql, $tags_sql, $monitor_filter, - $status_module_group_filter,$order['field'], $order['order']); - break; - } + $order_sql = $order['field'] . " " . $order['order']; + $sql = "SELECT COUNT(*) + FROM tagente_modulo + $tags_join + INNER JOIN tagente_estado + ON tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo + LEFT JOIN tmodule_group + ON tagente_modulo.id_module_group = tmodule_group.id_mg + WHERE tagente_modulo.id_agente = $id_agente + AND nombre LIKE '$status_text_monitor_sql' + AND delete_pending = 0 + AND $status_filter_sql + $tags_sql + AND tagente_estado.estado != $monitor_filter + GROUP BY tagente_modulo.id_agente_modulo + "; $count_modules = db_get_all_rows_sql($sql); if (isset($count_modules[0])) @@ -660,68 +620,22 @@ if ($list_modules) { //Get monitors/modules // Get all module from agent - switch ($config["dbtype"]) { - case "mysql": - $sql = sprintf(" - SELECT * - FROM tagente_estado, - (SELECT * - FROM tagente_modulo - WHERE id_agente = %d AND nombre LIKE \"%s\" AND delete_pending = 0 - AND disabled = 0 AND %s) tagente_modulo - LEFT JOIN tmodule_group - ON tagente_modulo.id_module_group = tmodule_group.id_mg - WHERE tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo - AND %s %s - AND tagente_estado.estado != %d - AND tagente_modulo.%s - ORDER BY tmodule_group.name , %s %s", - $id_agente, $status_text_monitor_sql,$status_module_group_filter,$status_filter_sql, $tags_sql, $monitor_filter, - $status_module_group_filter, $order['field'], $order['order']); - - break; - case "postgresql": - $sql = sprintf(" - SELECT * - FROM tagente_estado, - (SELECT * - FROM tagente_modulo - WHERE id_agente = %d AND nombre LIKE '%s' AND delete_pending = 0 - AND disabled = 0 AND %s) tagente_modulo - LEFT JOIN tmodule_group - ON tagente_modulo.id_module_group = tmodule_group.id_mg - WHERE tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo - AND %s %s - AND tagente_estado.estado != %d - AND tagente_modulo.%s - ORDER BY tmodule_group.name , %s %s", - $id_agente, $status_text_monitor_sql,$status_module_group_filter,$status_filter_sql, $tags_sql, $monitor_filter, - $status_module_group_filter, $order['field'], $order['order']); - break; - // If Dbms is Oracle then field_list in sql statement has to be recoded. See oracle_list_all_field_table() - case "oracle": - $fields_tagente_estado = oracle_list_all_field_table('tagente_estado', 'string'); - $fields_tagente_modulo = oracle_list_all_field_table('tagente_modulo', 'string'); - $fields_tmodule_group = oracle_list_all_field_table('tmodule_group', 'string'); - - $sql = sprintf (" - SELECT " . $fields_tagente_estado . ', ' . $fields_tagente_modulo . ', ' . $fields_tmodule_group . - " FROM tagente_estado, tagente_modulo - LEFT JOIN tmodule_group - ON tmodule_group.id_mg = tagente_modulo.id_module_group - WHERE tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo - AND tagente_modulo.id_agente = %d - AND tagente_modulo.nombre LIKE '%s' - AND %s %s - AND tagente_modulo.delete_pending = 0 - AND tagente_modulo.disabled = 0 - AND tagente_estado.estado != %d - AND tagente_modulo.%s - ORDER BY tmodule_group.name , %s %s - ", $id_agente, $status_text_monitor_sql, $tags_sql, $status_filter_sql, $monitor_filter, - $status_module_group_filter, $order['field'], $order['order']); - break; - } + $sql = "SELECT tagente_estado.*, tagente_modulo.*, tmodule_group.* + FROM tagente_modulo + $tags_join + INNER JOIN tagente_estado + ON tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo + LEFT JOIN tmodule_group + ON tagente_modulo.id_module_group = tmodule_group.id_mg + WHERE tagente_modulo.id_agente = $id_agente + AND nombre LIKE '$status_text_monitor_sql' + AND delete_pending = 0 + AND $status_filter_sql + $tags_sql + AND tagente_estado.estado != $monitor_filter + GROUP BY tagente_modulo.id_agente_modulo + ORDER BY tmodule_group.name, $order_sql + "; if ($monitors_change_filter) { $limit = " LIMIT " . $config['block_size'] . " OFFSET 0"; diff --git a/pandora_console/include/functions_tags.php b/pandora_console/include/functions_tags.php index c785ee1297..75eef28bdd 100644 --- a/pandora_console/include/functions_tags.php +++ b/pandora_console/include/functions_tags.php @@ -2628,4 +2628,41 @@ function tags_get_module_policy_tags($id_tag, $id_module) { return $id_module_policy; } + +/** + * Get all tags configured to user associated to the agent. + * + * @param int $id_agent Agent to extract tags + * @param string $access Access to check + * + * @return mixed + * false if user has not permission on agent groups + * true if there is not any tag restriction + * array with all tags if there are tags configured + */ +function tags_get_user_applied_agent_tags ($id_agent, $access) { + global $config; + + $agent_groups = agents_get_all_groups_agent($id_agent); + $user_groups = users_get_groups(false, 'AR', false, true); + // Check global agent permissions + if (!check_acl_one_of_groups($config['id_user'], $agent_groups, $access)) { + return false; + } + + $acl_column = get_acl_column($access); + $tags = array(); + foreach ($agent_groups as $group) { + // If user has not permission to a single group, continue + if (!isset($user_groups[$group])) continue; + $group_tags = $user_groups[$group]["tags"][$acl_column]; + if (!empty($group_tags)) { + $tags = array_merge($tags, $group_tags); + } else { + // If an agent + return true; + } + } + return empty($tags) ? true : $tags; +} ?> From 2d057f9ae9c9b15e7444a3ef3379d72e40abd980 Mon Sep 17 00:00:00 2001 From: fermin831 Date: Tue, 2 Oct 2018 13:35:48 +0200 Subject: [PATCH 12/42] Fixed tags problems with secondary groups in tree view --- pandora_console/include/class/Tree.class.php | 33 ++++++++----------- .../include/class/TreeTag.class.php | 4 +++ 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/pandora_console/include/class/Tree.class.php b/pandora_console/include/class/Tree.class.php index 11f7fa56c5..86da888d04 100644 --- a/pandora_console/include/class/Tree.class.php +++ b/pandora_console/include/class/Tree.class.php @@ -205,26 +205,19 @@ class Tree { return "AND ta.$field_filter > 0" . $show_init_condition; } - // FIXME: Separate and condition from inner join protected function getTagJoin () { - // $parent is the agent id - $group_id = (int) db_get_value('id_grupo', 'tagente', 'id_agente', $this->id); - $tag_join = ''; - if (empty($group_id)) { - // ACL error, this will restrict the module search - $tag_join = 'INNER JOIN ttag_module tta - ON 1=0'; - } - else if (!empty($this->acltags) && isset($this->acltags[$group_id])) { - $tags_str = $this->acltags[$group_id]; + return 'INNER JOIN ttag_module ttm + ON tam.id_agente_modulo = ttm.id_agente_modulo'; + } - if (!empty($tags_str)) { - $tag_join = sprintf('INNER JOIN ttag_module ttm - ON tam.id_agente_modulo = ttm.id_agente_modulo - AND ttm.id_tag IN (%s)', $tags_str); - } - } - return $tag_join; + protected function getTagCondition () { + $tags = tags_get_user_applied_agent_tags($this->id, "AR"); + // All tags permision, returns no condition + if ($tags === true) return ""; + // No permision, do not show anything + if ($tags === false) return " AND 1=0"; + $tags_sql = implode(',', $tags); + return "AND ttm.id_tag IN ($tags_sql)";; } protected function getModuleStatusFilterFromTestado ($state = false, $without_ands = false) { @@ -900,7 +893,8 @@ class Tree { $module_search_filter = $this->getModuleSearchFilter(); $module_status_filter = $this->getModuleStatusFilterFromTestado(); $agent_filter = "AND ta.id_agente = " . $this->id; - $tag_join = $this->getTagJoin(); + $tag_condition = $this->getTagCondition(); + $tag_join = empty($tag_condition) ? '' : $this->getTagJoin(); $condition = $this->L2condition; $inner = $this->L2inner; @@ -929,6 +923,7 @@ class Tree { $agent_status_filter $module_status_filter $module_search_filter + $tag_condition ORDER BY tam.nombre ASC, tam.id_agente_modulo ASC"; return $sql; } diff --git a/pandora_console/include/class/TreeTag.class.php b/pandora_console/include/class/TreeTag.class.php index 516dceb3db..c02fb7ba4a 100644 --- a/pandora_console/include/class/TreeTag.class.php +++ b/pandora_console/include/class/TreeTag.class.php @@ -52,6 +52,10 @@ class TreeTag extends Tree { protected function getTagJoin () { return ''; } + + protected function getTagCondition () { + return ''; + } } ?> From 8d5953ce503dced53e698152818d60f17443bcad Mon Sep 17 00:00:00 2001 From: fermin831 Date: Tue, 2 Oct 2018 15:01:40 +0200 Subject: [PATCH 13/42] Removed unused code --- pandora_console/include/class/Tree.class.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/pandora_console/include/class/Tree.class.php b/pandora_console/include/class/Tree.class.php index 86da888d04..05c994df9e 100644 --- a/pandora_console/include/class/Tree.class.php +++ b/pandora_console/include/class/Tree.class.php @@ -28,7 +28,6 @@ class Tree { protected $userGroups; protected $userGroupsArray; - protected $acltags = false; protected $access = false; protected $L1fieldName = ''; @@ -69,8 +68,6 @@ class Tree { enterprise_include_once("include/functions_agents.php"); if (is_metaconsole()) enterprise_include_once("meta/include/functions_ui_meta.php"); - - $this->acltags = tags_get_user_groups_and_tags($config['id_user'], $this->access); } public function setFilter($filter) { From f7674745168efc5b2067eeaa5cd6e97d925cd19b Mon Sep 17 00:00:00 2001 From: fermin831 Date: Tue, 2 Oct 2018 15:30:19 +0200 Subject: [PATCH 14/42] [Tags performance] Fixed indexed agents_get_modules with no details --- pandora_console/include/functions_agents.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pandora_console/include/functions_agents.php b/pandora_console/include/functions_agents.php index 925ff4d6c6..ef146bd7b8 100644 --- a/pandora_console/include/functions_agents.php +++ b/pandora_console/include/functions_agents.php @@ -1169,8 +1169,10 @@ function agents_get_modules ($id_agent = null, $details = false, } } + $stored_details = $details; if (empty ($details)) { $details = "tagente_modulo.nombre"; + $stored_details = "nombre"; } else { $details = (array)$details; @@ -1215,12 +1217,12 @@ function agents_get_modules ($id_agent = null, $details = false, $modules = array (); foreach ($result as $module) { if ($get_not_init_modules || modules_get_agentmodule_is_init($module['id_agente_modulo'])) { - if (is_array ($details) || $details == '*') { + if (is_array ($stored_details) || $stored_details == '*') { //Just stack the information in array by ID $modules[$module['id_agente_modulo']] = $module; } else { - $modules[$module['id_agente_modulo']] = $module[$details]; + $modules[$module['id_agente_modulo']] = $module[$stored_details]; } } } From 942c5391f94e80404f1aea7f98c3a3a7257ab312 Mon Sep 17 00:00:00 2001 From: danielmaya Date: Wed, 3 Oct 2018 10:31:45 +0200 Subject: [PATCH 15/42] Fixed agents/modules view. it shows nothing if there are no agents and modules selected --- pandora_console/extensions/agents_modules.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pandora_console/extensions/agents_modules.php b/pandora_console/extensions/agents_modules.php index 8e33c4180e..61675912c3 100644 --- a/pandora_console/extensions/agents_modules.php +++ b/pandora_console/extensions/agents_modules.php @@ -70,7 +70,7 @@ function mainAgentsModules() { $hor_offset = (int)get_parameter('hor_offset', 0); $block = $config['block_size']; if(get_parameter('modulegroup') != null){ - $agents_id = (array)get_parameter('id_agents2', -1); + $agents_id = (array)get_parameter('id_agents2', null); } $selection_a_m = (int)get_parameter('selection_agent_module'); $modules_selected = (array)get_parameter('module', 0); @@ -135,8 +135,6 @@ function mainAgentsModules() { } } - $groups = users_get_groups (); - //groups $filter_groups_label = ''.__('Group').''; $filter_groups = html_print_select_groups(false, "AR", true, 'group_id', $group_id, '', '', '', true, false, true, '', false , 'width: auto;'); @@ -371,7 +369,10 @@ function mainAgentsModules() { $filter_groups['id_grupo'] = $group_id; } } - $agents = agents_get_agents ($filter_groups); + + if (!empty($filter_groups['id_agente'])) { + $agents = agents_get_agents ($filter_groups); + } $nagents = count($agents); if ($all_modules == false || $agents == false) { From 7ffeaaf50ba69ece206278064fe352992a1d1376 Mon Sep 17 00:00:00 2001 From: fermin831 Date: Wed, 3 Oct 2018 11:13:25 +0200 Subject: [PATCH 16/42] [Tags performance] fermin revision 1 --- pandora_console/extensions/insert_data.php | 1 - pandora_console/extras/pandora_diag.php | 2 +- .../godmode/agentes/module_manager.php | 108 +++++-------- .../godmode/alerts/alert_list.builder.php | 2 +- .../massive/massive_delete_modules.php | 148 +----------------- pandora_console/include/functions_agents.php | 5 +- pandora_console/include/functions_tags.php | 2 +- .../operation/agentes/ver_agente.php | 5 +- 8 files changed, 54 insertions(+), 219 deletions(-) diff --git a/pandora_console/extensions/insert_data.php b/pandora_console/extensions/insert_data.php index 698938aa63..5cfcc331d0 100644 --- a/pandora_console/extensions/insert_data.php +++ b/pandora_console/extensions/insert_data.php @@ -174,7 +174,6 @@ function mainInsertData() { $table->data[1][0] = __('Module'); $modules = array (); if ($agent_id){ - // TODO TAGS agents_get_modules $modules = agents_get_modules ($agent_id, false, array("delete_pending" => 0)); } $table->data[1][1] = html_print_select ($modules, 'id_agent_module', $id_agent_module, true, diff --git a/pandora_console/extras/pandora_diag.php b/pandora_console/extras/pandora_diag.php index 0b4be02ae1..4c851238ad 100644 --- a/pandora_console/extras/pandora_diag.php +++ b/pandora_console/extras/pandora_diag.php @@ -612,7 +612,7 @@ echo "data[0][0] = __('Module'); $modules = array (); -// TODO TAGS agents_get_modules + if ($id_agente) $modules = agents_get_modules ($id_agente, false, array("delete_pending" => 0)); diff --git a/pandora_console/godmode/massive/massive_delete_modules.php b/pandora_console/godmode/massive/massive_delete_modules.php index 26bcb7ec19..8e6684c6fc 100755 --- a/pandora_console/godmode/massive/massive_delete_modules.php +++ b/pandora_console/godmode/massive/massive_delete_modules.php @@ -76,147 +76,14 @@ function process_manage_delete ($module_name, $id_agents, $module_status = 'all' if (($module_name[0] == "0") and (is_array($module_name)) and (count($module_name) == 1)) $filter_for_module_deletion = false; else - $filter_for_module_deletion = sprintf('nombre IN ("%s")', implode('","', $module_name)); + $filter_for_module_deletion = sprintf('tagente_modulo.nombre IN ("%s")', implode('","', $module_name)); - if ($config['dbtype'] == "oracle") { - $all_agent_modules = false; - if (($module_name[0] == "0") and (is_array($module_name)) and (count($module_name) == 1)) { - $all_agent_modules = true; - } - $names_to_long = array(); - $i = 0; - foreach ($module_name as $name) { - if (strlen($name) > 30) { - $original_names[] = $module_name[$i]; - unset($module_name[$i]); - $names_to_long[] = substr($name, 0, 28) . "%"; - } - $i++; - } - $modules = "SELECT id_agente_modulo, nombre FROM tagente_modulo WHERE"; - $modules .= sprintf(" id_agente IN (%s)", implode(",", $id_agents)); - if (!empty($module_name) && (!$all_agent_modules)) { - $modules .= sprintf(" AND nombre IN ('%s')", implode("','", $module_name)); - } - $modules = db_get_all_rows_sql($modules); - $modules2 = ""; - if (!empty($names_to_long) && (!$all_agent_modules)) { - $modules2 = "SELECT id_agente_modulo, nombre FROM tagente_modulo WHERE"; - $modules2 .= sprintf(" id_agente IN (%s) AND (", implode(",", $id_agents)); - $j = 0; - foreach ($names_to_long as $name) { - if ($j == 0) { - $modules2 .= "nombre LIKE ('" . $name . "')"; - } - else { - $modules2 .= " OR nombre LIKE ('" . $name . "')"; - } - $j++; - } - $modules2 .= ")"; - $modules2 = db_get_all_rows_sql($modules2); - $modules = array_merge($modules, $modules2); - } - $all_names = array(); - foreach ($modules as $module) { - $all_modules[] = $module['id_agente_modulo']; - $all_names[] = $module['nombre']; - } - $modules = $all_modules; - $modules = array_unique($modules); - if (!empty($names_to_long) && (!$all_agent_modules)) { - $j = 0; - foreach ($all_names as $name) { - if (strlen($name) > 30) { - if (!in_array($name, $original_names)) { - unset($modules[$j]); - } - } - $j++; - } - } - } - else { - // TODO TAGS agents_get_modules - $modules = agents_get_modules ($id_agents, 'id_agente_modulo', - $filter_for_module_deletion, true); - } + $modules = agents_get_modules ($id_agents, 'id_agente_modulo', + $filter_for_module_deletion, true); } else { - if ($config['dbtype'] == "oracle") { - $all_agent_modules = false; - $names_to_long = array(); - if (($module_name[0] == "0") and (is_array($module_name)) and (count($module_name) == 1)) { - $all_agent_modules = true; - } - $i = 0; - foreach ($module_name as $name) { - if (strlen($name) > 30) { - $original_names[] = $module_name[$i]; - unset($module_name[$i]); - $names_to_long[] = substr($name, 0, 28) . "%"; - } - $i++; - } - $modules = "SELECT id_agente_modulo, nombre FROM tagente_modulo WHERE"; - $any_agent = false; - if ($id_agents == null) { - $any_agent = true; - } - if (!empty($id_agents)) { - $modules .= sprintf(" id_agente IN (%s)", implode(",", $id_agents)); - $agents_selected = true; - } - if (!empty($module_name) && (!$all_agent_modules)) { - if ($any_agent) { - $modules .= sprintf(" nombre IN ('%s')", implode("','", $module_name)); - } - else { - $modules .= sprintf(" AND nombre IN ('%s')", implode("','", $module_name)); - } - } - $modules = db_get_all_rows_sql($modules); - if (!empty($names_to_long) && (!$all_agent_modules)) { - $modules2 = "SELECT id_agente_modulo, nombre FROM tagente_modulo WHERE"; - $modules2 .= sprintf(" id_agente IN (%s) AND (", implode(",", $id_agents)); - $j = 0; - foreach ($names_to_long as $name) { - if ($j == 0) { - $modules2 .= "nombre LIKE ('" . $name . "')"; - } - else { - $modules2 .= " OR nombre LIKE ('" . $name . "')"; - } - $j++; - } - $modules2 .= ")"; - $modules2 = db_get_all_rows_sql($modules2); - $modules = array_merge($modules, $modules2); - } - $all_names = array(); - foreach ($modules as $module) { - $all_modules[] = $module['id_agente_modulo']; - $all_names[] = $module['nombre']; - } - $modules = $all_modules; - $modules = array_unique($modules); - if (!empty($names_to_long) && (!$all_agent_modules)) { - $j = 0; - foreach ($all_names as $name) { - if (strlen($name) > 30) { - if (!in_array($name, $original_names)) { - unset($modules[$j]); - } - } - $j++; - } - } - } - else { - // TODO TAGS agents_get_modules - $modules = agents_get_modules ($id_agents, 'id_agente_modulo', - sprintf('nombre IN ("%s")', implode('","',$module_name)), true); - } + $modules = agents_get_modules ($id_agents, 'id_agente_modulo', + 'tagente_modulo.nombre IN ("' . implode('","',$module_name) . '")', true); } if (($module_status == 'unknown') && ($module_name[0] == "0") && (is_array($module_name)) && (count($module_name) == 1)) { @@ -432,8 +299,6 @@ $table->data['form_modules_1'][3] = __('Select all modules of this type') . ' ' html_print_checkbox_extended("force_type", 'type', '', '', false, '', 'style="margin-right: 40px;"', true); - - $modules = array (); if ($module_type != '') { $filter = array ('id_tipo_modulo' => $module_type); @@ -441,9 +306,8 @@ if ($module_type != '') { else { $filter = false; } -// TODO TAGS agents_get_modules $names = agents_get_modules (array_keys ($agents), - 'DISTINCT(nombre)', $filter, false); + 'DISTINCT(tagente_modulo.nombre)', $filter, false); foreach ($names as $name) { $modules[$name['nombre']] = $name['nombre']; } diff --git a/pandora_console/include/functions_agents.php b/pandora_console/include/functions_agents.php index ef146bd7b8..4199f2c9a5 100644 --- a/pandora_console/include/functions_agents.php +++ b/pandora_console/include/functions_agents.php @@ -1177,7 +1177,10 @@ function agents_get_modules ($id_agent = null, $details = false, else { $details = (array)$details; $details = io_safe_input ($details); - $details = array_map(function ($a) { return 'tagente_modulo.' . $a;}, $details); + $details = array_map(function ($a) { + return preg_match('/tagente_modulo./i', $a) ? $a : 'tagente_modulo.' . $a; + },$details + ); } $sql_tags_join = ""; diff --git a/pandora_console/include/functions_tags.php b/pandora_console/include/functions_tags.php index 75eef28bdd..d7349c745f 100644 --- a/pandora_console/include/functions_tags.php +++ b/pandora_console/include/functions_tags.php @@ -2640,7 +2640,7 @@ function tags_get_module_policy_tags($id_tag, $id_module) { * true if there is not any tag restriction * array with all tags if there are tags configured */ -function tags_get_user_applied_agent_tags ($id_agent, $access) { +function tags_get_user_applied_agent_tags ($id_agent, $access = "AR") { global $config; $agent_groups = agents_get_all_groups_agent($id_agent); diff --git a/pandora_console/operation/agentes/ver_agente.php b/pandora_console/operation/agentes/ver_agente.php index 7f67e01c43..6c1d3b9718 100644 --- a/pandora_console/operation/agentes/ver_agente.php +++ b/pandora_console/operation/agentes/ver_agente.php @@ -673,7 +673,7 @@ if (is_ajax ()) { } if ($status_modulo != -1) { - $filter['id_agente_modulo IN'] = ' (SELECT id_agente_modulo FROM tagente_estado where ' . $sql_conditions; + $filter['tagente_modulo.id_agente_modulo IN'] = ' (SELECT id_agente_modulo FROM tagente_estado where ' . $sql_conditions; } @@ -685,7 +685,7 @@ if (is_ajax ()) { if ($get_id_and_name) $fields = array('id_agente_modulo', 'nombre'); if ($get_distinct_name) - $fields = array('DISTINCT(nombre)'); + $fields = array('DISTINCT(tagente_modulo.nombre)'); $indexed = (bool) get_parameter ('indexed', true); $agentName = (string) get_parameter ('agent_name', null); @@ -730,7 +730,6 @@ if (is_ajax ()) { $id_agent = array_keys( agents_get_group_agents( array_keys(users_get_groups ()), $search, "none")); - // TODO TAGS agents_get_modules $agent_modules = agents_get_modules ($id_agent, $fields, $filter, $indexed, true, false, $tags); } From 3d1e2e4c79677d19d38f86d04f220823b48007e3 Mon Sep 17 00:00:00 2001 From: fermin831 Date: Wed, 3 Oct 2018 11:14:11 +0200 Subject: [PATCH 17/42] Removed unused code --- pandora_console/godmode/agentes/configurar_agente.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/pandora_console/godmode/agentes/configurar_agente.php b/pandora_console/godmode/agentes/configurar_agente.php index b0999eb638..81c8dc714f 100644 --- a/pandora_console/godmode/agentes/configurar_agente.php +++ b/pandora_console/godmode/agentes/configurar_agente.php @@ -207,11 +207,6 @@ if ($create_agent) { $agent_creation_error = __('No agent alias specified'); $agent_created_ok = 0; } - /*elseif (agents_get_agent_id ($nombre_agente)) { - $agent_creation_error = - __('There is already an agent in the database with this name'); - $agent_created_ok = 0; - }*/ else { if($alias_as_name){ $sql = 'SELECT nombre FROM tagente WHERE nombre = "' . $alias . '"'; From b277c71c44fd59731b610f3688c6ff22b802da23 Mon Sep 17 00:00:00 2001 From: fermin831 Date: Wed, 3 Oct 2018 13:02:51 +0200 Subject: [PATCH 18/42] [Tags performance] Check massive operations --- .../godmode/massive/massive_add_tags.php | 250 -------------- .../godmode/massive/massive_copy_modules.php | 1 - .../godmode/massive/massive_delete_alerts.php | 1 - .../godmode/massive/massive_delete_tags.php | 305 ------------------ .../godmode/massive/massive_edit_modules.php | 4 +- 5 files changed, 2 insertions(+), 559 deletions(-) delete mode 100755 pandora_console/godmode/massive/massive_add_tags.php delete mode 100755 pandora_console/godmode/massive/massive_delete_tags.php diff --git a/pandora_console/godmode/massive/massive_add_tags.php b/pandora_console/godmode/massive/massive_add_tags.php deleted file mode 100755 index 729f2dcfcb..0000000000 --- a/pandora_console/godmode/massive/massive_add_tags.php +++ /dev/null @@ -1,250 +0,0 @@ - $name_module) { - $modules_id[] = $id_module; - } - } - } - - - $conttotal = 0; - $contsuccess = 0; - foreach ($modules_id as $id_module) { - $err_count = tags_insert_module_tag($id_module, $id_tags); - - if ($err_count == 0) { - $contsuccess ++; - } - - $conttotal ++; - } - - if ($contsuccess > 0) { - db_pandora_audit("Massive management", "Add tags", false, false, - ""); - } - else { - db_pandora_audit("Massive management", "Fail try to add tags", - false, false, ""); - } - - ui_print_result_message ($contsuccess > 0, - __('Successfully added') . "(" . $contsuccess . "/" . $conttotal . ")", - __('Could not be added')); - -} - -$id_agents = get_parameter ('id_agents'); -$id_tags = get_parameter ('id_tags'); -$modules = get_parameter ('module'); - -$add = (bool) get_parameter_post ('add'); - -if ($add) { - process_manage_add ($id_agents, $modules, $id_tags); -} - -$groups = users_get_groups (); -$own_info = get_user_info($config['id_user']); -if (!$own_info['is_admin'] && !check_acl ($config['id_user'], 0, "AW")) - $return_all_group = false; -else - $return_all_group = true; - -$table->id = 'add_table'; -$table->width = '98%'; -$table->data = array (); -$table->style = array (); -$table->style[0] = 'font-weight: bold; vertical-align:top'; -$table->style[2] = 'font-weight: bold; vertical-align:top'; -$table->size = array (); -$table->size[0] = '15%'; -$table->size[1] = '40%'; -$table->size[2] = '15%'; -$table->size[3] = '40%'; - -$table->data = array (); - -$table->data[0][0] = __('Group'); -$table->data[0][1] = html_print_select_groups(false, "AW", - $return_all_group, 'id_group', 0, '', 'Select', -1, true, false, - true, '', false, 'width:180px;'); - -$table->data[1][0] = __('Agents'); -$table->data[1][0] .= ''; - -$agents = agents_get_group_agents( - array_keys(users_get_groups ($config["id_user"], "AW", false))); -$table->data[1][1] = html_print_select ($agents, - 'id_agents[]', '', '', '', '', true, true, true, '', false, 'width:180px;'); - -$table->data[1][2] = __('Modules'); -$table->data[1][2] .= ''; -$table->data[1][3] = '' . - html_print_select (array(), 'module[]', '', false, '', '', true, true, false, '', false, 'width:180px;'); - - -$table->data[2][0] = __('Tags'); -$tags = tags_get_all_tags(); -$table->data[2][1] = html_print_select ($tags, - 'id_tags[]', '', '', '', '', true, true, true, '', false, 'width:180px;'); - - -echo '
'; -html_print_table ($table); - -echo '
'; -html_print_input_hidden ('add', 1); - -html_print_submit_button (__('Add'), 'go', false, 'class="sub add"'); -echo '
'; -echo '
'; - -// TODO: Change to iu_print_error system -echo ''; - -//Hack to translate text "none" in PHP to javascript -echo ''; - -ui_require_jquery_file ('form'); -ui_require_jquery_file ('pandora.controls'); -?> - - diff --git a/pandora_console/godmode/massive/massive_copy_modules.php b/pandora_console/godmode/massive/massive_copy_modules.php index 23739110d1..aae7d4e2df 100755 --- a/pandora_console/godmode/massive/massive_copy_modules.php +++ b/pandora_console/godmode/massive/massive_copy_modules.php @@ -120,7 +120,6 @@ $table->class = 'databox filters'; $table->data = array (); $modules = array (); -// TODO TAGS agents_get_modules if ($source_id_agent) $modules = agents_get_modules ($source_id_agent, 'nombre'); diff --git a/pandora_console/godmode/massive/massive_delete_alerts.php b/pandora_console/godmode/massive/massive_delete_alerts.php index f96f467672..eb0fd60dc3 100755 --- a/pandora_console/godmode/massive/massive_delete_alerts.php +++ b/pandora_console/godmode/massive/massive_delete_alerts.php @@ -120,7 +120,6 @@ function process_manage_delete ($id_alert_template, $id_agents, $module_names) { $modules_id = array(); foreach ($id_agents as $id_agent) { - // TODO TAGS agents_get_modules $current_modules_agent = agents_get_modules($id_agent, 'id_agente_modulo', array ('disabled' => 0)); if ($current_modules_agent != false) { // And their modules diff --git a/pandora_console/godmode/massive/massive_delete_tags.php b/pandora_console/godmode/massive/massive_delete_tags.php deleted file mode 100755 index 296a7ab8e1..0000000000 --- a/pandora_console/godmode/massive/massive_delete_tags.php +++ /dev/null @@ -1,305 +0,0 @@ - $id) { - $id_agents[$key] = (int)$id; - } - - $data = db_get_all_rows_sql(" - SELECT nombre - FROM tagente_modulo - WHERE id_agente IN (" . implode(',', $id_agents) . ") - AND id_agente_modulo IN ( - SELECT t1.id_agente_modulo - FROM ttag_module t1 - WHERE id_tag = " . $id_tag . " - AND id_policy_module = 0) - GROUP BY nombre;"); - - if (empty($data)) { - echo json_encode(array()); - } - else { - $modules = array(); - foreach ($data as $row) { - $modules[] = $row['nombre']; - } - - echo json_encode($modules); - } - } - else { - echo json_encode(array()); - } - - return; - } - - return; -} - -function process_manage_delete ($id_agents, $modules, $id_tag) { - - if (empty ($id_agents) || $id_agents[0] == 0) { - ui_print_error_message(__('No agents selected')); - return false; - } - - if (empty ($modules) || $modules[0] == "0") { - ui_print_error_message(__('No modules selected')); - return false; - } - - if (empty ($id_tag)) { - ui_print_error_message(__('No tag selected')); - return false; - } - - $modules_id = array(); - foreach ($modules as $module) { - $data = db_get_all_rows_sql(" - SELECT id_agente_modulo - FROM tagente_modulo - WHERE nombre = '" . $module . "' - AND id_agente IN (" . implode(",", $id_agents) . ") - "); - - if (empty($data)) { - $data = array(); - } - - foreach ($data as $row) { - $modules_id[$row['id_agente_modulo']] = $row['id_agente_modulo']; - } - } - - $conttotal = 0; - $contsuccess = 0; - foreach ($modules_id as $id_module) { - $success = tags_remove_tag($id_tag, $id_module); - - if ($success) { - $contsuccess ++; - } - - $conttotal ++; - } - - if ($contsuccess > 0) { - db_pandora_audit("Massive management", "Delete tags", false, false, - ""); - } - else { - db_pandora_audit("Massive management", "Fail try to delete tags", - false, false, ""); - } - - ui_print_result_message ($contsuccess > 0, - __('Successfully deleted') . "(" . $contsuccess . "/" . $conttotal . ")", - __('Could not be deleted')); - -} - -$id_agents = get_parameter ('id_agents'); -$id_tag = (int)get_parameter ('id_tag'); -$modules = get_parameter ('modules'); - -$delete = (bool) get_parameter_post ('delete'); - -if ($delete) { - process_manage_delete ($id_agents, $modules, $id_tag); -} - -$groups = users_get_groups (); -$own_info = get_user_info($config['id_user']); -if (!$own_info['is_admin'] && !check_acl ($config['id_user'], 0, "AW")) - $return_all_group = false; -else - $return_all_group = true; - -$table->id = 'add_table'; -$table->width = '98%'; -$table->data = array (); -$table->style = array (); -$table->style[0] = 'font-weight: bold; vertical-align:top'; -$table->style[2] = 'font-weight: bold; vertical-align:top'; -$table->size = array (); -$table->size[0] = '15%'; -$table->size[1] = '40%'; -$table->size[2] = '15%'; -$table->size[3] = '40%'; - -$table->data = array (); - -$table->data[0][0] = __('Tags'); -$tags = tags_get_all_tags(); -$table->data[0][1] = html_print_select ($tags, - 'id_tag', '', '', '', '', true, false, true, '', false, 'min-width:180px;'); - -$table->data[1][0] = __('Agents'); -$table->data[1][0] .= ''; -$table->data[1][1] = html_print_select (array(), - 'id_agents[]', '', '', '', '', true, true, true, '', false, 'min-width:180px;'); - -$table->data[2][0] = __('Modules'); -$table->data[2][0] .= ''; -$table->data[2][1] = '' . - html_print_select (array(), 'modules[]', '', false, '', '', true, true, false, '', false, 'min-width:180px;'); - - - - - -echo '
'; -html_print_table ($table); - -echo '
'; -html_print_input_hidden ('delete', 1); - -html_print_submit_button (__('Delete'), 'go', false, 'class="sub delete"'); -echo '
'; -echo '
'; - -// TODO: Change to iu_print_error system -echo ''; - -//Hack to translate text "none" in PHP to javascript -echo ''; - -ui_require_jquery_file ('form'); -ui_require_jquery_file ('pandora.controls'); -?> - - diff --git a/pandora_console/godmode/massive/massive_edit_modules.php b/pandora_console/godmode/massive/massive_edit_modules.php index 4d326a8e22..4ef69a581b 100755 --- a/pandora_console/godmode/massive/massive_edit_modules.php +++ b/pandora_console/godmode/massive/massive_edit_modules.php @@ -276,9 +276,9 @@ if ($module_type != '') { else { $filter = false; } -// TODO TAGS agents_get_modules + $names = agents_get_modules (array_keys ($agents), - 'DISTINCT(nombre)', $filter, false); + 'DISTINCT(tagente_modulo.nombre)', $filter, false); foreach ($names as $name) { $modules[$name['nombre']] = $name['nombre']; } From 7bd0615681cfacc7d870107812e21f0c7db1e03b Mon Sep 17 00:00:00 2001 From: fermin831 Date: Wed, 3 Oct 2018 13:53:59 +0200 Subject: [PATCH 19/42] [Tags performace] Check visual consoles --- .../godmode/reporting/visual_console_builder.elements.php | 1 - .../godmode/reporting/visual_console_builder.php | 1 - .../include/ajax/visual_console_builder.ajax.php | 7 +++---- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/pandora_console/godmode/reporting/visual_console_builder.elements.php b/pandora_console/godmode/reporting/visual_console_builder.elements.php index 3bd89eba92..c7e63358fa 100755 --- a/pandora_console/godmode/reporting/visual_console_builder.elements.php +++ b/pandora_console/godmode/reporting/visual_console_builder.elements.php @@ -416,7 +416,6 @@ foreach ($layoutDatas as $layoutData) { } if ($cell_content_enterprise === false) { if (!defined('METACONSOLE')) { - // TODO TAGS agents_get_modules $modules = agents_get_modules($layoutData['id_agent']); } else { diff --git a/pandora_console/godmode/reporting/visual_console_builder.php b/pandora_console/godmode/reporting/visual_console_builder.php index bfe7c3228a..b7d1030dad 100755 --- a/pandora_console/godmode/reporting/visual_console_builder.php +++ b/pandora_console/godmode/reporting/visual_console_builder.php @@ -560,7 +560,6 @@ switch ($activeTab) { foreach ($name_modules as $mod) { foreach ($id_agents as $ag) { - // TODO TAGS agents_get_modules $id_module = agents_get_modules($ag, array('id_agente_modulo'), array('nombre' => $mod)); diff --git a/pandora_console/include/ajax/visual_console_builder.ajax.php b/pandora_console/include/ajax/visual_console_builder.ajax.php index 1226e2a09c..4366e5d24a 100755 --- a/pandora_console/include/ajax/visual_console_builder.ajax.php +++ b/pandora_console/include/ajax/visual_console_builder.ajax.php @@ -960,7 +960,6 @@ switch ($action) { //Make the html of select box of modules about id_agent. if (($elementFields['id_agent'] != 0) &&($elementFields['id_layout_linked'] == 0)) { - // TODO TAGS agents_get_modules $modules = agents_get_modules( $elementFields['id_agent'], false, array('disabled' => 0, @@ -989,7 +988,7 @@ switch ($action) { if (isset($elementFields["linked_layout_status_as_service_warning"])) { $elementFields["linked_layout_status_as_service_warning"] = (float) $elementFields["linked_layout_status_as_service_warning"]; } - + hd($type, true); switch ($type) { case 'auto_sla_graph': $elementFields['event_max_time_row'] = $elementFields['period']; @@ -1023,7 +1022,6 @@ switch ($action) { $elementFields['id_agent_string'] = $elementFields['id_agent']; if (($elementFields['id_agent_string'] != 0) && ($elementFields['id_layout_linked'] == 0)) { - // TODO TAGS agents_get_modules $modules = agents_get_modules( $elementFields['id_agent'], false, array('disabled' => 0, @@ -1052,12 +1050,13 @@ switch ($action) { $elementFields['id_agent_string'] = $elementFields['id_agent']; if (($elementFields['id_agent_string'] != 0) && ($elementFields['id_layout_linked'] == 0)) { + hd("vis3", true); // TODO TAGS agents_get_modules $modules = agents_get_modules( $elementFields['id_agent'], false, array('disabled' => 0, 'id_agente' => $elementFields['id_agent'], - 'tagente_modulo.id_tipo_modulo IN' => "(17,23,3,10,33)")); + 'tagente_modulo.id_tipo_modulo IN' => "(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,18,17,23,3,10,33)")); $elementFields['modules_html'] = ''; foreach ($modules as $id => $name) { From 36fade6b37b0d408592c9faac6735e2d46903437 Mon Sep 17 00:00:00 2001 From: fermin831 Date: Wed, 3 Oct 2018 13:55:06 +0200 Subject: [PATCH 20/42] Removed unwanted traces --- pandora_console/include/ajax/visual_console_builder.ajax.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/pandora_console/include/ajax/visual_console_builder.ajax.php b/pandora_console/include/ajax/visual_console_builder.ajax.php index 4366e5d24a..90a13ff3a0 100755 --- a/pandora_console/include/ajax/visual_console_builder.ajax.php +++ b/pandora_console/include/ajax/visual_console_builder.ajax.php @@ -988,7 +988,6 @@ switch ($action) { if (isset($elementFields["linked_layout_status_as_service_warning"])) { $elementFields["linked_layout_status_as_service_warning"] = (float) $elementFields["linked_layout_status_as_service_warning"]; } - hd($type, true); switch ($type) { case 'auto_sla_graph': $elementFields['event_max_time_row'] = $elementFields['period']; @@ -1050,8 +1049,6 @@ switch ($action) { $elementFields['id_agent_string'] = $elementFields['id_agent']; if (($elementFields['id_agent_string'] != 0) && ($elementFields['id_layout_linked'] == 0)) { - hd("vis3", true); - // TODO TAGS agents_get_modules $modules = agents_get_modules( $elementFields['id_agent'], false, array('disabled' => 0, From 0ca13b8e9826062f519d283897d235b48594f35f Mon Sep 17 00:00:00 2001 From: fermin831 Date: Wed, 3 Oct 2018 15:04:45 +0200 Subject: [PATCH 21/42] Removed unused code --- pandora_console/godmode/admin_access_logs.php | 2 - pandora_console/include/functions_agents.php | 50 -- pandora_console/include/functions_graph.php | 645 ------------------ 3 files changed, 697 deletions(-) diff --git a/pandora_console/godmode/admin_access_logs.php b/pandora_console/godmode/admin_access_logs.php index 82f0af0f7e..4af38ec669 100644 --- a/pandora_console/godmode/admin_access_logs.php +++ b/pandora_console/godmode/admin_access_logs.php @@ -106,8 +106,6 @@ $form .= html_print_table($table, true); $form .= ''; ui_toggle($form, __("Filter"), "", false); -// ui_toggle(graphic_user_activity(400, 150), __("Chart")); - $filter = "1=1"; if (!empty($filter_type)) { diff --git a/pandora_console/include/functions_agents.php b/pandora_console/include/functions_agents.php index 4199f2c9a5..b9980bd972 100644 --- a/pandora_console/include/functions_agents.php +++ b/pandora_console/include/functions_agents.php @@ -1327,56 +1327,6 @@ function agents_get_alias_by_name ($name, $case = 'none') { } } -/** - * Get the number of pandora data packets in the database. - * - * In case an array is passed, it will have a value for every agent passed - * incl. a total otherwise it will just return the total - * - * @param mixed Agent id or array of agent id's, 0 for all - * - * @return mixed The number of data in the database - */ -function agents_get_modules_data_count ($id_agent = 0) { - $id_agent = safe_int ($id_agent, 1); - - if (empty ($id_agent)) { - $id_agent = array (); - } - else { - $id_agent = (array) $id_agent; - } - - $count = array (); - $count["total"] = 0; - - $query[0] = "SELECT COUNT(*) FROM tagente_datos"; - - foreach ($id_agent as $agent_id) { - //Init value - $count[$agent_id] = 0; - // TODO TAGS agents_get_modules - $modules = array_keys (agents_get_modules ($agent_id)); - foreach ($query as $sql) { - //Add up each table's data - //Avoid the count over empty array - if (!empty($modules)) - $count[$agent_id] += (int) db_get_sql ($sql . - " WHERE id_agente_modulo IN (".implode (",", $modules).")", 0, true); - } - //Add total agent count to total count - $count["total"] += $count[$agent_id]; - } - - if ($count["total"] == 0) { - foreach ($query as $sql) { - $count["total"] += (int) db_get_sql ($sql, 0, true); - } - } - - return $count; //Return the array -} - /** * Check if an agent has alerts fired. * diff --git a/pandora_console/include/functions_graph.php b/pandora_console/include/functions_graph.php index b268751fd4..f09bb04c45 100644 --- a/pandora_console/include/functions_graph.php +++ b/pandora_console/include/functions_graph.php @@ -20,210 +20,6 @@ include_once($config['homedir'] . "/include/functions_agents.php"); include_once($config['homedir'] . "/include/functions_modules.php"); include_once($config['homedir'] . "/include/functions_users.php"); -function get_graph_statistics ($chart_array) { - global $config; - - /// IMPORTANT! - /// - /// The calculus for AVG, MIN and MAX values are in this function - /// because it must be done based on graph array data not using reporting - /// function to get coherent data between stats and graph visualization - - $stats = array (); - - $count = 0; - - $size = sizeof($chart_array); - - //Initialize stats array - $stats = array ("avg" => 0, "min" => null, "max" => null, "last" => 0); - - foreach ($chart_array as $item) { - - //Sum all values later divide by the number of elements - $stats['avg'] = $stats['avg'] + $item; - - //Get minimum - if ($stats['min'] == null) { - $stats['min'] = $item; - } - else if ($item < $stats['min']) { - $stats['min'] = $item; - } - - //Get maximum - if ($stats['max'] == null) { - $stats['max'] = $item; - } - else if ($item > $stats['max']) { - $stats['max'] = $item; - } - - $count++; - - //Get last data - if ($count == $size) { - $stats['last'] = $item; - } - } - - //End the calculus for average - if ($count > 0) { - - $stats['avg'] = $stats['avg'] / $count; - } - - //Format stat data to display properly - $stats['last'] = remove_right_zeros(number_format($stats['last'], $config['graph_precision'])); - $stats['avg'] = remove_right_zeros(number_format($stats['avg'], $config['graph_precision'])); - $stats['min'] = remove_right_zeros(number_format($stats['min'], $config['graph_precision'])); - $stats['max'] = remove_right_zeros(number_format($stats['max'], $config['graph_precision'])); - - return $stats; -} - -function get_statwin_graph_statistics ($chart_array, $series_suffix = '') { - - /// IMPORTANT! - /// - /// The calculus for AVG, MIN and MAX values are in this function - /// because it must be done based on graph array data not using reporting - /// function to get coherent data between stats and graph visualization - - $stats = array (); - - $count = 0; - - $size = sizeof($chart_array); - - //Initialize stats array - $stats['sum'] = array ("avg" => 0, "min" => null, "max" => null, "last" => 0); - $stats['min'] = array ("avg" => 0, "min" => null, "max" => null, "last" => 0); - $stats['max'] = array ("avg" => 0, "min" => null, "max" => null, "last" => 0); - - foreach ($chart_array as $item) { - if ($series_suffix != '') { - if (isset($item['sum' . $series_suffix])) - $item['sum'] = $item['sum' . $series_suffix]; - if (isset($item['min' . $series_suffix])) - $item['min'] = $item['min' . $series_suffix]; - if (isset($item['max' . $series_suffix])) - $item['max'] = $item['max' . $series_suffix]; - } - - //Get stats for normal graph - if (isset($item['sum']) && $item['sum']) { - - //Sum all values later divide by the number of elements - $stats['sum']['avg'] = $stats['sum']['avg'] + $item['sum']; - - //Get minimum - if ($stats['sum']['min'] == null) { - $stats['sum']['min'] = $item['sum']; - } - else if ($item['sum'] < $stats['sum']['min']) { - $stats['sum']['min'] = $item['sum']; - } - - //Get maximum - if ($stats['sum']['max'] == null) { - $stats['sum']['max'] = $item['sum']; - } - else if ($item['sum'] > $stats['sum']['max']) { - $stats['sum']['max'] = $item['sum']; - } - } - - //Get stats for min graph - if (isset($item['min']) && $item['min']) { - //Sum all values later divide by the number of elements - $stats['min']['avg'] = $stats['min']['avg'] + $item['min']; - - //Get minimum - if ($stats['min']['min'] == null) { - $stats['min']['min'] = $item['min']; - } - else if ($item['min'] < $stats['min']['min']) { - $stats['min']['min'] = $item['min']; - } - - //Get maximum - if ($stats['min']['max'] == null) { - $stats['min']['max'] = $item['min']; - } - else if ($item['min'] > $stats['min']['max']) { - $stats['min']['max'] = $item['min']; - } - } - - //Get stats for max graph - if (isset($item['max']) && $item['max']) { - //Sum all values later divide by the number of elements - $stats['max']['avg'] = $stats['max']['avg'] + $item['max']; - - //Get minimum - if ($stats['max']['min'] == null) { - $stats['max']['min'] = $item['max']; - } - else if ($item['max'] < $stats['max']['min']) { - $stats['max']['min'] = $item['max']; - } - - //Get maximum - if ($stats['max']['max'] == null) { - $stats['max']['max'] = $item['max']; - } - else if ($item['max'] > $stats['max']['max']) { - $stats['max']['max'] = $item['max']; - } - } - - //Count elements - $count++; - - //Get last data - if ($count == $size) { - if (isset($item['sum']) && $item['sum']) { - $stats['sum']['last'] = $item['sum']; - } - - if (isset($item['min']) && $item['min']) { - $stats['min']['last'] = $item['min']; - } - - if (isset($item['max']) && $item['max']) { - $stats['max']['last'] = $item['max']; - } - } - } - - //End the calculus for average - if ($count > 0) { - - $stats['sum']['avg'] = $stats['sum']['avg'] / $count; - $stats['min']['avg'] = $stats['min']['avg'] / $count; - $stats['max']['avg'] = $stats['max']['avg'] / $count; - } - - //Format stat data to display properly - $stats['sum']['last'] = round($stats['sum']['last'], 2); - $stats['sum']['avg'] = round($stats['sum']['avg'], 2); - $stats['sum']['min'] = round($stats['sum']['min'], 2); - $stats['sum']['max'] = round($stats['sum']['max'], 2); - - $stats['min']['last'] = round($stats['min']['last'], 2); - $stats['min']['avg'] = round($stats['min']['avg'], 2); - $stats['min']['min'] = round($stats['min']['min'], 2); - $stats['min']['max'] = round($stats['min']['max'], 2); - - $stats['max']['last'] = round($stats['max']['last'], 2); - $stats['max']['avg'] = round($stats['max']['avg'], 2); - $stats['max']['min'] = round($stats['max']['min'], 2); - $stats['max']['max'] = round($stats['max']['max'], 2); - - return $stats; -} - function grafico_modulo_sparse_data_chart ( $agent_module_id, $date_array, @@ -2624,383 +2420,6 @@ function graph_sla_slicebar ($id, $period, $sla_min, $sla_max, $date, $daysWeek $config['fontpath'], $round_corner, $home_url, $ttl); } -/** - * Print a pie graph with purge data of agent - * - * @param integer id_agent ID of agent to show - * @param integer width pie graph width - * @param integer height pie graph height - */ -function grafico_db_agentes_purge ($id_agent, $width = 380, $height = 300) { - global $config; - global $graphic_type; - - $filter = array(); - - if ($id_agent < 1) { - $query = ""; - } - else { - // TODO TAGS agents_get_modules - $modules = agents_get_modules($id_agent); - $module_ids = array_keys($modules); - - if (!empty($module_ids)) - $filter['id_agente_modulo'] = $module_ids; - } - - // All data (now) - $time_now = time(); - - // 1 day ago - $time_1day = $time_now - SECONDS_1DAY; - - // 1 week ago - $time_1week = $time_now - SECONDS_1WEEK; - - // 1 month ago - $time_1month = $time_now - SECONDS_1MONTH; - - // Three months ago - $time_3months = $time_now - SECONDS_3MONTHS; - - $query_error = false; - - // Data from 1 day ago - $num_1day = 0; - $num_1day += (int) db_get_sql('SELECT COUNT(*) - FROM tagente_datos - WHERE utimestamp > ' . $time_1day); - $num_1day += (int) db_get_sql('SELECT COUNT(*) - FROM tagente_datos_string - WHERE utimestamp > ' . $time_1day); - $num_1day += (int) db_get_sql('SELECT COUNT(*) - FROM tagente_datos_log4x - WHERE utimestamp > ' . $time_1day); - if ($num_1day >= 0) { - // Data from 1 week ago - $num_1week = 0; - $num_1week += (int) db_get_sql('SELECT COUNT(*) - FROM tagente_datos - WHERE utimestamp > ' . $time_1week . ' - AND utimestamp < ' . $time_1day); - $num_1week += (int) db_get_sql('SELECT COUNT(*) - FROM tagente_datos_string - WHERE utimestamp > ' . $time_1week . ' - AND utimestamp < ' . $time_1day); - $num_1week += (int) db_get_sql('SELECT COUNT(*) - FROM tagente_datos_log4x - WHERE utimestamp > ' . $time_1week . ' - AND utimestamp < ' . $time_1day); - if ($num_1week >= 0) { - if ($num_1week > 0) { - $num_1week = 0; - $num_1week += (int) db_get_sql('SELECT COUNT(*) - FROM tagente_datos - WHERE utimestamp > ' . $time_1week); - $num_1week += (int) db_get_sql('SELECT COUNT(*) - FROM tagente_datos_string - WHERE utimestamp > ' . $time_1week); - $num_1week += (int) db_get_sql('SELECT COUNT(*) - FROM tagente_datos_log4x - WHERE utimestamp > ' . $time_1week); - } - // Data from 1 month ago - $num_1month = 0; - $num_1month += (int) db_get_sql('SELECT COUNT(*) - FROM tagente_datos - WHERE utimestamp > ' . $time_1month . ' - AND utimestamp < ' . $time_1week); - $num_1month += (int) db_get_sql('SELECT COUNT(*) - FROM tagente_datos_string - WHERE utimestamp > ' . $time_1month . ' - AND utimestamp < ' . $time_1week); - $num_1month += (int) db_get_sql('SELECT COUNT(*) - FROM tagente_datos_log4x - WHERE utimestamp > ' . $time_1month . ' - AND utimestamp < ' . $time_1week); - if ($num_1month >= 0) { - if ($num_1month > 0) { - $num_1month = 0; - $num_1month += (int) db_get_sql('SELECT COUNT(*) - FROM tagente_datos - WHERE utimestamp > ' . $time_1month); - $num_1month += (int) db_get_sql('SELECT COUNT(*) - FROM tagente_datos_string - WHERE utimestamp > ' . $time_1month); - $num_1month += (int) db_get_sql('SELECT COUNT(*) - FROM tagente_datos_log4x - WHERE utimestamp > ' . $time_1month); - } - // Data from 3 months ago - $num_3months = 0; - $num_3months += (int) db_get_sql('SELECT COUNT(*) - FROM tagente_datos - WHERE utimestamp > ' . $time_3months . ' - AND utimestamp < ' . $time_1month); - $num_3months += (int) db_get_sql('SELECT COUNT(*) - FROM tagente_datos - WHERE utimestamp > ' . $time_3months . ' - AND utimestamp < ' . $time_1month); - $num_3months += (int) db_get_sql('SELECT COUNT(*) - FROM tagente_datos - WHERE utimestamp > ' . $time_3months . ' - AND utimestamp < ' . $time_1month); - if ($num_3months >= 0) { - if ($num_3months > 0) { - $num_3months = 0; - $num_3months += (int) db_get_sql('SELECT COUNT(*) - FROM tagente_datos - WHERE utimestamp > ' . $time_3months); - $num_3months += (int) db_get_sql('SELECT COUNT(*) - FROM tagente_datos - WHERE utimestamp > ' . $time_3months); - $num_3months += (int) db_get_sql('SELECT COUNT(*) - FROM tagente_datos - WHERE utimestamp > ' . $time_3months); - } - // All data - $num_all = 0; - $num_all += (int) db_get_sql('SELECT COUNT(*) - FROM tagente_datos - WHERE utimestamp < ' . $time_3months); - $num_all += (int) db_get_sql('SELECT COUNT(*) - FROM tagente_datos - WHERE utimestamp < ' . $time_3months); - $num_all += (int) db_get_sql('SELECT COUNT(*) - FROM tagente_datos - WHERE utimestamp < ' . $time_3months); - if ($num_all >= 0) { - $num_older = $num_all - $num_3months; - if ($config['history_db_enabled'] == 1) { - // All data in common and history database - $num_all_w_history = 0; - $num_all_w_history += (int) db_get_sql('SELECT COUNT(*) - FROM tagente_datos - WHERE utimestamp < ' . $time_3months); - $num_all_w_history += (int) db_get_sql('SELECT COUNT(*) - FROM tagente_datos - WHERE utimestamp < ' . $time_3months); - $num_all_w_history += (int) db_get_sql('SELECT COUNT(*) - FROM tagente_datos - WHERE utimestamp < ' . $time_3months); - if ($num_all_w_history >= 0) { - $num_history = $num_all_w_history - $num_all; - } - } - } - } - } - } - } - else if (($num_1day == 0) && ($num_1week == 0) && ($num_1month == 0) && ($num_3months == 0) && ($num_all == 0)) { - //If no data, returns empty - $query_error = true; - } - - // Error - if ($query_error || $num_older < 0 || ($config['history_db_enabled'] == 1 && $num_history < 0) - || (empty($num_1day) && empty($num_1week) && empty($num_1month) - && empty($num_3months) && empty($num_all) - && ($config['history_db_enabled'] == 1 && empty($num_all_w_history)))) { - return html_print_image('images/image_problem_area_small.png', true); - } - - // Data indexes - $str_1day = __("Today"); - $str_1week = "1 ".__("Week"); - $str_1month = "1 ".__("Month"); - $str_3months = "3 ".__("Months"); - $str_older = "> 3 ".__("Months"); - - // Filling the data array - $data = array(); - if (!empty($num_1day)) - $data[$str_1day] = $num_1day; - if (!empty($num_1week)) - $data[$str_1week] = $num_1week; - if (!empty($num_1month)) - $data[$str_1month] = $num_1month; - if (!empty($num_3months)) - $data[$str_3months] = $num_3months; - if (!empty($num_older)) - $data[$str_older] = $num_older; - if ($config['history_db_enabled'] == 1 && !empty($num_history)) { - // In this pie chart only 5 elements are shown, so we need to remove - // an element. With a history db enabled the >3 months element are dispensable - if (count($data) >= 5 && isset($data[$str_3months])) - unset($data[$str_3months]); - - $time_historic_db = time() - ((int)$config['history_db_days'] * SECONDS_1DAY); - $date_human = human_time_comparation($time_historic_db); - $str_history = "> $date_human (".__("History db").")"; - $data[$str_history] = $num_history; - } - - $water_mark = array( - 'file' => $config['homedir'] . "/images/logo_vertical_water.png", - 'url' => ui_get_full_url("images/logo_vertical_water.png", false, false, false) - ); - - return pie3d_graph($config['flash_charts'], $data, $width, $height, - __('Other'), '', $water_mark, $config['fontpath'], $config['font_size']); -} - -/** - * Print a horizontal bar graph with packets data of agents - * - * @param integer width pie graph width - * @param integer height pie graph height - */ -function grafico_db_agentes_paquetes($width = 380, $height = 300) { - global $config; - global $graphic_type; - - - $data = array (); - $legend = array (); - - $agents = agents_get_group_agents (array_keys (users_get_groups (false, 'RR')), false, "none"); - $count = agents_get_modules_data_count (array_keys ($agents)); - unset ($count["total"]); - arsort ($count, SORT_NUMERIC); - $count = array_slice ($count, 0, 8, true); - - foreach ($count as $agent_id => $value) { - $data[$agents[$agent_id]]['g'] = $value; - } - - if($config["fixed_graph"] == false){ - $water_mark = array('file' => - $config['homedir'] . "/images/logo_vertical_water.png", - 'url' => ui_get_full_url("images/logo_vertical_water.png", false, false, false)); - } - - return hbar_graph($config['flash_charts'], $data, $width, $height, array(), - $legend, "", "", true, "", $water_mark, - $config['fontpath'], $config['font_size'], false, 1, $config['homeurl'], - 'white', - 'black'); -} - -/** - * Print a horizontal bar graph with modules data of agents - * - * @param integer height graph height - * @param integer width graph width - */ -function graph_db_agentes_modulos($width, $height) { - global $config; - global $graphic_type; - - - $data = array (); - - switch ($config['dbtype']) { - case "mysql": - case "postgresql": - $modules = db_get_all_rows_sql (' - SELECT COUNT(id_agente_modulo), id_agente - FROM tagente_modulo - WHERE delete_pending = 0 - GROUP BY id_agente - ORDER BY 1 DESC LIMIT 10'); - break; - case "oracle": - $modules = db_get_all_rows_sql (' - SELECT COUNT(id_agente_modulo), id_agente - FROM tagente_modulo - WHERE rownum <= 10 - AND delete_pending = 0 - GROUP BY id_agente - ORDER BY 1 DESC'); - break; - } - if ($modules === false) - $modules = array (); - - $data = array(); - foreach ($modules as $module) { - $agent_name = agents_get_name ($module['id_agente'], "none"); - - if (empty($agent_name)) { - continue; - } - switch ($config['dbtype']) { - case "mysql": - case "postgresql": - $data[$agent_name]['g'] = $module['COUNT(id_agente_modulo)']; - break; - case "oracle": - $data[$agent_name]['g'] = $module['count(id_agente_modulo)']; - break; - } - } - - if($config["fixed_graph"] == false){ - $water_mark = array('file' => - $config['homedir'] . "/images/logo_vertical_water.png", - 'url' => ui_get_full_url("images/logo_vertical_water.png", false, false, false)); - } - - return hbar_graph($config['flash_charts'], - $data, $width, $height, array(), - array(), "", "", true, "", - $water_mark, - $config['fontpath'], $config['font_size'], false, 1, $config['homeurl'], - 'white', - 'black'); -} - -/** - * Print a pie graph with users activity in a period of time - * - * @param integer width pie graph width - * @param integer height pie graph height - * @param integer period time period - */ -function graphic_user_activity ($width = 350, $height = 230) { - global $config; - global $graphic_type; - - $data = array (); - $max_items = 5; - switch ($config['dbtype']) { - case "mysql": - case "postgresql": - $sql = sprintf ('SELECT COUNT(id_usuario) n_incidents, id_usuario - FROM tsesion - GROUP BY id_usuario - ORDER BY 1 DESC LIMIT %d', $max_items); - break; - case "oracle": - $sql = sprintf ('SELECT COUNT(id_usuario) n_incidents, id_usuario - FROM tsesion - WHERE rownum <= %d - GROUP BY id_usuario - ORDER BY 1 DESC', $max_items); - break; - } - $logins = db_get_all_rows_sql ($sql); - - if ($logins == false) { - $logins = array(); - } - foreach ($logins as $login) { - $data[$login['id_usuario']] = $login['n_incidents']; - } - - if($config["fixed_graph"] == false){ - $water_mark = array('file' => - $config['homedir'] . "/images/logo_vertical_water.png", - 'url' => ui_get_full_url("images/logo_vertical_water.png", false, false, false)); - } - - return pie3d_graph($config['flash_charts'], $data, $width, $height, - __('Other'), '', $water_mark, - $config['fontpath'], $config['font_size']); -} - /** * Print a pie graph with priodity incident */ @@ -3428,70 +2847,6 @@ function grafico_eventos_grupo ($width = 300, $height = 200, $url = "", $meta = $config['fontpath'], $config['font_size'], 1, 'bottom'); } -function grafico_eventos_agente ($width = 300, $height = 200, $result = false, $meta = false, $history = false) { - global $config; - global $graphic_type; - - //It was urlencoded, so we urldecode it - //$url = html_entity_decode (rawurldecode ($url), ENT_QUOTES); - $data = array (); - $loop = 0; - - if ($result === false) { - $result = array(); - } - - $system_events = 0; - $other_events = 0; - $total = array(); - $i = 0; - - foreach ($result as $row) { - if ($meta) { - $count[] = $row["agent_name"]; - } - else { - if ($row["id_agente"] == 0) { - $count[] = __('SYSTEM'); - } - else - $count[] = agents_get_alias($row["id_agente"]) ; - } - - } - - $total = array_count_values($count); - - foreach ($total as $key => $total) { - if ($meta) { - $name = $key." (".$total.")"; - } - else { - $name = $key." (".$total.")"; - } - $data[$name] = $total; - } - - /* - if ($other_events > 0) { - $name = __('Other')." (".$other_events.")"; - $data[$name] = $other_events; - } - */ - - // Sort the data - arsort($data); - if($config["fixed_graph"] == false){ - $water_mark = array('file' => - $config['homedir'] . "/images/logo_vertical_water.png", - 'url' => ui_get_full_url("images/logo_vertical_water.png", false, false, false)); - } - - return pie3d_graph($config['flash_charts'], $data, $width, $height, - __('Others'), '', $water_mark, - $config['fontpath'], $config['font_size'], 1, 'bottom'); -} - /** * Print a pie graph with events data in 320x200 size * From a33cae9e8fb7d0839ceb87f866ac899fcdf9c723 Mon Sep 17 00:00:00 2001 From: fermin831 Date: Wed, 3 Oct 2018 16:33:56 +0200 Subject: [PATCH 22/42] [Tags performance] Check functions_agents agents_get_modules --- pandora_console/include/functions_agents.php | 26 ++------------------ 1 file changed, 2 insertions(+), 24 deletions(-) diff --git a/pandora_console/include/functions_agents.php b/pandora_console/include/functions_agents.php index b9980bd972..3335bb769e 100644 --- a/pandora_console/include/functions_agents.php +++ b/pandora_console/include/functions_agents.php @@ -205,7 +205,6 @@ function agents_get_alerts_simple ($id_agent = false, $filter = '', $options = f } else { $id_agent = (array) $id_agent; - // TODO TAGS agents_get_modules $id_modules = array_keys (agents_get_modules ($id_agent, false, array('delete_pending' => 0))); if (empty ($id_modules)) @@ -593,7 +592,6 @@ function agents_process_manage_config ($source_id_agent, $destiny_id_agents, $co $module = modules_get_agentmodule ($id_agent_module); if ($module === false) return false; - // TODO TAGS agents_get_modules $modules = agents_get_modules ($id_destiny_agent, false, array ('nombre' => $module['nombre'], 'disabled' => false)); @@ -1636,7 +1634,6 @@ function agents_get_status($id_agent = 0, $noACLs = false) { global $config; if (!$noACLs) { - // TODO TAGS agents_get_modules $modules = agents_get_modules ($id_agent, 'id_agente_modulo', array('disabled' => 0), true, false); } @@ -2081,23 +2078,6 @@ function agents_monitor_total ($id_agent, $filter = '', $disabled = false) { return db_get_sql ($sql); } -//Get alert fired for this agent - -function agents_get_alerts_fired ($id_agent, $filter="") { - // TODO TAGS agents_get_modules - $modules_agent = agents_get_modules($id_agent, "id_agente_modulo", $filter); - - if (empty($modules_agent)) { - return 0; - } - - $mod_clause = "(".implode(",", $modules_agent).")"; - - return db_get_sql ("SELECT COUNT(times_fired) - FROM talert_template_modules - WHERE times_fired != 0 AND id_agent_module IN ".$mod_clause); -} - //Returns the alert image to display tree view function agents_tree_view_alert_img ($alert_fired) { @@ -2398,12 +2378,10 @@ function agents_get_network_interfaces ($agents = false, $agents_filter = false) ); if($type_interface){ - // TODO TAGS agents_get_modules - $interface_traffic_modules = agents_get_modules($agent_id, $columns, "nombre LIKE '". $interface_name . "_if%Octets'"); + $interface_traffic_modules = agents_get_modules($agent_id, $columns, "tagente_modulo.nombre LIKE '". $interface_name . "_if%Octets'"); } else{ - // TODO TAGS agents_get_modules - $interface_traffic_modules = agents_get_modules($agent_id, $columns, "nombre LIKE 'if%Octets_$interface_name'"); + $interface_traffic_modules = agents_get_modules($agent_id, $columns, "tagente_modulo.nombre LIKE 'if%Octets_$interface_name'"); } if (!empty($interface_traffic_modules) && count($interface_traffic_modules) >= 2) { From f3eae5e111e7e92566f99eeb518667d84ac942a6 Mon Sep 17 00:00:00 2001 From: fermin831 Date: Wed, 3 Oct 2018 17:00:57 +0200 Subject: [PATCH 23/42] [Tags performance] Some agents_get_modules checks --- pandora_console/include/functions_modules.php | 2 -- pandora_console/include/functions_reporting.php | 2 -- pandora_console/include/functions_reporting_html.php | 1 - 3 files changed, 5 deletions(-) diff --git a/pandora_console/include/functions_modules.php b/pandora_console/include/functions_modules.php index c2e037b444..bffd6d93d0 100755 --- a/pandora_console/include/functions_modules.php +++ b/pandora_console/include/functions_modules.php @@ -142,14 +142,12 @@ function modules_copy_agent_module_to_agent ($id_agent_module, $id_destiny_agent if ($forced_name !== false) $module['nombre'] = $forced_name; - // TODO TAGS agents_get_modules $modules = agents_get_modules ($id_destiny_agent, false, array ('nombre' => $module['nombre'], 'disabled' => false)); // The module already exist in the target if (! empty ($modules)) return array_pop (array_keys ($modules)); - // TODO TAGS agents_get_modules $modulesDisabled = agents_get_modules ($id_destiny_agent, false, array ('nombre' => $module['nombre'], 'disabled' => true)); diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index 0d4ce3b09f..279c972324 100755 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -1800,7 +1800,6 @@ function reporting_agent_module($report, $content) { $row = array(); $row['agent_status'][$agent] = agents_get_status($agent); $row['agent_name'] = agents_get_alias($agent); - // TODO TAGS agents_get_modules $agent_modules = agents_get_modules($agent); $row['modules'] = array(); @@ -3079,7 +3078,6 @@ function reporting_alert_report_agent($report, $content) { $return["description"] = $content["description"]; $return["date"] = reporting_get_date_text($report, $content); $return['label'] = (isset($content['style']['label'])) ? $content['style']['label'] : ''; - // TODO TAGS agents_get_modules $module_list = agents_get_modules($content['id_agent']); $data = array(); diff --git a/pandora_console/include/functions_reporting_html.php b/pandora_console/include/functions_reporting_html.php index 4fb6cfa4e4..fd4d0a2c76 100644 --- a/pandora_console/include/functions_reporting_html.php +++ b/pandora_console/include/functions_reporting_html.php @@ -3346,7 +3346,6 @@ function reporting_get_agent_monitors_table ($id_agent, $period = 0, $date = 0) function reporting_get_agent_modules_table ($id_agent, $period = 0, $date = 0) { $table->data = array (); $n_a_string = __('N/A').'(*)'; - // TODO TAGS agents_get_modules $modules = agents_get_modules ($id_agent, array ("nombre", "descripcion")); if ($modules === false) $modules = array(); From 75768c9eaaee83493272ec18aa12e9075121ada9 Mon Sep 17 00:00:00 2001 From: Fermin Date: Thu, 4 Oct 2018 16:23:36 +0200 Subject: [PATCH 24/42] [Tags performance] Open reporting checks --- pandora_console/include/functions_reporting.php | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index 279c972324..6059c095ac 100755 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -3667,7 +3667,6 @@ function reporting_agent_configuration($report, $content) { $agent_configuration['description'] = $agent_data['comentarios']; $agent_configuration['enabled'] = (int)!$agent_data['disabled']; $agent_configuration['group'] = $report["group"]; - // TODO TAGS agents_get_modules $modules = agents_get_modules ($content['id_agent']); $agent_configuration['modules'] = array(); @@ -8286,11 +8285,10 @@ function reporting_get_agentmodule_ttr ($id_agent_module, $period = 0, $date = 0 * Get a detailed report of the modules of the agent * * @param int $id_agent Agent id to get the report for. - * @param string $filter filter for get partial modules. * * @return array An array */ -function reporting_get_agent_module_info ($id_agent, $filter = false) { +function reporting_get_agent_module_info ($id_agent) { global $config; $return = array (); @@ -8306,12 +8304,7 @@ function reporting_get_agent_module_info ($id_agent, $filter = false) { return $return; } - if ($filter != '') { - $filter = 'AND '; - } - - $filter = 'disabled = 0'; - // TODO TAGS agents_get_modules + $filter = array('disabled' => 0); $modules = agents_get_modules($id_agent, false, $filter, true, false); if ($modules === false) { From 979e443824a1daf43c757b3f0aad867e54e174a6 Mon Sep 17 00:00:00 2001 From: Fermin Date: Thu, 4 Oct 2018 16:31:24 +0200 Subject: [PATCH 25/42] Removed unused code --- .../include/functions_reporting.php | 27 ------------------- 1 file changed, 27 deletions(-) diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index 6059c095ac..0b24819347 100755 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -8402,33 +8402,6 @@ function reporting_tiny_stats ($counts_info, $return = false, $type = 'agent', $ break; } - if ($strict_user && $type == 'agent') { - - $acltags = tags_get_user_groups_and_tags ($config['id_user'],'AR', $strict_user); - $filter['disabled'] = 0; - $id_agent = $counts_info['id_agente']; - - $counts_info = array(); - $counts_info['normal_count'] = count(tags_get_agent_modules ($id_agent, false, $acltags, false, $filter, false, AGENT_MODULE_STATUS_NORMAL)); - $counts_info['warning_count'] = count(tags_get_agent_modules ($id_agent, false, $acltags, false, $filter, false, AGENT_MODULE_STATUS_WARNING)); - $counts_info['critical_count'] = count(tags_get_agent_modules ($id_agent, false, $acltags, false, $filter, false, AGENT_MODULE_STATUS_CRITICAL_BAD)); - $counts_info['notinit_count'] = count(tags_get_agent_modules ($id_agent, false, $acltags, false, $filter, false, AGENT_MODULE_STATUS_NOT_INIT)); - $counts_info['unknown_count'] = count(tags_get_agent_modules ($id_agent, false, $acltags, false, $filter, false, AGENT_MODULE_STATUS_UNKNOWN)); - $counts_info['total_count'] = $counts_info['normal_count'] + $counts_info['warning_count'] + $counts_info['critical_count'] + $counts_info['unknown_count'] + $counts_info['notinit_count']; - - $all_agent_modules = tags_get_agent_modules ($id_agent, false, $acltags, false, $filter); - if (!empty($all_agent_modules)) { - $mod_clause = "(".implode(',', array_keys($all_agent_modules)).")"; - - $counts_info['fired_count'] = (int) db_get_sql ("SELECT COUNT(times_fired) - FROM talert_template_modules - WHERE times_fired != 0 AND id_agent_module IN ".$mod_clause); - } - else { - $counts_info['fired_count'] = 0; - } - } - // Store the counts in a data structure to print hidden divs with titles $stats = array(); From 1278f03fd965dbc90a5c7c9603a4cc88e006089e Mon Sep 17 00:00:00 2001 From: Fermin Date: Thu, 4 Oct 2018 19:08:01 +0200 Subject: [PATCH 26/42] [Tags performance] agents_get_modules misc checks --- .../godmode/reporting/graph_container.php | 1 - .../operation/agentes/exportdata.php | 18 ++---------------- pandora_console/operation/agentes/graphs.php | 3 --- 3 files changed, 2 insertions(+), 20 deletions(-) diff --git a/pandora_console/godmode/reporting/graph_container.php b/pandora_console/godmode/reporting/graph_container.php index 09084c14e0..2785db4dba 100644 --- a/pandora_console/godmode/reporting/graph_container.php +++ b/pandora_console/godmode/reporting/graph_container.php @@ -66,7 +66,6 @@ if ($enterpriseEnable) { } $subsection = reporting_enterprise_add_graph_template_subsection('', $buttons); -reporting_enterprise_select_graph_template_tab(); $buttons['graph_container'] = array('active' => true, 'text' => '' . diff --git a/pandora_console/operation/agentes/exportdata.php b/pandora_console/operation/agentes/exportdata.php index 5319d700d0..579dbe8382 100644 --- a/pandora_console/operation/agentes/exportdata.php +++ b/pandora_console/operation/agentes/exportdata.php @@ -37,21 +37,8 @@ ui_print_page_header (__("Export data"), "images/server_export_mc.png"); $group = get_parameter_post ('group', 0); $agentName = get_parameter_post ('agent', 0); - -switch ($config["dbtype"]) { - case "mysql": - $agents = agents_get_agents( - array('nombre LIKE "' . $agentName . '"'), array ('id_agente')); - break; - case "postgresql": - $agents = agents_get_agents( - array('nombre LIKE \'' . $agentName . '\''), array ('id_agente')); - break; - case "oracle": - $agents = agents_get_agents( - array('nombre LIKE \'%' . $agentName . '%\''), array ('id_agente')); - break; -} +$agents = agents_get_agents( + array('nombre LIKE "' . $agentName . '"'), array ('id_agente')); $agent = $agents[0]['id_agente']; $module = (array) get_parameter_post ('module_arr', array ()); @@ -283,7 +270,6 @@ if (empty($export_btn) || $show_form) { $table->data[2][0] .= ui_print_help_tip(__("No modules of type string. You can not calculate their average"),true); if ($agent > 0) { - // TODO TAGS agents_get_modules $modules = agents_get_modules ($agent); } else { diff --git a/pandora_console/operation/agentes/graphs.php b/pandora_console/operation/agentes/graphs.php index f13c92d157..4c9a546798 100644 --- a/pandora_console/operation/agentes/graphs.php +++ b/pandora_console/operation/agentes/graphs.php @@ -47,7 +47,6 @@ $option_type = get_parameter('option_type', 0); // - others //---------------------------------------------------------------------- $list_modules = array(); -// TODO TAGS agents_get_modules $modules_networkmap_no_proc = agents_get_modules( $id_agente, false, array( 'id_modulo' => 2, // networkmap type @@ -62,7 +61,6 @@ $modules_networkmap_no_proc = agents_get_modules( )); if (empty($modules_networkmap_no_proc)) $modules_networkmap_no_proc = array(); -// TODO TAGS agents_get_modules $modules_others = agents_get_modules( $id_agente, false, array( 'id_tipo_modulo' => array( @@ -77,7 +75,6 @@ $modules_others = agents_get_modules( if (empty($modules_others)) $modules_others = array(); -// TODO TAGS agents_get_modules $modules_boolean = agents_get_modules( $id_agente, false, array( 'id_tipo_modulo' => array( From e8621e54e575d1391306a37ac53dd43887a7543d Mon Sep 17 00:00:00 2001 From: danielmaya Date: Fri, 5 Oct 2018 09:40:08 +0200 Subject: [PATCH 27/42] Updated tags optimization --- .../extensions/matrix_events/ajax.php | 33 ++---- .../godmode/agentes/module_manager.php | 2 - pandora_console/include/ajax/events.php | 2 +- pandora_console/include/functions_alerts.php | 18 --- pandora_console/include/functions_events.php | 3 +- pandora_console/include/functions_tags.php | 106 +----------------- .../include/javascript/pandora_events.js | 1 - .../agentes/estado_generalagente.php | 2 +- .../operation/agentes/tactical.php | 1 - .../operation/events/events.build_query.php | 2 +- 10 files changed, 19 insertions(+), 151 deletions(-) diff --git a/pandora_console/extensions/matrix_events/ajax.php b/pandora_console/extensions/matrix_events/ajax.php index 0dd7706784..8e94e396f5 100644 --- a/pandora_console/extensions/matrix_events/ajax.php +++ b/pandora_console/extensions/matrix_events/ajax.php @@ -30,28 +30,19 @@ if (is_ajax()) { require_once ('include/functions_tags.php'); $limit = (int) get_parameter("limit", 5); - // TODO revision tag - $tags_condition = tags_get_acl_tags($config['id_user'], 0, 'ER', 'event_condition', 'AND'); - $filter = "estado<>1 $tags_condition"; - switch ($config["dbtype"]) { - case "mysql": - case "postgresql": - $sql = sprintf ("SELECT id_agente, evento, utimestamp - FROM tevento - WHERE %s - ORDER BY utimestamp DESC LIMIT %d", - $filter, $limit); - break; - case "oracle": - $sql = sprintf ("SELECT * - FROM tevento - WHERE %s - AND rownum <= %d - ORDER BY utimestamp DESC", - $filter, $limit); - break; - } + $tags_condition = tags_get_acl_tags($config['id_user'], 0, 'ER', 'event_condition', 'AND'); + + $filter = "estado <> 1 $tags_condition"; + + $sql = sprintf ("SELECT id_agente, evento, utimestamp + FROM tevento + LEFT JOIN tagent_secondary_group + ON tevento.id_agente = tagent_secondary_group.id_agent + WHERE %s + ORDER BY utimestamp DESC LIMIT %d", + $filter, $limit); + $result = db_get_all_rows_sql ($sql); $events = array(); diff --git a/pandora_console/godmode/agentes/module_manager.php b/pandora_console/godmode/agentes/module_manager.php index ffcb69c96c..8f95620398 100644 --- a/pandora_console/godmode/agentes/module_manager.php +++ b/pandora_console/godmode/agentes/module_manager.php @@ -455,8 +455,6 @@ $search_string_entities = io_safe_input($search_string); $basic_where = sprintf("(nombre LIKE '%%%s%%' OR nombre LIKE '%%%s%%' OR descripcion LIKE '%%%s%%' OR descripcion LIKE '%%%s%%') AND", $search_string, $search_string_entities, $search_string, $search_string_entities); // Tags acl -$tags_join = ""; -$tags_condition = ""; $agent_tags = tags_get_user_applied_agent_tags($id_agente); if ($agent_tags !== true) { $where_tags = " AND ttag_module.id_tag IN (" . implode(',', $agent_tags) . ")"; diff --git a/pandora_console/include/ajax/events.php b/pandora_console/include/ajax/events.php index 5874ccc511..070ce03a2a 100644 --- a/pandora_console/include/ajax/events.php +++ b/pandora_console/include/ajax/events.php @@ -555,7 +555,7 @@ if ($table_events) { // Fix: for tag functionality groups have to be all user_groups (propagate ACL funct!) $groups = users_get_groups($config["id_user"]); - // TODO revision tag + $tags_condition = tags_get_acl_tags($config['id_user'], array_keys($groups), 'ER', 'event_condition', 'AND'); echo '
'; diff --git a/pandora_console/include/functions_alerts.php b/pandora_console/include/functions_alerts.php index 6d121d0f46..b81dcb802b 100644 --- a/pandora_console/include/functions_alerts.php +++ b/pandora_console/include/functions_alerts.php @@ -1810,24 +1810,6 @@ function get_group_alerts($id_group, $filter = '', $options = false, FROM tagente_modulo WHERE delete_pending = 0'; } - if ($strict_user) { - $groups = users_get_groups($config["id_user"]); - - if ($idGroup !== 0) { - // TODO revision tag - $where_tags = tags_get_acl_tags($config['id_user'], $idGroup, 'AR', 'module_condition', 'AND', 'tagente_modulo', true, array(), true); - } else { - $where_tags = tags_get_acl_tags($config['id_user'], array_keys($groups), 'AR', 'module_condition', 'AND', 'tagente_modulo', true, array(), true); - } - - // If there are any errors add imposible condition - if (in_array($where_tags, array(ERR_WRONG_PARAMETERS, ERR_ACL))) { - $subQuery .= ' AND 1 = 0'; - } - else { - $subQuery .= $where_tags; - } - } } else { if ($allModules) diff --git a/pandora_console/include/functions_events.php b/pandora_console/include/functions_events.php index bfdc9e6238..5f5f6a65b1 100644 --- a/pandora_console/include/functions_events.php +++ b/pandora_console/include/functions_events.php @@ -3554,7 +3554,6 @@ function events_sql_events_grouped_agents($id_agent, $server_id = -1, else { $group_array = array_keys($groups); } - // TODO revision tag $tags_acls_condition = tags_get_acl_tags($id_user, $group_array, 'ER', 'event_condition', 'AND', '', $meta, array(), true); //FORCE CHECK SQL "(TAG = tag1 AND id_grupo = 1)" @@ -3600,6 +3599,8 @@ function events_list_events_grouped_agents($sql) { $table = events_get_events_table(is_metaconsole(), $history); $sql = "select * from $table + LEFT JOIN tagent_secondary_group + ON tagent_secondary_group.id_agent = tevento.id_agente WHERE $sql"; $result = db_get_all_rows_sql ($sql); diff --git a/pandora_console/include/functions_tags.php b/pandora_console/include/functions_tags.php index d7349c745f..83faac9a7a 100644 --- a/pandora_console/include/functions_tags.php +++ b/pandora_console/include/functions_tags.php @@ -988,7 +988,6 @@ function tags_get_user_tags($id_user = false, $access = 'AR', $return_tag_any = } // Get the tags of the required access flag for each group - // TODO revision tag $tags = tags_get_acl_tags($id_user, 0, $access, 'data'); // If there are wrong parameters or fail ACL check, return false if ($tags_user === ERR_WRONG_PARAMETERS || $tags_user === ERR_ACL) { @@ -1076,8 +1075,7 @@ function tags_get_tags_for_module_search($id_user = false, $access = 'AR') { //-------------------------------------------------------------- return false; } - // Get the tags of the required access flag for each group - // TODO revision tag + // Get the tags of the required access flag for each group $tags = tags_get_acl_tags($id_user, 0, $access, 'data'); // If there are wrong parameters or fail ACL check, return false if ($tags_user === ERR_WRONG_PARAMETERS || $tags_user === ERR_ACL) { @@ -1161,7 +1159,7 @@ function tags_check_acl($id_user, $id_group, $access, $tags = array(), $flag_id_ $id_group[] = $parent['id_grupo']; } } - // TODO revision tag + $acls = tags_get_acl_tags($id_user, $id_group, $access, 'data'); // If there are wrong parameters or fail ACL check, return false @@ -1261,106 +1259,6 @@ function tags_check_acl($id_user, $id_group, $access, $tags = array(), $flag_id_ return false; } -function tags_check_acl_event($id_user, $id_group, $access, $tags = array(),$p = false) { - global $config; - - if($id_user === false) { - $id_user = $config['id_user']; - } - // TODO revision tag - $acls = tags_get_acl_tags($id_user, $id_group, $access, 'data'); - - // If there are wrong parameters or fail ACL check, return false - if($acls === ERR_WRONG_PARAMETERS || $acls === ERR_ACL) { - return false; - } - - // If there are not tags restrictions or tags passed, check the group access - if (empty($acls) || empty($tags)) { - if (!is_array($id_group)) - $group_id_array = array($id_group); - - foreach ($id_group as $group) { - if (check_acl($id_user, $group, $access)) - return true; - } - } - - # Fix: If user profile has more than one group, due to ACL propagation then id_group can be an array - if (is_array($id_group)) { - - foreach ($id_group as $group) { - if ($group > 0) { - if (isset($acls[$group])) { - foreach ($tags as $tag) { - $tag = tags_get_id($tag); - if (in_array($tag, $acls[$group])) { - return true; - } - } - } - else { - //return false; - $return = false; - } - } - else { - foreach ($acls as $acl_tags) { - foreach ($tags as $tag) { - $tag = tags_get_id($tag); - if (in_array($tag, $acl_tags)) { - return true; - } - } - } - } - - } - - } - else { - if ($id_group > 0) { - if (isset($acls[$id_group])) { - foreach ($tags as $tag) { - $tag = tags_get_id($tag); - - if (in_array($tag, $acls[$id_group])) { - return true; - } - } - } - else { - //return false; - $return = false; - } - } - else { - foreach ($acls as $acl_tags) { - foreach ($tags as $tag) { - $tag = tags_get_id($tag); - if (in_array($tag, $acl_tags)) { - return true; - } - } - } - } - } - //return false; - $return = false; - - if ($return == false) { - $parent = db_get_value('parent','tgrupo','id_grupo',$id_group); - - if ($parent !== 0) { - $propagate = db_get_value('propagate','tgrupo','id_grupo',$parent); - if ($propagate == 1) { - $acl_parent = tags_check_acl_event($id_user, $parent, $access, $tags,$p); - return $acl_parent; - } - } - } -} - /* This function checks event ACLs */ function tags_checks_event_acl($id_user, $id_group, $access, $tags = array(), $childrens_ids = array()) { global $config; diff --git a/pandora_console/include/javascript/pandora_events.js b/pandora_console/include/javascript/pandora_events.js index 16d2ad4e0c..02eac5553c 100644 --- a/pandora_console/include/javascript/pandora_events.js +++ b/pandora_console/include/javascript/pandora_events.js @@ -540,7 +540,6 @@ function show_events_group_agent (id_insert, id_agent, server_id) { data: parameter, dataType: 'html', success: function (data) { - console.log(data); $("#"+id_insert).html(data); $("#"+id_insert).toggle(); } diff --git a/pandora_console/operation/agentes/estado_generalagente.php b/pandora_console/operation/agentes/estado_generalagente.php index f55889006f..64b2a2f212 100755 --- a/pandora_console/operation/agentes/estado_generalagente.php +++ b/pandora_console/operation/agentes/estado_generalagente.php @@ -549,7 +549,7 @@ if (!empty($network_interfaces)) { else { $group_array = $user_groups_ids; } - // TODO revision tag + $acl_tags = tags_get_acl_tags($config['id_user'], $group_array, 'ER', 'event_condition', 'AND', '', true, array(), true); diff --git a/pandora_console/operation/agentes/tactical.php b/pandora_console/operation/agentes/tactical.php index 43d0127ce7..dd2472d7bc 100755 --- a/pandora_console/operation/agentes/tactical.php +++ b/pandora_console/operation/agentes/tactical.php @@ -178,7 +178,6 @@ echo '1"; if (!empty($tags_condition)) { diff --git a/pandora_console/operation/events/events.build_query.php b/pandora_console/operation/events/events.build_query.php index 69411d647a..79a4a0538a 100755 --- a/pandora_console/operation/events/events.build_query.php +++ b/pandora_console/operation/events/events.build_query.php @@ -310,7 +310,7 @@ if ($id_group > 0 && in_array ($id_group, array_keys ($groups))) { else { $group_array = array_keys($groups); } -// TODO revision tag + if (check_acl ($id_user, 0, "ER")) $tags_acls_condition = tags_get_acl_tags($id_user, $group_array, 'ER', 'event_condition', 'AND', '', $meta, array(), true); //FORCE CHECK SQL "(TAG = tag1 AND id_grupo = 1)" From 198eb1bbc3e00088efa75afdad07981ce21cc90e Mon Sep 17 00:00:00 2001 From: Fermin Date: Fri, 5 Oct 2018 10:12:40 +0200 Subject: [PATCH 28/42] [Tags performance] Fixed parent module select --- .../agentes/module_manager_editor_common.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/pandora_console/godmode/agentes/module_manager_editor_common.php b/pandora_console/godmode/agentes/module_manager_editor_common.php index 61a5a23d32..0b9207a817 100644 --- a/pandora_console/godmode/agentes/module_manager_editor_common.php +++ b/pandora_console/godmode/agentes/module_manager_editor_common.php @@ -189,9 +189,23 @@ $table_simple->data[0][3] .= html_print_select_from_sql ('SELECT id_mg, name FRO $in_policy = strstr($page, "policy_modules"); if (!$in_policy) { + // Cannot select the current module to be itself parent + $module_parent_filter = $id_agent_module + ? array("tagente_modulo.id_agente_modulo" => "<>$id_agent_module") + : ""; $table_simple->data[1][0] = __('Module parent'); - $table_simple->data[1][1] .= html_print_select_from_sql ('SELECT id_agente_modulo, nombre FROM tagente_modulo WHERE id_agente = ' . $id_agente . ' ORDER BY nombre', - 'parent_module_id', $parent_module_id, '', __('Not assigned'), '0', true, false, true); + $modules_can_be_parent = agents_get_modules($id_agente, false, $module_parent_filter); + // If the user cannot have access to parent module, only print the name + if ($parent_module_id != 0 && !in_array($parent_module_id, array_keys($modules_can_be_parent))) { + $table_simple->data[1][1] = db_get_value( + 'nombre', 'tagente_modulo', 'id_agente_modulo', $parent_module_id + ); + } else { + $table_simple->data[1][1] = html_print_select ( + $modules_can_be_parent, 'parent_module_id', $parent_module_id, '', + __('Not assigned'), '0', true + ); + } } $table_simple->data[2][0] = __('Type').' ' . ui_print_help_icon ('module_type', true); From 1e4c570541b640c6705ea00bb4b03f38232b59dc Mon Sep 17 00:00:00 2001 From: Fermin Date: Fri, 5 Oct 2018 10:44:24 +0200 Subject: [PATCH 29/42] [Tags performance] check agents_get_modules in networkmap and removed unused code --- pandora_console/include/functions_graph.php | 4 +- .../include/functions_networkmap.php | 322 +----------------- .../functions_pandora_networkmap.js | 20 -- .../agentes/pandora_networkmap.view.php | 16 - 4 files changed, 14 insertions(+), 348 deletions(-) diff --git a/pandora_console/include/functions_graph.php b/pandora_console/include/functions_graph.php index f09bb04c45..feac091234 100644 --- a/pandora_console/include/functions_graph.php +++ b/pandora_console/include/functions_graph.php @@ -4183,16 +4183,14 @@ function graph_monitor_wheel ($width = 550, $height = 600, $filter = false) { if (!empty($agents)) { $agents_id = array(); $agents_aux = array(); - foreach ($agents as $key => $agent) { + foreach ($agents as $key => $agent) { $agents_aux[$agent['id_agente']] = $agent; } $agents = $agents_aux; $agents_aux = null; - $fields = array('id_agente_modulo', 'id_agente', 'id_module_group', 'nombre'); $module_groups = modules_get_modulegroups(); $module_groups[0] = __('Not assigned'); - // TODO TAGS agents_get_modules $modules = agents_get_modules(array_keys($agents), '*'); $data_agents = array(); diff --git a/pandora_console/include/functions_networkmap.php b/pandora_console/include/functions_networkmap.php index 9ea4e9ef11..8078fdfc59 100644 --- a/pandora_console/include/functions_networkmap.php +++ b/pandora_console/include/functions_networkmap.php @@ -260,7 +260,7 @@ function networkmap_generate_dot ($pandora_name, $group = 0, $relative = false, $text_filter = '', $ip_mask = null, $dont_show_subgroups = false, $strict_user = false, $size_canvas = null, $old_mode = false, $map_filter = array()) { - + global $config; $nooverlap = 1; @@ -271,17 +271,8 @@ function networkmap_generate_dot ($pandora_name, $group = 0, $filter['disabled'] = 0; if (!empty($text_filter)) { - switch ($config['dbtype']) { - case "mysql": - case "postgresql": - $filter[] = - '(nombre COLLATE utf8_general_ci LIKE "%' . $text_filter . '%")'; - break; - case "oracle": - $filter[] = - '(upper(nombre) LIKE upper(\'%' . $text_filter . '%\'))'; - break; - } + $filter[] = + '(nombre COLLATE utf8_general_ci LIKE "%' . $text_filter . '%")'; } if ($group >= 1) { @@ -305,33 +296,11 @@ function networkmap_generate_dot ($pandora_name, $group = 0, //foreach loop are without parent (id_parent = 0) // Get agents data - if ($strict_user) { - if ($dont_show_subgroups) - $filter['id_group'] = $group; - else { - if (!empty($childrens)) { - foreach ($childrens as $children) { - $filter_id_groups[$children] = $children; - } - } - $filter_id_groups[$group] = $group; - $filter['id_group'] = implode(',', $filter_id_groups); - } - - $filter['group_by'] = 'tagente.id_agente'; - $fields = array ('tagente.id_grupo, tagente.nombre, tagente.id_os, tagente.id_parent, tagente.id_agente, - tagente.normal_count, tagente.warning_count, tagente.critical_count, - tagente.unknown_count, tagente.total_count, tagente.notinit_count'); - $acltags = tags_get_user_groups_and_tags ($config['id_user'],'AR', $strict_user); - $agents = tags_get_all_user_agents (false, $config['id_user'], $acltags, $filter, $fields, false, $strict_user, true); - } - else { - $agents = agents_get_agents ($filter, - array ('id_grupo, nombre, id_os, id_parent, id_agente, - normal_count, warning_count, critical_count, - unknown_count, total_count, notinit_count'), 'AR', - array('field' => 'id_parent', 'order' => 'ASC')); - } + $agents = agents_get_agents ($filter, + array ('id_grupo, nombre, id_os, id_parent, id_agente, + normal_count, warning_count, critical_count, + unknown_count, total_count, notinit_count'), 'AR', + array('field' => 'id_parent', 'order' => 'ASC')); } else if ($group == -666) { $agents = false; @@ -343,21 +312,11 @@ function networkmap_generate_dot ($pandora_name, $group = 0, unknown_count, total_count, notinit_count'), $strict_user); } else { - if ($strict_user) { - $filter['group_by'] = 'tagente.id_agente'; - $fields = array ('tagente.id_grupo, tagente.nombre, tagente.id_os, tagente.id_parent, tagente.id_agente, - tagente.normal_count, tagente.warning_count, tagente.critical_count, - tagente.unknown_count, tagente.total_count, tagente.notinit_count'); - $acltags = tags_get_user_groups_and_tags ($config['id_user'],'AR', $strict_user); - $agents = tags_get_all_user_agents (false, $config['id_user'], $acltags, $filter, $fields, false, $strict_user, true); - } - else { - $agents = agents_get_agents ($filter, - array ('id_grupo, nombre, id_os, id_parent, id_agente, - normal_count, warning_count, critical_count, - unknown_count, total_count, notinit_count'), 'AR', - array('field' => 'id_parent', 'order' => 'ASC')); - } + $agents = agents_get_agents ($filter, + array ('id_grupo, nombre, id_os, id_parent, id_agente, + normal_count, warning_count, critical_count, + unknown_count, total_count, notinit_count'), 'AR', + array('field' => 'id_parent', 'order' => 'ASC')); } if ($agents === false) @@ -392,7 +351,6 @@ function networkmap_generate_dot ($pandora_name, $group = 0, $filter['disabled'] = 0; // Get agent modules data - // TODO TAGS agents_get_modules $modules = agents_get_modules($agent['id_agente'], '*', $filter, true, true); if ($modules === false) @@ -615,260 +573,6 @@ function networkmap_generate_dot ($pandora_name, $group = 0, return $graph; } -// Generate a dot graph definition for graphviz with groups -function networkmap_generate_dot_groups ($pandora_name, $group = 0, - $simple = 0, $font_size = 12, $layout = 'radial', $nooverlap = 0, - $zoom = 1, $ranksep = 2.5, $center = 0, $regen = 1, $pure = 0, - $modwithalerts = 0, $module_group = 0, $hidepolicymodules = 0, - $depth = 'all', $id_networkmap = 0, $dont_show_subgroups = 0, - $text_filter = '', $strict_user = false, $size_canvas = null) { - - global $config; - - if ($strict_user) { - $acltags = tags_get_user_groups_and_tags ($config['id_user'],'AR', $strict_user); - } - $parents = array(); - $orphans = array(); - - $filter = array (); - $filter['disabled'] = 0; - - if (!empty($text_filter)) { - switch ($config['dbtype']) { - case "mysql": - case "postgresql": - $filter[] = - '(nombre COLLATE utf8_general_ci LIKE "%' . $text_filter . '%")'; - break; - case "oracle": - $filter[] = - '(upper(nombre) LIKE upper(\'%' . $text_filter . '%\'))'; - break; - } - } - - // Get groups data - if ($group > 0) { - $groups = array(); - $id_groups = groups_get_id_recursive($group, true); - - foreach($id_groups as $id_group) { - $add = false; - if (check_acl($config["id_user"], $id_group, 'AR')) { - $add = true; - } - - if ($add) { - $groups[] = db_get_row ('tgrupo', 'id_grupo', $id_group); - } - } - - $filter['id_grupo'] = $id_groups; - } - else { - if ($strict_user) { - $groups = users_get_groups ($config['id_user'],"AR", false, true); - } - else { - $groups = db_get_all_rows_in_table ('tgrupo'); - } - if ($groups === false) { - $groups = array(); - } - } - - // Open Graph - $graph = networkmap_open_graph ($layout, $nooverlap, $pure, $zoom, - $ranksep, $font_size, $size_canvas); - - $node_count = 0; - - // Parse groups - $nodes = array (); - $nodes_groups = array(); - foreach ($groups as $group2) { - $node_count ++; - $group2['type'] = 'group'; - $group2['id_node'] = $node_count; - - // Add node - $nodes_groups[$group2['id_grupo']] = $group2; - } - - $node_count = 0; - - $groups_hiden = array(); - foreach ($nodes_groups as $node_group) { - - $node_count++; - - // Save node parent information to define edges later - if ($node_group['parent'] != "0" && $node_group['id_grupo'] != $group) { - if ((!$dont_show_subgroups) || ($group == 0)) { - $parents[$node_count] = $nodes_groups[$node_group['parent']]['id_node']; - } - else { - $groups_hiden[$node_group['id_grupo']] = 1; - continue; - } - } - else { - $orphans[$node_count] = 1; - } - - $nodes[$node_count] = $node_group; - } - - if ($depth != 'group') { - if ($strict_user) { - $filter['group_by'] = 'tagente.nombre'; - $filter['id_group'] = $filter['id_grupo']; - $fields = array ('tagente.id_grupo, tagente.nombre, tagente.id_os, tagente.id_agente, - tagente.normal_count, tagente.warning_count, tagente.critical_count, - tagente.unknown_count, tagente.total_count, tagente.notinit_count'); - $agents = tags_get_all_user_agents (false, $config['id_user'], $acltags, $filter, $fields, false, $strict_user, true); - unset($filter['id_group']); - } - else { - // Get agents data - $agents = agents_get_agents ($filter, - array ('id_grupo, nombre, id_os, id_agente, - normal_count, warning_count, critical_count, - unknown_count, total_count, notinit_count')); - } - if ($agents === false) - $agents = array(); - - // Parse agents - $nodes_agents = array(); - foreach ($agents as $agent) { - if ($dont_show_subgroups) { - if (!empty($groups_hiden[$agent['id_grupo']])) { - continue; - } - } - - // If only agents with alerts => agents without alerts discarded - $alert_agent = agents_get_alerts($agent['id_agente']); - - if ($modwithalerts and empty($alert_agent['simple'])) { - continue; - } - - $node_count ++; - // Save node parent information to define edges later - $parents[$node_count] = $agent['parent'] = $nodes_groups[$agent['id_grupo']]['id_node']; - - $agent['id_node'] = $node_count; - $agent['type'] = 'agent'; - // Add node - $nodes[$node_count] = $nodes_agents[$agent['id_agente']] = $agent; - - if ($depth == 'agent') { - continue; - } - - // Get agent modules data - // TODO TAGS agents_get_modules - $modules = agents_get_modules ($agent['id_agente'], false, array('disabled' => 0), true, false); - - // Parse modules - foreach ($modules as $key => $module) { - $node_count ++; - $agent_module = modules_get_agentmodule($key); - $alerts_module = db_get_sql('SELECT count(*) AS num - FROM talert_template_modules - WHERE id_agent_module = ' . $key); - - if ($alerts_module == 0 && $modwithalerts) { - continue; - } - - if ($agent_module['id_module_group'] != $module_group && - $module_group != 0) { - continue; - } - - if ($hidepolicymodules && $config['enterprise_installed']) { - enterprise_include_once('include/functions_policies.php'); - if (policies_is_module_in_policy($key)) { - continue; - } - } - - // Save node parent information to define edges later - $parents[$node_count] = $agent_module['parent'] = $agent['id_node']; - - $agent_module['id_node'] = $node_count; - - $agent_module['type'] = 'module'; - // Add node - $nodes[$node_count] = $agent_module; - } - } - } - - if (empty ($nodes)) { - return false; - } - - // Create void statistics array - $stats = array(); - - // Create nodes - foreach ($nodes as $node_id => $node) { - if ($center > 0 && ! networkmap_is_descendant ($node_id, $center, $parents)) { - unset ($parents[$node_id]); - unset ($orphans[$node_id]); - unset ($nodes[$node_id]); - continue; - } - switch ($node['type']) { - case 'group': - $graph .= networkmap_create_group_node ($node , $simple, $font_size, $metaconsole = false, null, $strict_user) . - "\n\t\t"; - $stats['groups'][] = $node['id_grupo']; - break; - case 'agent': - $graph .= networkmap_create_agent_node ($node , $simple, $font_size, true, true) . - "\n\t\t"; - $stats['agents'][] = $node['id_agente']; - break; - case 'module': - $graph .= networkmap_create_module_node ($node , $simple, $font_size) . - "\n\t\t"; - $stats['modules'][] = $node['id_agente_modulo']; - break; - } - } - // Define edges - foreach ($parents as $node => $parent_id) { - // Verify that the parent is in the graph - if (isset ($nodes[$parent_id])) { - $graph .= networkmap_create_edge ($node, $parent_id, $layout, $nooverlap, $pure, $zoom, $ranksep, $simple, $regen, $font_size, $group, 'operation/agentes/networkmap', 'groups', $id_networkmap); - } - else { - $orphans[$node] = 1; - } - } - - // Create a central node if orphan nodes exist - if (count ($orphans)) { - $graph .= networkmap_create_pandora_node ($pandora_name, $font_size, $simple, $stats); - } - - // Define edges for orphan nodes - foreach (array_keys($orphans) as $node) { - $graph .= networkmap_create_edge ('0', $node, $layout, $nooverlap, $pure, $zoom, $ranksep, $simple, $regen, $font_size, $group, 'operation/agentes/networkmap', 'groups', $id_networkmap); - } - - // Close graph - $graph .= networkmap_close_graph (); - - return $graph; -} - // Returns an edge definition function networkmap_create_edge ($head, $tail, $layout, $nooverlap, $pure, $zoom, $ranksep, $simple, $regen, $font_size, $group, $sec2 = 'operation/agentes/networkmap', $tab = 'topology', $id_networkmap = 0) { if (defined("METACONSOLE")) { diff --git a/pandora_console/include/javascript/functions_pandora_networkmap.js b/pandora_console/include/javascript/functions_pandora_networkmap.js index 7edc029f68..83418f97c1 100644 --- a/pandora_console/include/javascript/functions_pandora_networkmap.js +++ b/pandora_console/include/javascript/functions_pandora_networkmap.js @@ -3958,26 +3958,6 @@ function get_status_module() { }); } -function check_changes_num_modules() { - var params = []; - params.push("check_changes_num_modules=1"); - params.push("id=" + id_agent); - params.push("page=operation/agentes/pandora_networkmap.view"); - jQuery.ajax({ - data: params.join("&"), - dataType: 'json', - type: 'POST', - url: action = "../../../ajax.php", - success: function (data) { - if (data['correct']) { - if (module_count != data['count']) { - //location.reload(true); - } - } - } - }); -} - function show_networkmap_node(id_agent_param, refresh_state) { id_agent = id_agent_param; diff --git a/pandora_console/operation/agentes/pandora_networkmap.view.php b/pandora_console/operation/agentes/pandora_networkmap.view.php index f15c49e28d..738f9ed5df 100644 --- a/pandora_console/operation/agentes/pandora_networkmap.view.php +++ b/pandora_console/operation/agentes/pandora_networkmap.view.php @@ -563,8 +563,6 @@ if (is_ajax ()) { $get_status_node = (bool)get_parameter('get_status_node', false); $get_status_module = (bool)get_parameter('get_status_module', false); - $check_changes_num_modules = (bool)get_parameter( - 'check_changes_num_modules', false); if ($get_status_node) { $id = (int)get_parameter('id', 0); @@ -593,20 +591,6 @@ if (is_ajax ()) { return; } - if ($check_changes_num_modules) { - $id = (int)get_parameter('id', 0); - // TODO TAGS agents_get_modules - $modules = agents_get_modules($id); - - $return = array(); - $return['correct'] = true; - $return['count'] = count($modules); - - echo json_encode($return); - - return; - } - if ($update_node_alert) { $map_id = (int)get_parameter('map_id', 0); From a72b9b0515d2c60df6086a0995f1cd6ea1c5a8d6 Mon Sep 17 00:00:00 2001 From: Fermin Date: Fri, 5 Oct 2018 13:32:14 +0200 Subject: [PATCH 30/42] [Tags performance] Fixed agents_get_modules to ajax calls --- pandora_console/include/ajax/module.php | 5 ++++- pandora_console/include/functions_agents.php | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/pandora_console/include/ajax/module.php b/pandora_console/include/ajax/module.php index a2c675fd94..331de16279 100755 --- a/pandora_console/include/ajax/module.php +++ b/pandora_console/include/ajax/module.php @@ -554,7 +554,10 @@ if ($list_modules) { $tags_sql = ""; if($cluster_list != 1) { $tags = tags_get_user_applied_agent_tags ($id_agent, $access); - if (is_array($tags)) { + if ($tags === false) { + $tags_sql = " AND 1=0"; + } + elseif (is_array($tags)) { $tags_sql = " AND ttag_module.id_tag IN (" . implode(',', $tags) . ")"; $tags_join = "LEFT JOIN ttag_module ON ttag_module.id_agente_modulo = tagente_modulo.id_agente_modulo"; diff --git a/pandora_console/include/functions_agents.php b/pandora_console/include/functions_agents.php index 3335bb769e..cf193c0c09 100644 --- a/pandora_console/include/functions_agents.php +++ b/pandora_console/include/functions_agents.php @@ -2573,6 +2573,7 @@ function agents_get_all_groups_agent ($id_agent, $group = false, $force_meta = f // If cannot retrieve the group, it means that agent does not exist if (!$group) return array(); + enterprise_include_once('include/functions_agents.php'); $secondary_groups = enterprise_hook('agents_get_secondary_groups', array($id_agent, $force_meta)); // Return only an array with the group in open version From d2b8939804687776a85bede4d335b645a7b8a42e Mon Sep 17 00:00:00 2001 From: Fermin Date: Mon, 8 Oct 2018 12:33:40 +0200 Subject: [PATCH 31/42] [Tags performance] Fixed select_modules_for_agent_group function (failed with several secondary groups). --- pandora_console/include/functions_agents.php | 37 +++++++++++--------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/pandora_console/include/functions_agents.php b/pandora_console/include/functions_agents.php index cf193c0c09..2ead3d093f 100644 --- a/pandora_console/include/functions_agents.php +++ b/pandora_console/include/functions_agents.php @@ -2473,8 +2473,8 @@ function select_modules_for_agent_group( $id_group, $id_agents, $selection, $return = true ) { global $config; - $agents = implode(",", $id_agents); - + $agents = (empty($id_agents)) ? array() : implode(",", $id_agents); + $filter_agent_group = ""; $filter_group = ""; $filter_agent = ""; @@ -2499,7 +2499,7 @@ function select_modules_for_agent_group( } if (!$selection && $agents != null) { $number_agents = count($id_agents); - $selection_filter = "HAVING COUNT(tagente_modulo.id_agente_modulo) = $number_agents"; + $selection_filter = "HAVING COUNT(id_agente_modulo) = $number_agents"; } if (tags_has_user_acl_tags(false)){ @@ -2511,20 +2511,23 @@ function select_modules_for_agent_group( ON ttag_module.id_agente_modulo = tagente_modulo.id_agente_modulo"; } - $sql = "SELECT DISTINCT(tagente_modulo.id_agente_modulo), tagente_modulo.nombre - FROM tagente_modulo - $sql_tags_inner - INNER JOIN tagente - ON tagente.id_agente = tagente_modulo.id_agente - LEFT JOIN tagent_secondary_group tasg - ON tagente.id_agente = tasg.id_agent - WHERE tagente.disabled = 0 - AND tagente_modulo.disabled = 0 - $filter_agent_group - $filter_group - $filter_agent - $sql_conditions_tags - GROUP BY tagente_modulo.nombre + $sql = "SELECT * FROM + ( + SELECT DISTINCT(tagente_modulo.id_agente_modulo), tagente_modulo.nombre + FROM tagente_modulo + $sql_tags_inner + INNER JOIN tagente + ON tagente.id_agente = tagente_modulo.id_agente + LEFT JOIN tagent_secondary_group tasg + ON tagente.id_agente = tasg.id_agent + WHERE tagente.disabled = 0 + AND tagente_modulo.disabled = 0 + $filter_agent_group + $filter_group + $filter_agent + $sql_conditions_tags + ) x + GROUP BY nombre $selection_filter"; $modules = db_get_all_rows_sql($sql); From 099f01a4baf5df6efe88ab1a579e1909b6ddefff Mon Sep 17 00:00:00 2001 From: Fermin Date: Mon, 8 Oct 2018 13:45:30 +0200 Subject: [PATCH 32/42] [Tags performance] Fixed select modules from Agent/Module dashboard widget --- pandora_console/include/functions_agents.php | 23 ++++++++++------ .../operation/agentes/ver_agente.php | 27 ++++++++++--------- 2 files changed, 30 insertions(+), 20 deletions(-) diff --git a/pandora_console/include/functions_agents.php b/pandora_console/include/functions_agents.php index 2ead3d093f..25791a1194 100644 --- a/pandora_console/include/functions_agents.php +++ b/pandora_console/include/functions_agents.php @@ -2470,7 +2470,7 @@ function agents_get_agent_custom_field ($agent_id, $custom_field_name) { } function select_modules_for_agent_group( - $id_group, $id_agents, $selection, $return = true + $id_group, $id_agents, $selection, $return = true, $index_by_name = false ) { global $config; $agents = (empty($id_agents)) ? array() : implode(",", $id_agents); @@ -2533,16 +2533,23 @@ function select_modules_for_agent_group( $modules = db_get_all_rows_sql($sql); if ($modules === false) $modules = array(); - if($return == false){ - foreach ($modules as $value) { - $modules_array[$value['id_agente_modulo']] = $value['nombre']; - } - return $modules_array; - } - else{ + if ($return) { echo json_encode($modules); return; } + + $modules_array = array(); + foreach ($modules as $value) { + if($index_by_name) { + $modules_array[io_safe_output($value['nombre'])] = + ui_print_truncate_text( + io_safe_output($value['nombre']), 'module_medium', false, true + ); + } else { + $modules_array[$value['id_agente_modulo']] = $value['nombre']; + } + } + return $modules_array; } /** diff --git a/pandora_console/operation/agentes/ver_agente.php b/pandora_console/operation/agentes/ver_agente.php index 6c1d3b9718..5b660632d7 100644 --- a/pandora_console/operation/agentes/ver_agente.php +++ b/pandora_console/operation/agentes/ver_agente.php @@ -35,6 +35,7 @@ if (is_ajax ()) { $get_agent_status_tooltip = (bool) get_parameter ("get_agent_status_tooltip"); $get_agents_group_json = (bool) get_parameter ("get_agents_group_json"); $get_modules_group_json = (bool) get_parameter ("get_modules_group_json"); + $get_modules_group_value_name_json = (bool) get_parameter ("get_modules_group_value_name_json"); $get_agent_modules_json_for_multiple_agents = (bool) get_parameter("get_agent_modules_json_for_multiple_agents"); $get_agent_modules_alerts_json_for_multiple_agents = (bool) get_parameter("get_agent_modules_alerts_json_for_multiple_agents"); $get_agent_modules_multiple_alerts_json_for_multiple_agents = (bool) get_parameter("get_agent_modules_multiple_alerts_json_for_multiple_agents"); @@ -165,12 +166,23 @@ if (is_ajax ()) { } if ($get_modules_group_json) { - $id_group = (int) get_parameter('id_module_group'); + $id_group = (int) get_parameter('id_module_group', 0); $id_agents = get_parameter('id_agents'); $selection = get_parameter('selection'); select_modules_for_agent_group($id_group, $id_agents, $selection); } + + if ($get_modules_group_value_name_json) { + $id_agents = get_parameter('id_agents'); + $selection = get_parameter('selection'); + + // No filter by module group + $modules = select_modules_for_agent_group(0, $id_agents, $selection, false, true); + echo json_encode($modules); + return; + + } if ($get_agent_json) { $id_agent = (int) get_parameter ('id_agent'); @@ -373,17 +385,7 @@ if (is_ajax ()) { $filter .= ' AND t1.id_tipo_modulo NOT IN (' . implode($module_types_excluded) . ')'; if (!empty($module_name)) { - switch ($config['dbtype']) { - case "mysql": - $filter .= " AND t1.nombre COLLATE utf8_general_ci LIKE '%$module_name%'"; - break; - case "postgresql": - $filter .= " AND t1.nombre LIKE '%$module_name%'"; - break; - case "oracle": - $filter .= " AND UPPER(t1.nombre) LIKE UPPER('%$module_name%')"; - break; - } + $filter .= " AND t1.nombre COLLATE utf8_general_ci LIKE '%$module_name%'"; } // Status selector @@ -533,6 +535,7 @@ if (is_ajax ()) { asort($result); } else { + $modules = agents_get_modules(); if($idAgents[0] < 0){ if($selection_mode == 'common'){ $sql_agent_total = 'SELECT count(*) FROM tagente WHERE disabled=0'; From 441458843fb6c86d6c33cc755464b805ba86fc4a Mon Sep 17 00:00:00 2001 From: Fermin Date: Mon, 8 Oct 2018 17:19:46 +0200 Subject: [PATCH 33/42] [Tags performance] Fixed check acl tags by module and removed unused code --- pandora_console/include/functions_events.php | 7 +- pandora_console/include/functions_tags.php | 161 ++---------------- .../include/functions_treeview.php | 11 +- 3 files changed, 20 insertions(+), 159 deletions(-) diff --git a/pandora_console/include/functions_events.php b/pandora_console/include/functions_events.php index 5f5f6a65b1..33ca35c24a 100644 --- a/pandora_console/include/functions_events.php +++ b/pandora_console/include/functions_events.php @@ -2240,12 +2240,7 @@ function events_page_details ($event, $server = "") { $strict_user = (bool) db_get_value("strict_acl", "tusuario", "id_user", $config['id_user']); if (!empty($agent['id_grupo'])) { - if ($strict_user) { - $acl_graph = tags_check_acl_by_module($module["id_agente_modulo"], $config['id_user'], 'RR') === true; - } - else { - $acl_graph = check_acl($config['id_user'], $agent['id_grupo'], "RR"); - } + $acl_graph = check_acl($config['id_user'], $agent['id_grupo'], "RR"); } if ($acl_graph) { diff --git a/pandora_console/include/functions_tags.php b/pandora_console/include/functions_tags.php index 83faac9a7a..fe4cd97d07 100644 --- a/pandora_console/include/functions_tags.php +++ b/pandora_console/include/functions_tags.php @@ -457,7 +457,7 @@ function tags_get_module_tags ($id, $policy = false) { $tags = db_get_all_rows_filter('ttag_module', array('id_agente_modulo' => $id), false); } - + if ($tags === false) return array(); @@ -1111,151 +1111,26 @@ function tags_check_acl_by_module($id_module = 0, $id_user = false, $access = 'AW') { global $config; - $return = false; - - if (!empty($id_module)) { - $tags = tags_get_module_tags($id_module); - $groups = modules_get_agent_groups($id_module); - - if ($id_user === false) { - $id_user = $config["id_user"]; - } - - foreach ($groups as $group) { - if (tags_check_acl($id_user, $group, $access, $tags, true)) { - return true; - } - } - } - - return $return; -} - -/** - * Check the ACLs with tags - * - * @param string ID of the user (with false the user will be taked from config) - * @param string id of the group (0 means for at least one) - * @param string access flag (AR,AW...) - * @param mixed tags to be checked (array() means for at least one) - * - * @return bool true if the acl check has success, false otherwise - */ -function tags_check_acl($id_user, $id_group, $access, $tags = array(), $flag_id_tag = false) { - global $config; - + if (empty($id_module)) return false; if ($id_user === false) { - $id_user = $config['id_user']; + $id_user = $config["id_user"]; } - - // Get parents to check in propagate ACL cases - if (!is_array($id_group) && $id_group != 0) { - $id_group = array($id_group); - $group = db_get_row_filter('tgrupo', - array('id_grupo' => $id_group)); - $parents = groups_get_parents($group['parent'], true); - - foreach ($parents as $parent) { - $id_group[] = $parent['id_grupo']; - } + + $tags = tags_get_module_tags($id_module); + $groups = modules_get_agent_groups($id_module); + $user_groups = users_get_groups($id_user, $acces, false, true); + + $acl_column = get_acl_column($access); + foreach ($groups as $group) { + // If user has not permission for this group,go to next group + if (!isset($user_groups[$group])) continue; + // No tags means user can see all tags for this group + if (!isset($user_groups[$group]["tags"][$acl_column])) return true; + // Check acl + $intersection = array_intersect($tags, $user_groups[$group]["tags"][$acl_column]); + if(!empty($intersection)) return true; } - - $acls = tags_get_acl_tags($id_user, $id_group, $access, 'data'); - - // If there are wrong parameters or fail ACL check, return false - if ($acls === ERR_WRONG_PARAMETERS || $acls === ERR_ACL) { - return false; - } - - // If there are not tags restrictions or tags passed, check the group access - if (empty($acls) || empty($tags)) { - if (!is_array($id_group)) - $group_id_array = array($id_group); - - foreach ($id_group as $group) { - if (check_acl($id_user, $group, $access)) - return true; - } - } - - # Fix: If user profile has more than one group, due to ACL propagation then id_group can be an array - if (is_array($id_group)) { - - foreach ($id_group as $group) { - if ($group > 0) { - if (array_key_exists(0, $acls)) { - //There is a All group - - foreach ($tags as $tag) { - if (in_array($tag, $acls[0])) { - return true; - } - else { - return false; - } - } - } - else if (isset($acls[$group])) { - foreach ($tags as $tag) { - if (!$flag_id_tag) - $tag = tags_get_id($tag); - - if (in_array($tag, $acls[$group])) { - return true; - } else if (empty($acls[$group])) { - return true; - } - } - } - else { - return false; - } - } - else { - - foreach ($acls as $acl_tags) { - foreach ($tags as $tag) { - if (!$flag_id_tag) - $tag = tags_get_id($tag); - - if (in_array($tag, $acl_tags)) { - return true; - } - } - } - } - } - } - else { - if ($id_group > 0) { - if (isset($acls[$id_group])) { - foreach ($tags as $tag) { - if (!$flag_id_tag) - $tag = tags_get_id($tag); - - if (in_array($tag, $acls[$id_group])) { - return true; - } - } - } - else { - return false; - } - } - else { - foreach ($acls as $acl_tags) { - foreach ($tags as $tag) { - if (!$flag_id_tag) - $tag = tags_get_id($tag); - - if (in_array($tag, $acl_tags)) { - return true; - } - } - } - } - } - + return false; } diff --git a/pandora_console/include/functions_treeview.php b/pandora_console/include/functions_treeview.php index 20d1f577bc..2f2e899143 100755 --- a/pandora_console/include/functions_treeview.php +++ b/pandora_console/include/functions_treeview.php @@ -745,16 +745,7 @@ function treeview_printTable($id_agente, $server_data = array(), $no_head = fals foreach ($network_interfaces as $interface_name => $interface) { if (!empty($interface['traffic'])) { - $permission = false; - - if ($strict_user) { - if (tags_check_acl_by_module($interface['traffic']['in'], $config['id_user'], 'RR') === true - && tags_check_acl_by_module($interface['traffic']['out'], $config['id_user'], 'RR') === true) - $permission = true; - } - else { - $permission = check_acl($config['id_user'], $agent["id_grupo"], "RR"); - } + $permission = check_acl($config['id_user'], $agent["id_grupo"], "RR"); if ($permission) { $params = array( From f952d5c70e7f8b65ab51fce191fdf598f4bc741a Mon Sep 17 00:00:00 2001 From: danielmaya Date: Mon, 8 Oct 2018 17:45:26 +0200 Subject: [PATCH 34/42] tags_get_acl_tags revision --- .../reporting/visual_console_builder.elements.php | 8 +++++--- pandora_console/include/functions_graph.php | 11 ++++++----- pandora_console/include/functions_tags.php | 2 +- pandora_console/mobile/operation/modules.php | 13 +++++++++---- 4 files changed, 21 insertions(+), 13 deletions(-) diff --git a/pandora_console/godmode/reporting/visual_console_builder.elements.php b/pandora_console/godmode/reporting/visual_console_builder.elements.php index c7e63358fa..9796a217e8 100755 --- a/pandora_console/godmode/reporting/visual_console_builder.elements.php +++ b/pandora_console/godmode/reporting/visual_console_builder.elements.php @@ -420,9 +420,11 @@ foreach ($layoutDatas as $layoutData) { } else { if ($layoutData['id_agent'] != 0) { - $modules = agents_meta_get_modules( - $layoutData['id_metaconsole'], - $layoutData['id_agent']); + $server = db_get_row('tmetaconsole_setup', 'id', $layoutData['id_metaconsole']); + if (metaconsole_connect($server) == NOERR) { + $modules = agents_get_modules($layoutData['id_agent']); + metaconsole_restore_db(); + } } } diff --git a/pandora_console/include/functions_graph.php b/pandora_console/include/functions_graph.php index feac091234..fd9460819c 100644 --- a/pandora_console/include/functions_graph.php +++ b/pandora_console/include/functions_graph.php @@ -2267,7 +2267,7 @@ function graph_event_module ($width = 300, $height = 200, $id_agent) { // Fix: tag filters implemented! for tag functionality groups have to be all user_groups (propagate ACL funct!) $groups = users_get_groups($config["id_user"]); - // TODO revision tag + $tags_condition = tags_get_acl_tags($config['id_user'], array_keys($groups), 'ER', 'event_condition', 'AND'); $data = array (); @@ -2771,7 +2771,6 @@ function grafico_eventos_grupo ($width = 300, $height = 200, $url = "", $meta = } // Add tags condition to filter - // TODO revision tag $tags_condition = tags_get_acl_tags($config['id_user'], 0, 'ER', 'event_condition', 'AND'); //This will give the distinct id_agente, give the id_grupo that goes @@ -2859,7 +2858,6 @@ function grafico_eventos_total($filter = "", $width = 320, $height = 200, $noWat $filter = str_replace ( "\\" , "", $filter); // Add tags condition to filter - // TODO revision tag $tags_condition = tags_get_acl_tags($config['id_user'], 0, 'ER', 'event_condition', 'AND'); $filter .= $tags_condition; @@ -2873,8 +2871,11 @@ function grafico_eventos_total($filter = "", $width = 320, $height = 200, $noWat } $sql = sprintf("SELECT criticity, COUNT(id_evento) events - FROM tevento %s - GROUP BY criticity ORDER BY events DESC", $where); + FROM tevento + LEFT JOIN tagent_secondary_group tasg + ON tevento.id_agente = tasg.id_agent + %s %s + GROUP BY criticity ORDER BY events DESC", $where , $filter); $criticities = db_get_all_rows_sql ($sql, false, false); diff --git a/pandora_console/include/functions_tags.php b/pandora_console/include/functions_tags.php index fe4cd97d07..c2dac8a378 100644 --- a/pandora_console/include/functions_tags.php +++ b/pandora_console/include/functions_tags.php @@ -1145,7 +1145,7 @@ function tags_checks_event_acl($id_user, $id_group, $access, $tags = array(), $c if (users_is_admin($id_user)) { return true; } - // TODO revision tag + $tags_user = tags_get_acl_tags($id_user, $id_group, $access, 'data', '', '', true, $childrens_ids, true); // If there are wrong parameters or fail ACL check, return false if ($tags_user === ERR_WRONG_PARAMETERS || $tags_user === ERR_ACL) { diff --git a/pandora_console/mobile/operation/modules.php b/pandora_console/mobile/operation/modules.php index 5b86254209..f54b8009d3 100644 --- a/pandora_console/mobile/operation/modules.php +++ b/pandora_console/mobile/operation/modules.php @@ -281,8 +281,7 @@ class Modules { $modules = array(); $modules_db = array(); - $sql_conditions_base = " WHERE tagente.id_agente = tagente_modulo.id_agente - AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo"; + $sql_conditions_base = " WHERE 1=1"; // Part SQL for the id_agent @@ -302,7 +301,6 @@ class Modules { // Part SQL for the Tag - // TODO revision tag $sql_conditions_tags = tags_get_acl_tags($user->getIdUser(), $user->getIdGroups($this->acl), $this->acl, 'module_condition', 'AND', 'tagente_modulo'); @@ -401,7 +399,14 @@ class Modules { $sql_total = "SELECT count(*)"; - $sql = " FROM tagente, tagente_modulo, tagente_estado" . + $sql = " FROM tagente INNER JOIN tagente_modulo + ON tagente_modulo.id_agente = tagente.id_agente + INNER JOIN tagente_estado + ON tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo + LEFT JOIN tagent_secondary_group tasg + ON tagente.id_agente = tasg.id_agent + LEFT JOIN ttag_module + ON ttag_module.id_agente_modulo = tagente_modulo.id_agente_modulo" . $sql_conditions_all; $sql_limit = "ORDER BY tagente.nombre ASC "; From 052d888ac4ced21567b4e5ab5548e0ec7943a769 Mon Sep 17 00:00:00 2001 From: Fermin Date: Mon, 8 Oct 2018 18:53:21 +0200 Subject: [PATCH 35/42] Fixed a minor warning --- pandora_console/godmode/massive/massive_edit_agents.php | 1 + 1 file changed, 1 insertion(+) diff --git a/pandora_console/godmode/massive/massive_edit_agents.php b/pandora_console/godmode/massive/massive_edit_agents.php index f543772648..a6e101403c 100755 --- a/pandora_console/godmode/massive/massive_edit_agents.php +++ b/pandora_console/godmode/massive/massive_edit_agents.php @@ -327,6 +327,7 @@ $agents = agents_get_group_agents (array_keys ($groups)); $modules = db_get_all_rows_sql("SELECT id_agente_modulo as id_module, nombre as name FROM tagente_modulo WHERE id_agente = " . $id_parent); +if ($modules === false) $modules = array(); $modules_values = array(); $modules_values[0] = __('Any'); From 28f9e152e7fc48409f03f15dfc47b138d20017b8 Mon Sep 17 00:00:00 2001 From: fermin831 Date: Tue, 9 Oct 2018 10:56:02 +0200 Subject: [PATCH 36/42] [Tags performance] Fixed tags filter and removed unwanted code --- pandora_console/include/functions_tags.php | 4 +- pandora_console/include/javascript/pandora.js | 52 ------------------- .../operation/agentes/ver_agente.php | 1 - 3 files changed, 3 insertions(+), 54 deletions(-) diff --git a/pandora_console/include/functions_tags.php b/pandora_console/include/functions_tags.php index c2dac8a378..0bdf707646 100644 --- a/pandora_console/include/functions_tags.php +++ b/pandora_console/include/functions_tags.php @@ -2146,7 +2146,9 @@ function tags_get_user_groups_and_tags ($id_user = false, $access = 'AR', $stric $return = array(); foreach ($acls as $acl) { - $return[$acl["id_grupo"]] = implode(",",$acl["tags"][get_acl_column($access)]); + $return[$acl["id_grupo"]] = isset($acl["tags"][get_acl_column($access)]) + ? implode(",",$acl["tags"][get_acl_column($access)]) + : ""; } return $return; diff --git a/pandora_console/include/javascript/pandora.js b/pandora_console/include/javascript/pandora.js index 11157ed3ff..d8ce30714e 100644 --- a/pandora_console/include/javascript/pandora.js +++ b/pandora_console/include/javascript/pandora.js @@ -65,58 +65,6 @@ Array.prototype.in_array = function () { return false; }; -/** - * Fill up select box with id "module" with modules after agent has been selected - * - * @param event that has been triggered - * @param id_agent Agent ID that has been selected - * @param selected Which module(s) have to be selected - */ -function agent_changed (event, id_agent, selected) { - if (id_agent == undefined) - id_agent = this.value; - $('#module').attr ('disabled', 1); - $('#module').empty (); - $('#module').append ($('').html ("Loading...").attr ("value", 0)); - jQuery.post ('ajax.php', - {"page": "operation/agentes/ver_agente", - "get_agent_modules_json": 1, - "id_agent": id_agent - }, - function (data) { - - $('#module').empty (); - - if (typeof($(document).data('text_for_module')) != 'undefined') { - $('#module').append ($('').html ($(document).data('text_for_module')).attr("value", 0).prop('selected', true)); - } - else { - if (typeof(data['any_text']) != 'undefined') { - $('#module').append ($('').html (data['any_text']).attr ("value", 0).prop('selected', true)); - } - else { - var anyText = $("#any_text").html(); //Trick for catch the translate text. - - if (anyText == null) { - anyText = 'Any'; - } - - $('#module').append ($('').html (anyText).attr ("value", 0).prop('selected', true)); - } - } - jQuery.each (data, function (i, val) { - s = js_html_entity_decode (val['nombre']); - $('#module').append ($('').html (s).attr ("value", val['id_agente_modulo'])); - $('#module').fadeIn ('normal'); - }); - if (selected != undefined) - $('#module').attr ('value', selected); - $('#module').removeAttr('disabled'); - }, - "json" - ); -} - /** * Util for check is empty object * diff --git a/pandora_console/operation/agentes/ver_agente.php b/pandora_console/operation/agentes/ver_agente.php index 5b660632d7..042185b5b6 100644 --- a/pandora_console/operation/agentes/ver_agente.php +++ b/pandora_console/operation/agentes/ver_agente.php @@ -720,7 +720,6 @@ if (is_ajax ()) { $id_agent = array_keys( agents_get_group_agents( array_keys (users_get_groups ()), $search, "none")); - // TODO TAGS agents_get_modules $agent_modules = agents_get_modules ($id_agent, $fields, $filter, $indexed, true, false, $tags); } // Restore db connection From ec7c645d1b23c45b0c6ae2240b726bded4091e6a Mon Sep 17 00:00:00 2001 From: fermin831 Date: Tue, 9 Oct 2018 11:45:55 +0200 Subject: [PATCH 37/42] [Tags performance] Fixed problems when there is not using secondary groups --- pandora_console/include/functions_tags.php | 63 +--------------------- 1 file changed, 1 insertion(+), 62 deletions(-) diff --git a/pandora_console/include/functions_tags.php b/pandora_console/include/functions_tags.php index 0bdf707646..da783465c7 100644 --- a/pandora_console/include/functions_tags.php +++ b/pandora_console/include/functions_tags.php @@ -734,7 +734,7 @@ function tags_get_acl_tags_module_condition($acltags, $modules_table = '') { if($has_secondary){ $agent_condition = sprintf('((tagente.id_grupo = %d OR tasg.id_group = %d) %s)',$group_id,$group_id,$tag_join); } else { - $agent_condition = sprintf('((tagente.id_grupo = %d %s)',$group_id,$tag_join); + $agent_condition = sprintf('((tagente.id_grupo = %d %s))',$group_id,$tag_join); } $group_conditions[] = $agent_condition; } else { @@ -757,67 +757,6 @@ function tags_get_acl_tags_module_condition($acltags, $modules_table = '') { return $condition; } -// The old function will be keeped to serve as reference of the changes done -/** - * Transform the acl_groups data into a SQL condition - * - * @param mixed acl_groups data calculated in tags_get_acl_tags function - * - * @return string SQL condition for tagente_module - */ -function tags_get_acl_tags_module_condition_old($acltags, $modules_table = '') { - if (!empty($modules_table)) - $modules_table .= '.'; - - $condition = ''; - $group_conditions = array(); - - // The acltags array contains the groups with the acl propagation applied - // after the changes done into the 'tags_get_user_groups_and_tags' function. - foreach ($acltags as $group_id => $group_tags) { - $tag_join = ''; - if (!empty($group_tags)) { - $tag_join = sprintf('INNER JOIN ttag_module ttmc - ON tamc.id_agente_modulo = ttmc.id_agente_modulo - AND ttmc.id_tag IN (%s)', - is_array($group_tags) ? implode(',', $group_tags) : $group_tags); - } - // FIXME: Not properly way to increse performance - if(enterprise_hook('agents_is_using_secondary_groups')){ - $agent_condition = sprintf('SELECT tamc.id_agente_modulo - FROM tagente_modulo tamc - %s - INNER JOIN tagente tac - ON tamc.id_agente = tac.id_agente - LEFT JOIN tagent_secondary_group tasg - ON tasg.id_agent = tac.id_agente - WHERE (tac.id_grupo = %d OR tasg.id_group = %d)', - $tag_join, $group_id, $group_id); - } - else{ - $agent_condition = sprintf('SELECT tamc.id_agente_modulo - FROM tagente_modulo tamc - %s - INNER JOIN tagente tac - ON tamc.id_agente = tac.id_agente - AND tac.id_grupo = %d', - $tag_join, $group_id); - } - - $sql_condition = sprintf('(%sid_agente_modulo IN (%s))', $modules_table, $agent_condition); - - $group_conditions[] = $sql_condition; - - $i++; - } - - if (!empty($group_conditions)) - $condition = implode(' OR ', $group_conditions); - $condition = !empty($condition) ? "($condition)" : ''; - - return $condition; -} - /** * Transform the acl_groups data into a SQL condition * From 4558c909ef3ae3b482ef4919812676f2fac14b29 Mon Sep 17 00:00:00 2001 From: danielmaya Date: Wed, 10 Oct 2018 16:57:04 +0200 Subject: [PATCH 38/42] Changed source filter in event list --- .../godmode/events/event_edit_filter.php | 3 +-- pandora_console/include/functions_events.php | 24 ------------------- .../operation/events/events.build_query.php | 2 +- .../operation/events/events_list.php | 13 +++++----- 4 files changed, 8 insertions(+), 34 deletions(-) diff --git a/pandora_console/godmode/events/event_edit_filter.php b/pandora_console/godmode/events/event_edit_filter.php index f83d19e14d..8c305fd90f 100644 --- a/pandora_console/godmode/events/event_edit_filter.php +++ b/pandora_console/godmode/events/event_edit_filter.php @@ -399,9 +399,8 @@ if (!is_metaconsole()) { $text_module, false, true, '', array(), true, $id_agent_module); } -$sources = events_get_all_source(); $table ->data[22][0] = '' . __('Source') . ''; -$table ->data[22][1] = html_print_select ($sources, 'source', $source, '', '', '', true); +$table ->data[22][1] = html_print_input_text ('source', $source, '', 35, 255, true); $table ->data[23][0] = '' . __('Extra ID') . ''; $table ->data[23][1] = html_print_input_text ('id_extra', $id_extra, '', 11, 255, true); diff --git a/pandora_console/include/functions_events.php b/pandora_console/include/functions_events.php index 33ca35c24a..39c5fa59ae 100644 --- a/pandora_console/include/functions_events.php +++ b/pandora_console/include/functions_events.php @@ -1531,30 +1531,6 @@ function events_get_all_status ($report = false) { return $fields; } -/** - * Return all event source. - * - * @return array event source array. - */ -function events_get_all_source () { - $event_table = events_get_events_table(is_metaconsole(),false); - $fields = array (); - $fields[''] = __('All'); - - if (users_is_admin()) { - $sources = db_get_all_rows_sql("SELECT DISTINCT(source) FROM ". $event_table); - } else { - $groups_user = users_get_groups ($config['id_user'], "ER", true); - $sources = db_get_all_rows_sql("SELECT DISTINCT(source) FROM ". $event_table. " WHERE id_grupo IN (" .implode(",",array_keys($groups_user)) .")"); - } - - foreach ($sources as $key => $source) { - $fields[$source['source']] = $source['source']; - } - - return $fields; -} - /** * Decode a numeric status into status description. * diff --git a/pandora_console/operation/events/events.build_query.php b/pandora_console/operation/events/events.build_query.php index 79a4a0538a..c06d2ac6c9 100755 --- a/pandora_console/operation/events/events.build_query.php +++ b/pandora_console/operation/events/events.build_query.php @@ -158,7 +158,7 @@ if ($user_comment != '') { } if ($source != '') { - $sql_post .= " AND source LIKE '$source'"; + $sql_post .= " AND source LIKE '%$source%'"; } // In metaconsole mode the agent search is performed by name diff --git a/pandora_console/operation/events/events_list.php b/pandora_console/operation/events/events_list.php index 2add378167..068011f796 100644 --- a/pandora_console/operation/events/events_list.php +++ b/pandora_console/operation/events/events_list.php @@ -666,9 +666,8 @@ $table->data[] = $data; $table->rowclass[] = ''; $data = array(); -$sources = events_get_all_source(); $data[0] = __('Source') . $jump; -$data[0] .= html_print_select ($sources, 'source', $source, '', '', '', true); +$data[0] .= html_print_input_text ('source', $source, '', 35, 255, true); $data[1] = __('Extra ID') . $jump; $data[1] .= html_print_input_text ('id_extra', $id_extra, '', 11, 255, true); $data[2] = __("Comment") . $jump; @@ -975,7 +974,7 @@ $(document).ready( function() { if (i == 'id_group_filter') $("#id_group_filter").val(val); if (i == 'source') - $("#source").val(val); + $("#text-source").val(val); if (i == 'id_extra') $("#text-id_extra").val(val); if (i == 'user_comment') @@ -1018,7 +1017,7 @@ $(document).ready( function() { $("#pagination").val(20); $("#update_from_filter_table").val(1); $("#text_id_agent").val(""); - $("#source").val(''); + $("#text-source").val(''); $("#text-id_extra").val(''); $("#text-user_comment").val(''); @@ -1090,7 +1089,7 @@ $(document).ready( function() { } } if (i == 'source') - $("#source").val(val); + $("#text-source").val(val); if (i == 'id_extra') $("#text-id_extra").val(val); if (i == 'user_comment') @@ -1161,7 +1160,7 @@ $(document).ready( function() { "id_group_filter": $("#id_group_filter").val(), "date_from": $("#text-date_from").val(), "date_to": $("#text-date_to").val(), - "source": $("#source").val(), + "source": $("#text-source").val(), "id_extra": $("#text-id_extra").val(), "user_comment": $("#text-user_comment").val() }, @@ -1261,7 +1260,7 @@ $(document).ready( function() { "id_group_filter": $("#id_group_filter").val(), "date_from": $("#text-date_from").val(), "date_to": $("#text-date_to").val(), - "source": $("#source").val(), + "source": $("#text-source").val(), "id_extra": $("#text-id_extra").val(), "user_comment": $("#text-user_comment").val() }, From de10de03f7bb510a5874b0839e11825c240bc6d6 Mon Sep 17 00:00:00 2001 From: fermin831 Date: Wed, 10 Oct 2018 17:42:33 +0200 Subject: [PATCH 39/42] [Tags performance] Fixed edit and delete massive delete and edit modules in bulk selecting modules first --- .../massive/massive_delete_modules.php | 58 +++---------- pandora_console/include/functions_agents.php | 86 +++++++++++++++++++ pandora_console/include/functions_modules.php | 20 ++--- pandora_console/include/javascript/pandora.js | 2 +- .../operation/agentes/ver_agente.php | 65 +++----------- 5 files changed, 121 insertions(+), 110 deletions(-) diff --git a/pandora_console/godmode/massive/massive_delete_modules.php b/pandora_console/godmode/massive/massive_delete_modules.php index 8e6684c6fc..994b0053ad 100755 --- a/pandora_console/godmode/massive/massive_delete_modules.php +++ b/pandora_console/godmode/massive/massive_delete_modules.php @@ -101,12 +101,7 @@ function process_manage_delete ($module_name, $id_agents, $module_status = 'all' } $count_deleted_modules = count($modules); - if ($config['dbtype'] == "oracle") { - $success = db_process_sql(sprintf("DELETE FROM tagente_modulo WHERE id_agente_modulo IN (%s)", implode(",", $modules))); - } - else { - $success = modules_delete_agent_module ($modules); - } + $success = modules_delete_agent_module ($modules); if (! $success) { ui_print_error_message( @@ -123,8 +118,6 @@ function process_manage_delete ($module_name, $id_agents, $module_status = 'all' } $module_type = (int) get_parameter ('module_type'); -$idGroupMassive = (int) get_parameter('id_group_massive'); -$idAgentMassive = (int) get_parameter('id_agent_massive'); $group_select = get_parameter('groups_select'); $delete = (bool) get_parameter_post ('delete'); @@ -146,9 +139,7 @@ if ($delete) { $agents_ = array(); } - foreach ($agents_select as $agent_name) { - $agents_[] = agents_get_agent_id(io_safe_output($agent_name)); - } + $agents_ = $agents_select; $modules_ = $module_name; break; case 'agents': @@ -231,35 +222,18 @@ $groups = users_get_groups (); $agents = agents_get_group_agents (array_keys (users_get_groups ()), false, "none"); -switch ($config["dbtype"]) { - case "mysql": - $module_types = db_get_all_rows_filter ('tagente_modulo,ttipo_modulo', - array ('tagente_modulo.id_tipo_modulo = ttipo_modulo.id_tipo', - 'id_agente' => array_keys ($agents), - 'disabled' => 0, - 'order' => 'ttipo_modulo.nombre'), - array ('DISTINCT(id_tipo)', - 'CONCAT(ttipo_modulo.descripcion," (",ttipo_modulo.nombre,")") AS description')); - break; - case "oracle": - $module_types = db_get_all_rows_filter ('tagente_modulo,ttipo_modulo', - array ('tagente_modulo.id_tipo_modulo = ttipo_modulo.id_tipo', - 'id_agente' => array_keys ($agents), - 'disabled' => 0, - 'order' => 'ttipo_modulo.nombre'), - array ('ttipo_modulo.id_tipo', - 'ttipo_modulo.descripcion || \' (\' || ttipo_modulo.nombre || \')\' AS description')); - break; - case "postgresql": - $module_types = db_get_all_rows_filter ('tagente_modulo,ttipo_modulo', - array ('tagente_modulo.id_tipo_modulo = ttipo_modulo.id_tipo', - 'id_agente' => array_keys ($agents), - 'disabled' => 0, - 'order' => 'description'), - array ('DISTINCT(id_tipo)', - 'ttipo_modulo.descripcion || \' (\' || ttipo_modulo.nombre || \')\' AS description')); - break; -} +$module_types = db_get_all_rows_filter ( + 'tagente_modulo,ttipo_modulo', + array ( + 'tagente_modulo.id_tipo_modulo = ttipo_modulo.id_tipo', + 'id_agente' => array_keys ($agents), + 'disabled' => 0, + 'order' => 'ttipo_modulo.nombre' + ), array ( + 'DISTINCT(id_tipo)', + 'CONCAT(ttipo_modulo.descripcion," (",ttipo_modulo.nombre,")") AS description' + ) +); if ($module_types === false) $module_types = array (); @@ -275,16 +249,12 @@ $table->data = array (); $table->style[0] = 'font-weight: bold'; $table->style[2] = 'font-weight: bold'; - - $table->data['selection_mode'][0] = __('Selection mode'); $table->data['selection_mode'][1] = ''.__('Select modules first ') . '' . html_print_radio_button_extended ("selection_mode", 'modules', '', $selection_mode, false, '', 'style="margin-right: 40px;"', true).'
'; $table->data['selection_mode'][1] .= ''.__('Select agents first ') . '' . html_print_radio_button_extended ("selection_mode", 'agents', '', $selection_mode, false, '', 'style="margin-right: 40px;"', true); - - $table->rowclass['form_modules_1'] = 'select_modules_row'; $table->data['form_modules_1'][0] = __('Module type'); $table->data['form_modules_1'][0] .= '