2012-06-07 Dario Rodriguez <dario.rodriguez@artica.es>

* operation/tree.php,
	include/functions_groups.php: Fixed some errors and 
	improved performance of group tree view.

	MERGED FROM 4.0.2



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@6435 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
darode 2012-06-07 09:24:05 +00:00
parent 358315f7e1
commit 3356ea7904
3 changed files with 148 additions and 51 deletions

View File

@ -1,3 +1,11 @@
2012-06-07 Dario Rodriguez <dario.rodriguez@artica.es>
* 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 <juanmanuel.ramon@artica.es> 2012-06-06 Juan Manuel Ramon <juanmanuel.ramon@artica.es>
* operation/agentes/ver_agente.php * operation/agentes/ver_agente.php

View File

@ -842,13 +842,11 @@ function groups_create_group($group_name, $rest_values){
function groups_agent_unknown ($group_array) { function groups_agent_unknown ($group_array) {
// If there are not groups to query, we jump to nextone
if (empty ($group_array)) { if (empty ($group_array)) {
return 0; return 0;
} else if (!is_array ($group_array)){ } else if (!is_array ($group_array)){
$group_array[0] = $group_array; $group_array = array($group_array);
} }
$group_clause = implode (",", $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 // Get monitor NOT INIT, except disabled AND async modules
function groups_monitor_not_init ($group_array) { function groups_monitor_not_init ($group_array) {
@ -868,7 +941,7 @@ function groups_monitor_not_init ($group_array) {
return 0; return 0;
} else if (!is_array ($group_array)){ } else if (!is_array ($group_array)){
$group_array[0] = $group_array; $group_array = array($group_array);
} }
$group_clause = implode (",", $group_array); $group_clause = implode (",", $group_array);
@ -894,7 +967,7 @@ function groups_monitor_ok ($group_array) {
return 0; return 0;
} else if (!is_array ($group_array)){ } else if (!is_array ($group_array)){
$group_array[0] = $group_array; $group_array = array($group_array);
} }
$group_clause = implode (",", $group_array); $group_clause = implode (",", $group_array);
@ -917,7 +990,7 @@ function groups_monitor_critical ($group_array) {
return 0; return 0;
} else if (!is_array ($group_array)){ } else if (!is_array ($group_array)){
$group_array[0] = $group_array; $group_array = array($group_array);
} }
$group_clause = implode (",", $group_array); $group_clause = implode (",", $group_array);
@ -941,7 +1014,7 @@ function groups_monitor_warning ($group_array) {
return 0; return 0;
} else if (!is_array ($group_array)){ } else if (!is_array ($group_array)){
$group_array[0] = $group_array; $group_array = array($group_array);
} }
$group_clause = implode (",", $group_array); $group_clause = implode (",", $group_array);
@ -965,7 +1038,7 @@ function groups_monitor_unknown ($group_array) {
return 0; return 0;
} else if (!is_array ($group_array)){ } else if (!is_array ($group_array)){
$group_array[0] = $group_array; $group_array = array($group_array);
} }
$group_clause = implode (",", $group_array); $group_clause = implode (",", $group_array);
@ -989,7 +1062,7 @@ function groups_monitor_alerts ($group_array) {
return 0; return 0;
} else if (!is_array ($group_array)){ } else if (!is_array ($group_array)){
$group_array[0] = $group_array; $group_array = array($group_array);
} }
$group_clause = implode (",", $group_array); $group_clause = implode (",", $group_array);
@ -1015,7 +1088,7 @@ function groups_monitor_fired_alerts ($group_array) {
return 0; return 0;
} else if (!is_array ($group_array)){ } else if (!is_array ($group_array)){
$group_array[0] = $group_array; $group_array = array($group_array);
} }
$group_clause = implode (",", $group_array); $group_clause = implode (",", $group_array);
@ -1040,7 +1113,7 @@ function groups_total_agents ($group_array) {
return 0; return 0;
} else if (!is_array ($group_array)){ } else if (!is_array ($group_array)){
$group_array[0] = $group_array; $group_array = array($group_array);
} }
$group_clause = implode (",", $group_array); $group_clause = implode (",", $group_array);

View File

@ -24,6 +24,7 @@ global $config;
if (is_ajax ()) if (is_ajax ())
{ {
function printTable($id_agente) { function printTable($id_agente) {
global $config; global $config;
@ -320,7 +321,23 @@ if (is_ajax ())
$count++; $count++;
switch ($type) { switch ($type) {
case 'group': 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; break;
case 'os': case 'os':
$agent_info = reporting_get_agent_module_info ($row["id_agente"]); $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;')); html_print_image ("operation/tree/branch.png", false, array ("style" => 'vertical-align: middle;'));
echo $img; echo $img;
echo "</a>"; echo "</a>";
echo " "; echo " ";
echo str_replace('.png' ,'_ball.png', echo str_replace('.png' ,'_ball.png',
@ -632,7 +648,22 @@ function printTree_($type) {
echo '<table class="databox" style="width:98%">'; echo '<table class="databox" style="width:98%">';
echo '<tr><td style="width:60%" valign="top">'; echo '<tr><td style="width:60%" valign="top">';
//Get all groups
$avariableGroups = users_get_groups (); //db_get_all_rows_in_table('tgrupo', 'nombre'); $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)); $avariableGroupsIds = implode(',',array_keys($avariableGroups));
if($avariableGroupsIds == ''){ if($avariableGroupsIds == ''){
$avariableGroupsIds == -1; $avariableGroupsIds == -1;
@ -776,33 +807,10 @@ function printTree_($type) {
$id = $item['id_grupo']; $id = $item['id_grupo'];
$name = $item['nombre']; $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;')); $iconImg = html_print_image ("images/groups_small/" . groups_get_icon($item['id_grupo']).".png", true, array ("style" => 'vertical-align: middle; width: 16px; height: 16px;'));
$num_ok = groups_agent_ok($id);
$agentes = db_get_all_rows_sql("SELECT id_agente FROM tagente WHERE id_grupo=$id"); $num_critical = groups_agent_critical($id);
if ($agentes === false) { $num_warning = groups_agent_warning($id);
$agentes = array(); $num_unknown = groups_agent_unknown ($id);
}
$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;
}
}
break; break;
case 'module_group': case 'module_group':
$id = $item['id_mg']; $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")); $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; continue;
} else { } else {
echo "<li style='margin: 0px 0px 0px 0px;'> echo "<li style='margin: 0px 0px 0px 0px;'>
@ -1042,6 +1052,11 @@ printTree_($activeTab);
return; return;
if (loadDiv == 0) { if (loadDiv == 0) {
//Put an spinner to simulate loading process
$('#tree_div'+id_father+'_'+type+'_'+div_id).html("<img style='padding-top:10px;padding-bottom:10px;padding-left:20px;' src=images/spinner.gif>");
$('#tree_div'+id_father+'_'+type+'_'+div_id).show('normal');
$('#tree_div'+id_father+'_'+type+'_'+div_id).attr('loadDiv', 2); $('#tree_div'+id_father+'_'+type+'_'+div_id).attr('loadDiv', 2);
$.ajax({ $.ajax({
type: "POST", type: "POST",
@ -1149,6 +1164,7 @@ printTree_($activeTab);
$('#cont').html(data); $('#cont').html(data);
} }
}); });
loadSubTree(type, div_id, less_branchs, id_father); loadSubTree(type, div_id, less_branchs, id_father);
} }
</script> </script>