diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index 0957d018ea..10fc05b9ff 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,11 @@ +2012-06-07 Dario Rodriguez + + * operation/tree.php, + include/functions_groups.php: Fixed some errors and + improved performance of group tree view. + + MERGED FROM 4.0.2 + 2012-06-06 Juan Manuel Ramon * operation/agentes/ver_agente.php diff --git a/pandora_console/include/functions_groups.php b/pandora_console/include/functions_groups.php index 3fbad32721..b9557d6519 100644 --- a/pandora_console/include/functions_groups.php +++ b/pandora_console/include/functions_groups.php @@ -841,14 +841,12 @@ function groups_create_group($group_name, $rest_values){ // Get unknown agents by using the status code in modules. function groups_agent_unknown ($group_array) { - - // If there are not groups to query, we jump to nextone if (empty ($group_array)) { return 0; } else if (!is_array ($group_array)){ - $group_array[0] = $group_array; + $group_array = array($group_array); } $group_clause = implode (",", $group_array); @@ -858,6 +856,81 @@ function groups_agent_unknown ($group_array) { } +// Get ok agents by using the status code in modules. + +function groups_agent_ok ($group_array) { + + if (empty ($group_array)) { + return 0; + + } else if (!is_array ($group_array)){ + $group_array = array($group_array); + } + + $group_clause = implode (",", $group_array); + $group_clause = "(" . $group_clause . ")"; + + //!!!Query explanation!!! + //An agent is OK if all its modules are OK + //The status values are: 0 OK; 1 Critical; 2 Warning; 3 Unkown + //This query grouped all modules by agents and select the MAX value for status which has the value 0 + //If MAX(estado) is 0 it means all modules has status 0 => OK + //Then we count the agents of the group selected to know how many agents are in OK status + + return db_get_sql ("SELECT COUNT(max_estado) FROM (SELECT MAX(tagente_estado.estado) as max_estado FROM tagente_estado, tagente, tagente_modulo WHERE tagente.disabled = 0 AND tagente_estado.utimestamp != 0 AND tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo AND tagente_modulo.disabled = 0 AND tagente_estado.id_agente = tagente.id_agente AND tagente.id_grupo IN $group_clause GROUP BY tagente.id_agente HAVING max_estado = 0) AS S1"); + +} + +// Get critical agents by using the status code in modules. + +function groups_agent_critical ($group_array) { + + if (empty ($group_array)) { + return 0; + + } else if (!is_array ($group_array)){ + $group_array = array($group_array); + } + + $group_clause = implode (",", $group_array); + $group_clause = "(" . $group_clause . ")"; + + //!!!Query explanation!!! + //An agent is Warning when has at least one module in warning status and nothing more in critical status + //The status values are: 0 OK; 1 Critical; 2 Warning; 3 Unkown + //If estado = 1 it means at leas 1 module is in critical status so the agent is critical + //Then we count the agents of the group selected to know how many agents are in critical status + + return db_get_sql ("SELECT COUNT( DISTINCT tagente_estado.id_agente) FROM tagente_estado, tagente, tagente_modulo WHERE tagente.disabled = 0 AND tagente_estado.utimestamp != 0 AND tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo AND tagente_modulo.disabled = 0 AND estado = 1 AND tagente_estado.id_agente = tagente.id_agente AND tagente.id_grupo IN $group_clause"); + +} + +// Get warning agents by using the status code in modules. + +function groups_agent_warning ($group_array) { + + if (empty ($group_array)) { + return 0; + + } else if (!is_array ($group_array)){ + $group_array = array($group_array); + } + + $group_clause = implode (",", $group_array); + $group_clause = "(" . $group_clause . ")"; + + //!!!Query explanation!!! + //An agent is Warning when has at least one module in warning status and nothing more in critical status + //The status values are: 0 OK; 1 Critical; 2 Warning; 3 Unkown + //This query grouped all modules by agents and select the MIN value for status which has the value 0 + //If MIN(estado) is 2 it means at least one module is warning and there is no critical modules + //Then we count the agents of the group selected to know how many agents are in warning status + + return db_get_sql ("SELECT COUNT(min_estado) FROM (SELECT MIN(tagente_estado.estado) as min_estado FROM tagente_estado, tagente, tagente_modulo WHERE tagente.disabled = 0 AND tagente_estado.utimestamp != 0 AND tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo AND tagente_modulo.disabled = 0 AND tagente_estado.id_agente = tagente.id_agente AND tagente.id_grupo IN $group_clause GROUP BY tagente.id_agente HAVING min_estado = 2) AS S1"); + +} + + // Get monitor NOT INIT, except disabled AND async modules function groups_monitor_not_init ($group_array) { @@ -868,7 +941,7 @@ function groups_monitor_not_init ($group_array) { return 0; } else if (!is_array ($group_array)){ - $group_array[0] = $group_array; + $group_array = array($group_array); } $group_clause = implode (",", $group_array); @@ -894,7 +967,7 @@ function groups_monitor_ok ($group_array) { return 0; } else if (!is_array ($group_array)){ - $group_array[0] = $group_array; + $group_array = array($group_array); } $group_clause = implode (",", $group_array); @@ -917,7 +990,7 @@ function groups_monitor_critical ($group_array) { return 0; } else if (!is_array ($group_array)){ - $group_array[0] = $group_array; + $group_array = array($group_array); } $group_clause = implode (",", $group_array); @@ -941,7 +1014,7 @@ function groups_monitor_warning ($group_array) { return 0; } else if (!is_array ($group_array)){ - $group_array[0] = $group_array; + $group_array = array($group_array); } $group_clause = implode (",", $group_array); @@ -965,7 +1038,7 @@ function groups_monitor_unknown ($group_array) { return 0; } else if (!is_array ($group_array)){ - $group_array[0] = $group_array; + $group_array = array($group_array); } $group_clause = implode (",", $group_array); @@ -989,7 +1062,7 @@ function groups_monitor_alerts ($group_array) { return 0; } else if (!is_array ($group_array)){ - $group_array[0] = $group_array; + $group_array = array($group_array); } $group_clause = implode (",", $group_array); @@ -1015,7 +1088,7 @@ function groups_monitor_fired_alerts ($group_array) { return 0; } else if (!is_array ($group_array)){ - $group_array[0] = $group_array; + $group_array = array($group_array); } $group_clause = implode (",", $group_array); @@ -1040,7 +1113,7 @@ function groups_total_agents ($group_array) { return 0; } else if (!is_array ($group_array)){ - $group_array[0] = $group_array; + $group_array = array($group_array); } $group_clause = implode (",", $group_array); diff --git a/pandora_console/operation/tree.php b/pandora_console/operation/tree.php index da14fafc98..ee6ede95de 100644 --- a/pandora_console/operation/tree.php +++ b/pandora_console/operation/tree.php @@ -24,6 +24,7 @@ global $config; if (is_ajax ()) { + function printTable($id_agente) { global $config; @@ -51,7 +52,7 @@ if (is_ajax ()) require_once ("general/noaccess.php"); return; } - + echo '
'; echo ''; //Agent name @@ -166,7 +167,7 @@ if (is_ajax ()) //End of table echo '
'; - + // Blank space below title, DONT remove this, this // Breaks the layout when Flash charts are enabled :-o echo '
 
'; @@ -193,11 +194,11 @@ if (is_ajax ()) return; } - + require_once ('include/functions_reporting.php'); require_once ('include/functions_users.php'); require_once ('include/functions_servers.php'); - + global $config; $enterpriseEnable = false; @@ -320,7 +321,23 @@ if (is_ajax ()) $count++; switch ($type) { case 'group': - $agent_info = reporting_get_agent_module_info ($row["id_agente"]); + $agent_info["monitor_alertsfired"] = agents_get_alerts_fired ($row["id_agente"]); + + $agent_info["monitor_critical"] = agents_monitor_critical ($row["id_agente"]); + $agent_info["monitor_warning"] = agents_monitor_warning ($row["id_agente"]); + $agent_info["monitor_unknown"] = agents_monitor_unknown ($row["id_agente"]); + $agent_info["monitor_normal"] = agents_monitor_ok ($row["id_agente"]); + + $agent_info["alert_img"] = agents_tree_view_alert_img ($agent_info["monitor_alertsfired"]); + + $agent_info["status_img"] = agetns_tree_view_status_img ($agent_info["monitor_critical"], + $agent_info["monitor_warning"], + $agent_info["monitor_unknown"]); + + //Count all modules + $agent_info["modules"] = $agent_info["monitor_critical"] + $agent_info["monitor_warning"] + $agent_info["monitor_unknown"] + $agent_info["monitor_normal"]; + + break; case 'os': $agent_info = reporting_get_agent_module_info ($row["id_agente"]); @@ -381,7 +398,6 @@ if (is_ajax ()) html_print_image ("operation/tree/branch.png", false, array ("style" => 'vertical-align: middle;')); echo $img; - echo ""; echo " "; echo str_replace('.png' ,'_ball.png', @@ -394,7 +410,7 @@ if (is_ajax ()) echo ""; echo " "; - + echo $row["nombre"]; echo " ("; @@ -632,7 +648,22 @@ function printTree_($type) { echo ''; echo ''; @@ -1042,6 +1052,11 @@ printTree_($activeTab); return; if (loadDiv == 0) { + + //Put an spinner to simulate loading process + $('#tree_div'+id_father+'_'+type+'_'+div_id).html(""); + $('#tree_div'+id_father+'_'+type+'_'+div_id).show('normal'); + $('#tree_div'+id_father+'_'+type+'_'+div_id).attr('loadDiv', 2); $.ajax({ type: "POST", @@ -1139,8 +1154,8 @@ printTree_($activeTab); ); } - function loadTable(type, div_id, less_branchs, id_father) { - id_agent = div_id; + function loadTable(type, div_id, less_branchs, id_father) { + id_agent = div_id; $.ajax({ type: "POST", url: "ajax.php", @@ -1149,7 +1164,8 @@ printTree_($activeTab); $('#cont').html(data); } }); - loadSubTree(type, div_id, less_branchs, id_father); + + loadSubTree(type, div_id, less_branchs, id_father); }
'; - $avariableGroups = users_get_groups(); //db_get_all_rows_in_table('tgrupo', 'nombre'); + + //Get all groups + $avariableGroups = users_get_groups (); //db_get_all_rows_in_table('tgrupo', 'nombre'); + + //Get all groups with agents + $full_groups = db_get_all_rows_sql("SELECT DISTINCT id_grupo FROM tagente"); + + $fgroups = array(); + + foreach ($full_groups as $fg) { + $fgroups[$fg['id_grupo']] = ""; + } + + //We only want groups with agents, so we need the intesect of both arrays. + $avariableGroups = array_intersect_key($avariableGroups, $fgroups); + $avariableGroupsIds = implode(',',array_keys($avariableGroups)); if($avariableGroupsIds == ''){ $avariableGroupsIds == -1; @@ -776,33 +807,10 @@ function printTree_($type) { $id = $item['id_grupo']; $name = $item['nombre']; $iconImg = html_print_image ("images/groups_small/" . groups_get_icon($item['id_grupo']).".png", true, array ("style" => 'vertical-align: middle; width: 16px; height: 16px;')); - - $agentes = db_get_all_rows_sql("SELECT id_agente FROM tagente WHERE id_grupo=$id"); - if ($agentes === false) { - $agentes = array(); - } - $num_ok = 0; - $num_critical = 0; - $num_warning = 0; - $num_unknown = 0; - foreach ($agentes as $agente) { - $stat = reporting_get_agent_module_info ($agente["id_agente"]); - - switch ($stat['status']) { - case 'agent_ok.png': - $num_ok++; - break; - case 'agent_critical.png': - $num_critical++; - break; - case 'agent_warning.png': - $num_warning++; - break; - case 'agent_down.png': - $num_unknown++; - break; - } - } + $num_ok = groups_agent_ok($id); + $num_critical = groups_agent_critical($id); + $num_warning = groups_agent_warning($id); + $num_unknown = groups_agent_unknown ($id); break; case 'module_group': $id = $item['id_mg']; @@ -923,7 +931,9 @@ function printTree_($type) { $img = html_print_image ("operation/tree/last_closed.png", true, array ("style" => 'vertical-align: middle;', "id" => "tree_image_" . $type . "_" . $id, "pos_tree" => "3")); } } - if (($type == 'os') && ($num_ok == 0) && ($num_critical == 0) && ($num_warning == 0) && ($num_unknown == 0)) { + + //skip if there is a empty OS or group! + if (($type == 'os' || $type == 'group') && ($num_ok == 0) && ($num_critical == 0) && ($num_warning == 0) && ($num_unknown == 0)) { continue; } else { echo "
  • @@ -936,7 +946,7 @@ function printTree_($type) { echo "
    "; echo "
  • \n"; - } + } } echo "\n"; echo '