From 4babcbe647b638ca1a57303606efbc5adc0c8262 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Tue, 20 Oct 2020 18:25:04 +0200 Subject: [PATCH 1/5] Forced recursion while selecting All group - group_alert_report --- .../reporting/reporting_builder.item_editor.php | 14 ++++++++++++++ pandora_console/include/functions_reporting.php | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/pandora_console/godmode/reporting/reporting_builder.item_editor.php b/pandora_console/godmode/reporting/reporting_builder.item_editor.php index db1303d907..dfdc05c1fc 100755 --- a/pandora_console/godmode/reporting/reporting_builder.item_editor.php +++ b/pandora_console/godmode/reporting/reporting_builder.item_editor.php @@ -3744,6 +3744,19 @@ $(document).ready (function () { $("#combo_group").change ( function () { + + // Alert report group must show all matches when selecting All group + // ignoring 'recursion' option. #6497. + if ($('#type').val() == 'alert_report_group' + && $("#combo_group").val() == 0 + ) { + $('#checkbox-recursion').attr('disabled',true) + $('#checkbox-recursion').attr('checked','checked') + } else { + $('#checkbox-recursion').removeAttr('checked') + $('#checkbox-recursion').removeAttr('disabled') + } + $("#id_agents").html(''); $("#id_agents2").html(''); $("#module").html(''); @@ -3772,6 +3785,7 @@ $(document).ready (function () { ); } ); + $("#combo_group").change(); $("#checkbox-recursion").change ( function () { diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index 0bfe96e864..3c5aa9c66b 100755 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -3912,7 +3912,7 @@ function reporting_alert_report_group($report, $content) $agent_modules = alerts_get_agent_modules( $content['id_group'], - $content['recursion'] + (((string) $content['id_group'] === '0') ? true : $content['recursion']) ); if (empty($alerts)) { From 42cca865acc2bc82e7201a14d1ba5cf5b258160b Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Wed, 21 Oct 2020 11:38:57 +0200 Subject: [PATCH 2/5] groups_get_children and propagate update --- pandora_console/extensions/agents_modules.php | 2 +- .../godmode/agentes/modificar_agente.php | 2 +- .../agentes/planned_downtime.editor.php | 2 +- .../godmode/massive/massive_delete_alerts.php | 2 +- .../godmode/reporting/map_builder.php | 2 +- .../reporting/visual_console_favorite.php | 2 +- .../include/class/CredentialStore.class.php | 2 +- .../include/class/NetworkMap.class.php | 2 +- pandora_console/include/functions_agents.php | 7 +- pandora_console/include/functions_api.php | 2 +- .../include/functions_custom_fields.php | 2 +- pandora_console/include/functions_events.php | 42 ++---- pandora_console/include/functions_groups.php | 120 ++++-------------- .../include/functions_networkmap.php | 2 +- .../include/functions_reporting.php | 2 +- pandora_console/include/functions_tags.php | 12 +- .../operation/agentes/estado_agente.php | 4 +- .../operation/agentes/ver_agente.php | 14 +- .../operation/events/events.build_query.php | 2 +- 19 files changed, 78 insertions(+), 147 deletions(-) diff --git a/pandora_console/extensions/agents_modules.php b/pandora_console/extensions/agents_modules.php index 8aa032c9a8..0a3cc2a382 100644 --- a/pandora_console/extensions/agents_modules.php +++ b/pandora_console/extensions/agents_modules.php @@ -668,7 +668,7 @@ function mainAgentsModules() if ($recursion) { $filter_groups['id_grupo'] = array_merge( $group_id, - groups_get_id_recursive($group_id, true) + groups_get_children_ids($group_id, true) ); } else { $filter_groups['id_grupo'] = $group_id; diff --git a/pandora_console/godmode/agentes/modificar_agente.php b/pandora_console/godmode/agentes/modificar_agente.php index d4036bd68c..8238d1636b 100644 --- a/pandora_console/godmode/agentes/modificar_agente.php +++ b/pandora_console/godmode/agentes/modificar_agente.php @@ -408,7 +408,7 @@ if ($ag_group > 0) { $ag_groups = []; $ag_groups = (array) $ag_group; if ($recursion) { - $ag_groups = groups_get_id_recursive($ag_group, true); + $ag_groups = groups_get_children_ids($ag_group, true); } $user_groups_to_sql = implode(',', $ag_groups); diff --git a/pandora_console/godmode/agentes/planned_downtime.editor.php b/pandora_console/godmode/agentes/planned_downtime.editor.php index b3e7029dbd..4aceac701e 100644 --- a/pandora_console/godmode/agentes/planned_downtime.editor.php +++ b/pandora_console/godmode/agentes/planned_downtime.editor.php @@ -877,7 +877,7 @@ if ($id_downtime > 0) { $filter_cond = ''; if ($filter_group > 0) { if ($recursion) { - $rg = groups_get_id_recursive($filter_group, true); + $rg = groups_get_children_ids($filter_group, true); $filter_cond .= ' AND id_grupo IN ('; $i = 0; diff --git a/pandora_console/godmode/massive/massive_delete_alerts.php b/pandora_console/godmode/massive/massive_delete_alerts.php index c9bcda46ba..c5407ed365 100755 --- a/pandora_console/godmode/massive/massive_delete_alerts.php +++ b/pandora_console/godmode/massive/massive_delete_alerts.php @@ -40,7 +40,7 @@ if (is_ajax()) { $keys_prefix = (string) get_parameter('keys_prefix', ''); if ($recursion) { - $groups = groups_get_id_recursive($id_group, true); + $groups = groups_get_children_ids($id_group, true); } else { $groups = [$id_group]; } diff --git a/pandora_console/godmode/reporting/map_builder.php b/pandora_console/godmode/reporting/map_builder.php index 9f8b8f0162..482b995f8f 100644 --- a/pandora_console/godmode/reporting/map_builder.php +++ b/pandora_console/godmode/reporting/map_builder.php @@ -278,7 +278,7 @@ if ($ag_group > 0) { $ag_groups = []; $ag_groups = (array) $ag_group; if ($recursion) { - $ag_groups = groups_get_id_recursive($ag_group, true); + $ag_groups = groups_get_children_ids($ag_group, true); } } diff --git a/pandora_console/godmode/reporting/visual_console_favorite.php b/pandora_console/godmode/reporting/visual_console_favorite.php index b9f4fe28d7..253218431f 100644 --- a/pandora_console/godmode/reporting/visual_console_favorite.php +++ b/pandora_console/godmode/reporting/visual_console_favorite.php @@ -143,7 +143,7 @@ if (!$own_info['is_admin'] && !check_acl($config['id_user'], 0, 'AW')) { $ag_groups = []; $ag_groups = (array) $ag_group; if ($recursion) { - $ag_groups = groups_get_id_recursive($ag_group, true); + $ag_groups = groups_get_children_ids($ag_group, true); } } else if ($own_info['is_admin']) { $returnAllGroups = 1; diff --git a/pandora_console/include/class/CredentialStore.class.php b/pandora_console/include/class/CredentialStore.class.php index 073f0831a3..d14314a6b4 100644 --- a/pandora_console/include/class/CredentialStore.class.php +++ b/pandora_console/include/class/CredentialStore.class.php @@ -248,7 +248,7 @@ class CredentialStore extends Wizard ); } else { $groups = [ $filter['filter_id_group'] ]; - $childrens = groups_get_childrens($id_group, null, true); + $childrens = groups_get_children($id_group, null, true); if (!empty($childrens)) { foreach ($childrens as $child) { $groups[] = (int) $child['id_grupo']; diff --git a/pandora_console/include/class/NetworkMap.class.php b/pandora_console/include/class/NetworkMap.class.php index a14e2b80c4..0eaea52134 100644 --- a/pandora_console/include/class/NetworkMap.class.php +++ b/pandora_console/include/class/NetworkMap.class.php @@ -810,7 +810,7 @@ class NetworkMap $filter['id_grupo'] = $this->idGroup; } else { // Show current group and children. - $childrens = groups_get_childrens($this->idGroup, null, true); + $childrens = groups_get_children($this->idGroup, null, true); if (!empty($childrens)) { $childrens = array_keys($childrens); diff --git a/pandora_console/include/functions_agents.php b/pandora_console/include/functions_agents.php index beff278dc1..8ba751042c 100644 --- a/pandora_console/include/functions_agents.php +++ b/pandora_console/include/functions_agents.php @@ -1108,11 +1108,14 @@ function agents_get_group_agents( foreach ($id_group as $parent) { $id_group = array_merge( $id_group, - groups_get_id_recursive($parent, false) + groups_get_children_ids($parent, $noACL) ); } } else { - $id_group = groups_get_id_recursive($id_group, false); + $id_group = array_merge( + [$id_group], + groups_get_children_ids($id_group, $noACL) + ); } // Check available groups for target user only if asking for 'All' group. diff --git a/pandora_console/include/functions_api.php b/pandora_console/include/functions_api.php index 6401910faa..863eaf0b3f 100644 --- a/pandora_console/include/functions_api.php +++ b/pandora_console/include/functions_api.php @@ -1973,7 +1973,7 @@ function api_get_all_agents($thrash1, $thrash2, $other, $returnType) $ag_groups = $other['data'][1]; // Recursion. if ($other['data'][6] === '1') { - $ag_groups = groups_get_id_recursive($ag_groups, true); + $ag_groups = groups_get_children_ids($ag_groups, true); } $ag_groups = implode(',', (array) $ag_groups); diff --git a/pandora_console/include/functions_custom_fields.php b/pandora_console/include/functions_custom_fields.php index d1f661e874..c15b0cae95 100644 --- a/pandora_console/include/functions_custom_fields.php +++ b/pandora_console/include/functions_custom_fields.php @@ -367,7 +367,7 @@ function agent_counters_custom_fields($filters) if ($filters['group']) { // Recursion check acl. if ($filters['recursion']) { - $recursion_groups = groups_get_id_recursive($filters['group'], true); + $recursion_groups = groups_get_children_ids($filters['group'], true); if (!users_can_manage_group_all('AR')) { if (isset($user_groups) && is_array($user_groups)) { $groups_intersect = array_intersect($user_groups, $recursion_groups); diff --git a/pandora_console/include/functions_events.php b/pandora_console/include/functions_events.php index 7a337fbdab..cf486b8acf 100644 --- a/pandora_console/include/functions_events.php +++ b/pandora_console/include/functions_events.php @@ -871,37 +871,23 @@ function events_get_all( } $groups = $filter['id_group_filter']; - if (isset($groups) && $groups > 0) { - $propagate = db_get_value( - 'propagate', - 'tgrupo', - 'id_grupo', - $groups - ); + if (isset($groups) === true && $groups > 0) { + $children = groups_get_children($groups); - if (!$propagate && isset($groups)) { - $sql_filters[] = sprintf( - ' AND (te.id_grupo = %d OR tasg.id_group = %d)', - $groups, - $groups - ); - } else { - $children = groups_get_children($groups); - $_groups = [ $groups ]; - if (!empty($children)) { - foreach ($children as $child) { - $_groups[] = (int) $child['id_grupo']; - } + $_groups = [ $groups ]; + if (empty($children) === false) { + foreach ($children as $child) { + $_groups[] = (int) $child['id_grupo']; } - - $groups = $_groups; - - $sql_filters[] = sprintf( - ' AND (te.id_grupo IN (%s) OR tasg.id_group IN (%s))', - join(',', $groups), - join(',', $groups) - ); } + + $groups = $_groups; + + $sql_filters[] = sprintf( + ' AND (te.id_grupo IN (%s) OR tasg.id_group IN (%s))', + join(',', $groups), + join(',', $groups) + ); } // Skip system messages if user is not PM. diff --git a/pandora_console/include/functions_groups.php b/pandora_console/include/functions_groups.php index b6c1a5e6c9..7b733b9c8d 100644 --- a/pandora_console/include/functions_groups.php +++ b/pandora_console/include/functions_groups.php @@ -265,49 +265,21 @@ function groups_check_used($idGroup) } -/** - * Return a array of id_group of childrens (to branches down) - * - * @param integer $parent The id_group parent to search the childrens. - * @param array $groups The groups, its for optimize the querys to DB. - */ -function groups_get_childrens_ids($parent, $groups=null) -{ - if (empty($groups)) { - $groups = db_get_all_rows_in_table('tgrupo'); - } - - $return = ''; - - foreach ($groups as $key => $group) { - if ($group['id_grupo'] == 0) { - continue; - } - - if ($group['parent'] == $parent) { - $return .= $group['id_grupo'].','; - $propagate = db_get_value('propagate', 'tgrupo', 'id_grupo', $group['id_grupo']); - if ($propagate) { - $return .= groups_get_childrens_ids($group['id_grupo']); - } - } - } - - return $return; -} - - /** * Return a array of id_group of children of given parent. * * @param integer $parent The id_grupo parent to search its children. * @param array $ignorePropagate Ignore propagate. + * @param string $privilege Default privilege. + * + * @return array Of Groups, children of $parent. */ -function groups_get_children($parent, $ignorePropagate=false) +function groups_get_children($parent, $ignorePropagate=false, $privilege='AR') { static $groups; + static $user_groups; - if (empty($groups)) { + if (empty($groups) === true) { $aux_groups = []; $groups = db_get_all_rows_in_table('tgrupo'); foreach ($groups as $key => $value) { @@ -317,13 +289,29 @@ function groups_get_children($parent, $ignorePropagate=false) $groups = $aux_groups; } + if (empty($user_groups) === true) { + $user_groups = users_get_groups(false, $privilege, true); + } + + // Admin see always all groups. + $ignorePropagate = users_is_admin() || $ignorePropagate; + $return = []; foreach ($groups as $key => $g) { if ($g['id_grupo'] == 0) { continue; } - if ($ignorePropagate || $parent == 0 || $groups[$parent]['propagate']) { + // IgnorePropagate will be true if user can access child. + $allowed = $ignorePropagate || array_key_exists( + $g['id_grupo'], + $user_groups + ); + + if ($allowed === true + || (int) $parent === 0 + || (bool) $groups[$parent]['propagate'] === true + ) { if ($g['parent'] == $parent) { $return += [$g['id_grupo'] => $g]; if ($g['propagate'] || $ignorePropagate) { @@ -340,38 +328,6 @@ function groups_get_children($parent, $ignorePropagate=false) } -/** - * @deprecated This is not working. Expects 'propagate' on CHILD not on PARENT!!! - * - * Return a array of id_group of childrens (to branches down) - * - * @param integer $parent The id_group parent to search the childrens. - * @param array $groups The groups, its for optimize the querys to DB. - */ -function groups_get_childrens($parent, $groups=null, $onlyPropagate=false) -{ - if (empty($groups)) { - $groups = db_get_all_rows_in_table('tgrupo'); - } - - $return = []; - - foreach ($groups as $key => $group) { - if ($group['id_grupo'] == 0) { - continue; - } - - if ($group['propagate'] || $onlyPropagate) { - if ($group['parent'] == $parent) { - $return = ($return + [$group['id_grupo'] => $group] + groups_get_childrens($group['id_grupo'], $groups, $onlyPropagate)); - } - } - } - - return $return; -} - - /** * Return a array of id_group of parents (to roots up). * @@ -541,35 +497,11 @@ function groups_get_all($groupWithAgents=false) * * @return array with all result groups */ -function groups_get_id_recursive($id_parent, $all=false) +function groups_get_children_ids($id_parent, $all=false) { - $return = []; + $return = groups_get_children($id_parent, $all); - $return = array_merge($return, [$id_parent]); - - // Check propagate - $propagate = db_get_value_filter('propagate', 'tgrupo', ['id_grupo' => $id_parent]); - - if (($propagate == 1) || $all) { - $children = db_get_all_rows_filter('tgrupo', ['parent' => $id_parent, 'disabled' => 0], ['id_grupo']); - - if ($children === false) { - $children = []; - } else { - $temp = []; - foreach ($children as $id_children) { - $temp = array_merge($temp, [$id_children['id_grupo']]); - } - - $children = $temp; - } - - foreach ($children as $id_children) { - $return = array_merge($return, groups_get_id_recursive($id_children, $all)); - } - } - - return $return; + return array_keys($return); } diff --git a/pandora_console/include/functions_networkmap.php b/pandora_console/include/functions_networkmap.php index 56172331c6..bd5152576d 100644 --- a/pandora_console/include/functions_networkmap.php +++ b/pandora_console/include/functions_networkmap.php @@ -319,7 +319,7 @@ function networkmap_generate_dot( if ($dont_show_subgroups) { $filter['id_grupo'] = $group; } else { - $childrens = groups_get_childrens($group, null, true); + $childrens = groups_get_children($group, null, true); if (!empty($childrens)) { $childrens = array_keys($childrens); diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index 0bfe96e864..c480969f16 100755 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -9072,7 +9072,7 @@ function reporting_get_group_stats($id_group=0, $access='AR') $covered_groups = []; $group_array = []; foreach ($id_group as $group) { - $children = groups_get_childrens($group); + $children = groups_get_children($group); // Show empty groups only if they have children with agents // $group_array = array(); diff --git a/pandora_console/include/functions_tags.php b/pandora_console/include/functions_tags.php index 5aace86006..fe36bc34fa 100644 --- a/pandora_console/include/functions_tags.php +++ b/pandora_console/include/functions_tags.php @@ -941,7 +941,7 @@ function tags_get_acl_tags_event_condition( } // 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 = sprintf('id_grupo IN (%s)', implode(',', array_values(groups_get_children_ids($group_id, true))));. $group_condition = '('.$id_grupo_table_pretag.'id_grupo = '.$group_id.' OR '.$alt_id_grupo_table_pretag.'id_group = '.$group_id.')'; // Tags condition (The module has at least one of the restricted tags). @@ -1350,7 +1350,7 @@ function tags_checks_event_acl($id_user, $id_group, $access, $tags=[], $children foreach ($user_tags as $user_tag) { $tags_user = $user_tag['tags']; $id_group_user = $user_tag['id_grupo']; - $childrens = groups_get_childrens($id_group_user, null, true); + $childrens = groups_get_children($id_group_user, null, true); if (empty($childrens)) { $group_ids = $id_group_user; @@ -1421,7 +1421,7 @@ function tags_get_agents_counter($id_tag, $groups_and_tags=[], $agent_filter=[], $tags_arr = explode(',', $tags); foreach ($tags_arr as $tag) { if ($tag == $id_tag) { - $hierarchy_groups = groups_get_id_recursive($group_id); + $hierarchy_groups = groups_get_children_ids($group_id); $groups_id = array_merge($groups_id, $hierarchy_groups); } } @@ -1923,7 +1923,7 @@ function tags_get_monitors_counter($id_tag, $groups_and_tags=[], $agent_filter=[ $tags_arr = explode(',', $tags); foreach ($tags_arr as $tag) { if ($tag == $id_tag) { - $hierarchy_groups = groups_get_id_recursive($group_id); + $hierarchy_groups = groups_get_children_ids($group_id); $groups_id = array_merge($groups_id, $hierarchy_groups); } } @@ -2219,7 +2219,7 @@ function tags_monitors_fired_alerts($id_tag, $groups_and_tags=[], $id_agente=fal $tags_arr = explode(',', $tags); foreach ($tags_arr as $tag) { if ($tag == $id_tag) { - $hierarchy_groups = groups_get_id_recursive($group_id); + $hierarchy_groups = groups_get_children_ids($group_id); $groups_id = array_merge($groups_id, $hierarchy_groups); } } @@ -2283,7 +2283,7 @@ function tags_get_monitors_alerts($id_tag, $groups_and_tags=[], $id_agente=false $tags_arr = explode(',', $tags); foreach ($tags_arr as $tag) { if ($tag == $id_tag) { - $hierarchy_groups = groups_get_id_recursive($group_id); + $hierarchy_groups = groups_get_children_ids($group_id); $groups_id = array_merge($groups_id, $hierarchy_groups); } } diff --git a/pandora_console/operation/agentes/estado_agente.php b/pandora_console/operation/agentes/estado_agente.php index c0e6d147c5..8144ea524a 100644 --- a/pandora_console/operation/agentes/estado_agente.php +++ b/pandora_console/operation/agentes/estado_agente.php @@ -546,7 +546,7 @@ if (!empty($search_custom)) { if ($group_id > 0) { $groups = [$group_id]; if ($recursion) { - $groups = groups_get_id_recursive($group_id, true); + $groups = groups_get_children_ids($group_id, true); } } else { $groups = []; @@ -576,7 +576,7 @@ if ($strict_user) { if ($group_id > 0) { $groups = [$group_id]; if ($recursion) { - $groups = groups_get_id_recursive($group_id, true); + $groups = groups_get_children_ids($group_id, true); } $filter['id_group'] = implode(',', $groups); diff --git a/pandora_console/operation/agentes/ver_agente.php b/pandora_console/operation/agentes/ver_agente.php index e86960938a..eb4a5186bf 100644 --- a/pandora_console/operation/agentes/ver_agente.php +++ b/pandora_console/operation/agentes/ver_agente.php @@ -146,14 +146,24 @@ if (is_ajax()) { // Perform search. $agents = agents_get_group_agents( + // Id_group. $id_group, + // Search. $filter, + // Case. 'lower', - false, + // NoACL. + true, + // ChildGroups. $recursion, + // Serialized. false, + // Separator. '|', - $cluster_mode + // Add_alert_bulk_op. + $cluster_mode, + // Force_serialized. + false ); if (empty($agents)) { diff --git a/pandora_console/operation/events/events.build_query.php b/pandora_console/operation/events/events.build_query.php index b1b4051e7f..0f68cbfb5f 100755 --- a/pandora_console/operation/events/events.build_query.php +++ b/pandora_console/operation/events/events.build_query.php @@ -28,7 +28,7 @@ if ($id_group > 0) { if ($propagate) { $childrens_ids = [$id_group]; - $childrens = groups_get_childrens($id_group, null, true); + $childrens = groups_get_children($id_group, null, true); if (!empty($childrens)) { foreach ($childrens as $child) { From 6b25ae60044827fc5d40399f1b91d62a34d9fa3b Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Wed, 21 Oct 2020 13:23:17 +0200 Subject: [PATCH 3/5] improved agent_module report (CSV) --- pandora_console/include/functions.php | 67 +++++++++++++++++++ pandora_console/include/functions_agents.php | 19 +++--- .../operation/agentes/ver_agente.php | 2 +- 3 files changed, 78 insertions(+), 10 deletions(-) diff --git a/pandora_console/include/functions.php b/pandora_console/include/functions.php index 0147168ebf..b14ad3e7b2 100644 --- a/pandora_console/include/functions.php +++ b/pandora_console/include/functions.php @@ -1342,6 +1342,73 @@ function get_priority_name($priority) } +/** + * Translates status into string. + * + * @param integer $status Agent status. + * + * @return string Translation. + */ +function get_agent_status_string($status) +{ + switch ($status) { + case AGENT_STATUS_CRITICAL: + return __('CRITICAL'); + + case AGENT_STATUS_WARNING: + return __('WARNING'); + + case AGENT_STATUS_ALERT_FIRED: + return __('ALERT FIRED'); + + case AGENT_STATUS_NOT_INIT: + return __('NO DATA'); + + case AGENT_STATUS_NORMAL: + return __('NORMAL'); + + case AGENT_STATUS_UNKNOWN: + default: + return __('UNKNOWN'); + } +} + + +/** + * Translates status into string. + * + * @param integer $status Module status. + * + * @return string Translation. + */ +function get_module_status_string($status) +{ + switch ($status) { + case AGENT_MODULE_STATUS_CRITICAL_BAD: + return __('CRITICAL'); + + case AGENT_MODULE_STATUS_WARNING_ALERT: + case AGENT_MODULE_STATUS_CRITICAL_ALERT: + return __('ALERT FIRED'); + + case AGENT_MODULE_STATUS_WARNING: + return __('WARNING'); + + case AGENT_MODULE_STATUS_UNKNOWN: + return __('UNKNOWN'); + + case AGENT_MODULE_STATUS_NO_DATA: + case AGENT_MODULE_STATUS_NOT_INIT: + return __('NO DATA'); + + case AGENT_MODULE_STATUS_NORMAL_ALERT: + case AGENT_MODULE_STATUS_NORMAL: + default: + return __('NORMAL'); + } +} + + /** * Get priority class (CSS class) from priority value. * diff --git a/pandora_console/include/functions_agents.php b/pandora_console/include/functions_agents.php index 8ba751042c..8bad693c3d 100644 --- a/pandora_console/include/functions_agents.php +++ b/pandora_console/include/functions_agents.php @@ -19,17 +19,18 @@ require_once $config['homedir'].'/include/functions.php'; require_once $config['homedir'].'/include/functions_modules.php'; -require_once $config['homedir'].'/include/functions_users.php';/** - * Return the agent if exists in the DB. - * - * @param integer $id_agent The agent id. - * @param boolean $show_disabled Show the agent found althought it is disabled. By default false. - * @param boolean $force_meta - * - * @return boolean The result to check if the agent is in the DB. - */ +require_once $config['homedir'].'/include/functions_users.php'; +/** + * Return the agent if exists in the DB. + * + * @param integer $id_agent The agent id. + * @param boolean $show_disabled Show the agent found althought it is disabled. By default false. + * @param boolean $force_meta + * + * @return boolean The result to check if the agent is in the DB. + */ function agents_get_agent($id_agent, $show_disabled=true, $force_meta=false) { $agent = db_get_row_filter( diff --git a/pandora_console/operation/agentes/ver_agente.php b/pandora_console/operation/agentes/ver_agente.php index eb4a5186bf..df5146711c 100644 --- a/pandora_console/operation/agentes/ver_agente.php +++ b/pandora_console/operation/agentes/ver_agente.php @@ -88,7 +88,7 @@ if (is_ajax()) { if ($get_agents_group_json) { $id_group = (int) get_parameter('id_group'); - $recursion = (bool) get_parameter('recursion'); + $recursion = (get_parameter_switch('recursion', 'false') === 'true'); $id_os = get_parameter('id_os', ''); $agent_name = get_parameter('name', ''); From 6112b3e932e300d3b25ab2c1ae1a29181037ba30 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Thu, 29 Oct 2020 10:55:07 +0100 Subject: [PATCH 4/5] minor fix --- .../godmode/reporting/reporting_builder.item_editor.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/pandora_console/godmode/reporting/reporting_builder.item_editor.php b/pandora_console/godmode/reporting/reporting_builder.item_editor.php index dfdc05c1fc..814e9f1ec4 100755 --- a/pandora_console/godmode/reporting/reporting_builder.item_editor.php +++ b/pandora_console/godmode/reporting/reporting_builder.item_editor.php @@ -3747,13 +3747,10 @@ $(document).ready (function () { // Alert report group must show all matches when selecting All group // ignoring 'recursion' option. #6497. - if ($('#type').val() == 'alert_report_group' - && $("#combo_group").val() == 0 - ) { + if ($("#combo_group").val() == 0) { $('#checkbox-recursion').attr('disabled',true) $('#checkbox-recursion').attr('checked','checked') } else { - $('#checkbox-recursion').removeAttr('checked') $('#checkbox-recursion').removeAttr('disabled') } From 3e1a89dab782522cfd1df638ac88c5a98a61b2f6 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Thu, 29 Oct 2020 11:21:56 +0100 Subject: [PATCH 5/5] groups_get_cChildren --- pandora_console/include/functions_groups.php | 49 +++++++++++++++----- 1 file changed, 38 insertions(+), 11 deletions(-) diff --git a/pandora_console/include/functions_groups.php b/pandora_console/include/functions_groups.php index 7b733b9c8d..3248eadb31 100644 --- a/pandora_console/include/functions_groups.php +++ b/pandora_console/include/functions_groups.php @@ -266,16 +266,21 @@ function groups_check_used($idGroup) /** - * Return a array of id_group of children of given parent. + * Return a array of id_group of children of given parent INCLUDING PARENT!!. * * @param integer $parent The id_grupo parent to search its children. * @param array $ignorePropagate Ignore propagate. * @param string $privilege Default privilege. + * @param boolean $selfInclude Include group "id_parent" in return. * * @return array Of Groups, children of $parent. */ -function groups_get_children($parent, $ignorePropagate=false, $privilege='AR') -{ +function groups_get_children( + $parent, + $ignorePropagate=false, + $privilege='AR', + $selfInclude=true +) { static $groups; static $user_groups; @@ -296,7 +301,15 @@ function groups_get_children($parent, $ignorePropagate=false, $privilege='AR') // Admin see always all groups. $ignorePropagate = users_is_admin() || $ignorePropagate; + // Prepare array. $return = []; + + if ($selfInclude === true) { + if (array_key_exists($parent, $user_groups) === true) { + $return[$parent] = $groups[$parent]; + } + } + foreach ($groups as $key => $g) { if ($g['id_grupo'] == 0) { continue; @@ -317,7 +330,9 @@ function groups_get_children($parent, $ignorePropagate=false, $privilege='AR') if ($g['propagate'] || $ignorePropagate) { $return += groups_get_children( $g['id_grupo'], - $ignorePropagate + $ignorePropagate, + $privilege, + $selfInclude ); } } @@ -490,16 +505,28 @@ function groups_get_all($groupWithAgents=false) /** - * Get all groups recursive from an initial group. + * Get all groups recursive from an initial group INCLUDING PARENT!!. * - * @param int Id of the parent group - * @param bool Whether to force recursive search ignoring propagation (true) or not (false) + * @param integer $id_parent Id of the parent group. + * @param boolean $ignorePropagate Whether to force recursive search ignoring + * propagation (true) or not (false). + * @param boolean $selfInclude Include group "id_parent" in return. + * @param string $privilege Privilege flag to search for default 'AR'. * - * @return array with all result groups + * @return array With all result groups. */ -function groups_get_children_ids($id_parent, $all=false) -{ - $return = groups_get_children($id_parent, $all); +function groups_get_children_ids( + $id_parent, + $ignorePropagate=false, + $selfInclude=true, + $privilege='AR' +) { + $return = groups_get_children( + $id_parent, + $ignorePropagate, + $privilege, + $selfInclude + ); return array_keys($return); }