From 84b6f70df4e8b1e0d91e45aee097c6ba77175540 Mon Sep 17 00:00:00 2001 From: Alejandro Gallardo Escobar Date: Wed, 14 Jan 2015 17:53:22 +0100 Subject: [PATCH] Fixed an error on the function "group_get_data" --- pandora_console/include/functions_groups.php | 78 ++++++++++---------- 1 file changed, 41 insertions(+), 37 deletions(-) diff --git a/pandora_console/include/functions_groups.php b/pandora_console/include/functions_groups.php index dfcfecf236..ab2e190ce6 100644 --- a/pandora_console/include/functions_groups.php +++ b/pandora_console/include/functions_groups.php @@ -1840,9 +1840,10 @@ function group_get_data ($id_user = false, $user_strict = false, $acltags, $retu if ($id_user == false) { $id_user = $config['id_user']; } - + $user_groups = array(); $user_tags = array(); + $groups_without_tags = array(); foreach ($acltags as $group => $tags) { if ($user_strict) { //Remove groups with tags if ($tags == '') { @@ -1864,34 +1865,31 @@ function group_get_data ($id_user = false, $user_strict = false, $acltags, $retu } else { $user_groups_ids = implode(',',array_keys($acltags)); } - - if ($user_groups_ids == '') { - $user_groups_ids == -1; - } - switch ($config["dbtype"]) { - case "mysql": - $list_groups = db_get_all_rows_sql(" - SELECT * - FROM tgrupo - WHERE id_grupo IN (" . $user_groups_ids . ") - ORDER BY nombre COLLATE utf8_general_ci ASC"); - - break; - case "postgresql": - $list_groups = db_get_all_rows_sql(" - SELECT * - FROM tgrupo - WHERE id_grupo IN (" . $user_groups_ids . ") - ORDER BY nombre ASC"); - break; - case "oracle": - $list_groups = db_get_all_rows_sql(" - SELECT * - FROM tgrupo - WHERE id_grupo IN (" . $user_groups_ids . ") - ORDER BY nombre COLLATE utf8_general_ci ASC"); - break; + if (!empty($user_groups_ids)) { + switch ($config["dbtype"]) { + case "mysql": + $list_groups = db_get_all_rows_sql(" + SELECT * + FROM tgrupo + WHERE id_grupo IN (" . $user_groups_ids . ") + ORDER BY nombre COLLATE utf8_general_ci ASC"); + break; + case "postgresql": + $list_groups = db_get_all_rows_sql(" + SELECT * + FROM tgrupo + WHERE id_grupo IN (" . $user_groups_ids . ") + ORDER BY nombre ASC"); + break; + case "oracle": + $list_groups = db_get_all_rows_sql(" + SELECT * + FROM tgrupo + WHERE id_grupo IN (" . $user_groups_ids . ") + ORDER BY nombre COLLATE utf8_general_ci ASC"); + break; + } } if ($list_groups == false) { @@ -1919,11 +1917,14 @@ function group_get_data ($id_user = false, $user_strict = false, $acltags, $retu $list[$i]['_name_'] = $item['nombre']; $list[$i]['_iconImg_'] = html_print_image ("images/groups_small/" . groups_get_icon($item['id_grupo']).".png", true, array ("style" => 'vertical-align: middle;')); + if ($mode == 'tree' && !empty($item['parent'])) + $list[$i]['_parent_id_'] = $item['parent']; + $list[$i]['_agents_unknown_'] = $group_stat[0]["unknown"]; $list[$i]['_monitors_alerts_fired_'] = $group_stat[0]["alerts_fired"]; $list[$i]['_total_agents_'] = $group_stat[0]["agents"]; - if ($mode == 'tactical') { + if ($mode == 'tactical' || $mode == 'tree') { $list[$i]['_agents_ok_'] = $group_stat[0]["normal"]; $list[$i]['_agents_warning_'] = $group_stat[0]["warning"]; $list[$i]['_agents_critical_'] = $group_stat[0]["critical"]; @@ -1949,7 +1950,7 @@ function group_get_data ($id_user = false, $user_strict = false, $acltags, $retu $list[0]['_monitors_not_init_'] += $list[$i]['_monitors_not_init_']; $list[0]['_agents_not_init'] += $list[$i]['_agents_not_init']; - if ($mode == 'tactical') { + if ($mode == 'tactical' || $mode == 'tree') { $list[0]['_agents_ok_'] += $group_stat[0]["normal"]; $list[0]['_agents_warning_'] += $group_stat[0]["warning"]; $list[0]['_agents_critical_'] += $group_stat[0]["critical"]; @@ -1957,7 +1958,7 @@ function group_get_data ($id_user = false, $user_strict = false, $acltags, $retu } } - if ($mode == 'group') { + if ($mode == 'group' || $mode == 'tree') { if (! defined ('METACONSOLE')) { if (($list[$i]['_agents_unknown_'] == 0) && ($list[$i]['_monitors_alerts_fired_'] == 0) && ($list[$i]['_total_agents_'] == 0) && ($list[$i]['_monitors_ok_'] == 0) && ($list[$i]['_monitors_critical_'] == 0) && ($list[$i]['_monitors_warning_'] == 0) && ($list[$i]['_monitors_unknown_'] == 0) && ($list[$i]['_monitors_not_init_'] == 0) && ($list[$i]['_agents_not_init_'] == 0)) { unset($list[$i]); @@ -1974,6 +1975,9 @@ function group_get_data ($id_user = false, $user_strict = false, $acltags, $retu $list[$i]['_name_'] = $item['nombre']; $list[$i]['_iconImg_'] = html_print_image ("images/groups_small/" . groups_get_icon($item['id_grupo']).".png", true, array ("style" => 'vertical-align: middle;')); + if ($mode == 'tree' && !empty($item['parent'])) + $list[$i]['_parent_id_'] = $item['parent']; + $list[$i]['_monitors_ok_'] = groups_monitor_ok($id, $user_strict, $id); $list[$i]['_monitors_critical_'] = groups_monitor_critical($id, $user_strict, $id); $list[$i]['_monitors_warning_'] = groups_monitor_warning($id, $user_strict, $id); @@ -1984,7 +1988,7 @@ function group_get_data ($id_user = false, $user_strict = false, $acltags, $retu $list[$i]['_monitors_not_init_'] = groups_monitor_not_init($id, $user_strict, $id); $list[$i]['_agents_not_init_'] = groups_agent_not_init ($id, $user_strict, $id); - if ($mode == 'tactical') { + if ($mode == 'tactical' || $mode == 'tree') { $list[$i]['_agents_ok_'] = groups_agent_ok ($id, $user_strict, $id); $list[$i]['_agents_warning_'] = groups_agent_warning ($id, $user_strict, $id); $list[$i]['_agents_critical_'] = groups_agent_critical ($id, $user_strict, $id); @@ -2002,7 +2006,7 @@ function group_get_data ($id_user = false, $user_strict = false, $acltags, $retu $list[0]['_monitors_not_init_'] = $list[$i]['_monitors_not_init_']; $list[0]['_agents_not_init_'] += $list[$i]['_agents_not_init']; - if ($mode == 'tactical') { + if ($mode == 'tactical' || $mode == 'tree') { $list[0]['_agents_ok_'] += $list[$i]['_agents_ok_']; $list[0]['_agents_warning_'] += $list[$i]['_agents_warning_']; $list[0]['_agents_critical_'] += $list[$i]['_agents_critical_']; @@ -2010,7 +2014,7 @@ function group_get_data ($id_user = false, $user_strict = false, $acltags, $retu } } - if ($mode == 'group') { + if ($mode == 'group' || $mode == 'tree') { if (! defined ('METACONSOLE')) { if (($list[$i]['_agents_unknown_'] == 0) && ($list[$i]['_monitors_alerts_fired_'] == 0) && ($list[$i]['_total_agents_'] == 0) && ($list[$i]['_monitors_ok_'] == 0) && ($list[$i]['_monitors_critical_'] == 0) && ($list[$i]['_monitors_warning_'] == 0) && ($list[$i]['_monitors_unknown_'] == 0) && ($list[$i]['_monitors_not_init_'] == 0) && ($list[$i]['_agents_not_init_'] == 0)) { unset($list[$i]); @@ -2041,7 +2045,7 @@ function group_get_data ($id_user = false, $user_strict = false, $acltags, $retu $list[$i]['_monitors_warning_'] = tags_monitors_warning ($id, $acltags); $list[$i]['_monitors_alerts_fired_'] = tags_monitors_fired_alerts($id, $acltags); - if ($mode == 'tactical') { + if ($mode == 'tactical' || $mode == 'tree') { $list[$i]['_agents_ok_'] = tags_agent_ok ($id, $acltags); $list[$i]['_agents_warning_'] = tags_agent_warning ($id, $acltags); $list[$i]['_agents_critical_'] = tags_get_critical_agents ($id, $acltags); @@ -2059,7 +2063,7 @@ function group_get_data ($id_user = false, $user_strict = false, $acltags, $retu $list[0]['_monitors_unknown_'] += $list[$i]['_monitors_unknown_']; $list[0]['_monitors_not_init_'] = $list[$i]['_monitors_not_init_']; - if ($mode == 'tactical') { + if ($mode == 'tactical' || $mode == 'tree') { $list[0]['_agents_ok_'] += $list[$i]['_agents_ok_']; $list[0]['_agents_warning_'] += $list[$i]['_agents_warning_']; $list[0]['_agents_critical_'] += $list[$i]['_agents_critical_']; @@ -2067,7 +2071,7 @@ function group_get_data ($id_user = false, $user_strict = false, $acltags, $retu } } - if ($mode == 'group') { + if ($mode == 'group' || $mode == 'tree') { if (! defined ('METACONSOLE')) { if (($list[$i]['_agents_unknown_'] == 0) && ($list[$i]['_monitors_alerts_fired_'] == 0) && ($list[$i]['_total_agents_'] == 0) && ($list[$i]['_monitors_ok_'] == 0) && ($list[$i]['_monitors_critical_'] == 0) && ($list[$i]['_monitors_warning_'] == 0) && ($list[$i]['_monitors_unknown_'] == 0) && ($list[$i]['_monitors_not_init_'] == 0) && ($list[$i]['_agents_not_init_'] == 0)) { unset($list[$i]);