diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index 9c46958694..001a97f256 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,11 @@ +2012-06-11 Dario Rodriguez + + * include/functions_modules.php, + include/functions_agents.php, + operation/tree.php: Improved tree view for module groups. + + MERGED FROM 4.0.2 + 2012-06-11 Miguel de Dios * include/functions_visual_map.php: cleaned source code style. diff --git a/pandora_console/include/functions_agents.php b/pandora_console/include/functions_agents.php index 7a542d25b8..0ec71bbec2 100644 --- a/pandora_console/include/functions_agents.php +++ b/pandora_console/include/functions_agents.php @@ -1851,4 +1851,94 @@ function agents_get_count_incidents ($id_agent) { return db_get_value('count(*)', 'tincidencia', 'id_agent', $id_agent); } + +// Get critical monitors by using the status code in modules. + +function agents_monitor_critical ($id_agent, $filter="") { + + if ($filter) { + $filter = " AND ".$filter; + } + + return db_get_sql ("SELECT COUNT( DISTINCT tagente_modulo.id_agente_modulo) 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_agente = $id_agent".$filter); +} + +// Get warning monitors by using the status code in modules. + +function agents_monitor_warning ($id_agent, $filter="") { + + if ($filter) { + $filter = " AND ".$filter; + } + + return db_get_sql ("SELECT COUNT( DISTINCT tagente_modulo.id_agente_modulo) 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 = 2 AND tagente_estado.id_agente = tagente.id_agente AND tagente.id_agente = $id_agent".$filter); +} + +// Get unknown monitors by using the status code in modules. + +function agents_monitor_unknown ($id_agent, $filter="") { + + if ($filter) { + $filter = " AND ".$filter; + } + + return db_get_sql ("SELECT COUNT( DISTINCT tagente_modulo.id_agente_modulo) 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 = 3 AND tagente_estado.id_agente = tagente.id_agente AND tagente.id_agente = $id_agent".$filter); +} + +// Get ok monitors by using the status code in modules. + +function agents_monitor_ok ($id_agent, $filter="") { + + if ($filter) { + $filter = " AND ".$filter; + } + + return db_get_sql ("SELECT COUNT( DISTINCT tagente_modulo.id_agente_modulo) 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 = 0 AND tagente_estado.id_agente = tagente.id_agente AND tagente.id_agente = $id_agent".$filter); +} + +//Get alert fired for this agent + +function agents_get_alerts_fired ($id_agent, $filter="") { + + $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) { + + if ($alert_fired) { + return ui_print_status_image (STATUS_ALERT_FIRED, __('Alert fired'), true); + } else { + return ui_print_status_image (STATUS_ALERT_NOT_FIRED, __('Alert not fired'), true); + } +} + +//Returns the status image to display tree view + +function agetns_tree_view_status_img ($critical, $warning, $unknown) { + + if ($critical > 0) { + return ui_print_status_image (STATUS_AGENT_CRITICAL, __('At least one module in CRITICAL status'), true); + } + else if ($warning > 0) { + return ui_print_status_image (STATUS_AGENT_WARNING, __('At least one module in WARNING status'), true); + } + else if ($unknown > 0) { + return ui_print_status_image (STATUS_AGENT_DOWN, __('At least one module is in UKNOWN status'), true); + } + else { + return ui_print_status_image (STATUS_AGENT_OK, __('All Monitors OK'), true); + } +} + + ?> diff --git a/pandora_console/include/functions_modules.php b/pandora_console/include/functions_modules.php index c161e94e76..31f0bdc687 100644 --- a/pandora_console/include/functions_modules.php +++ b/pandora_console/include/functions_modules.php @@ -1306,6 +1306,64 @@ function modules_agents_warning ($module_name) { } +// Get unknown agents by using the status code in modules + +function modules_group_agent_unknown ($module_group) { + + //TODO REVIEW ORACLE AND POSTGRES + + 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_estado.estado != 0 AND tagente_modulo.id_module_group = $module_group GROUP BY tagente.id_agente HAVING min_estado = 3) AS S1"); + +} + +// Get ok agents by using the status code in modules. + +function modules_group_agent_ok ($module_group) { + + //!!!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 + + //TODO REVIEW ORACLE AND POSTGRES + + 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_modulo.id_module_group = $module_group GROUP BY tagente.id_agente HAVING max_estado = 0) AS S1"); + +} + +// Get critical agents by using the status code in modules. + +function modules_group_agent_critical ($module_group) { + + //!!!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 + + //TODO REVIEW ORACLE AND POSTGRES + + 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_modulo.id_module_group = $module_group"); + +} + +// Get warning agents by using the status code in modules. + +function modules_group_agent_warning ($module_group) { + + //!!!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 + + //TODO REVIEW ORACLE AND POSTGRES + + 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_modulo.id_module_group = $module_group GROUP BY tagente.id_agente HAVING min_estado = 2) AS S1"); + +} ?> - diff --git a/pandora_console/operation/tree.php b/pandora_console/operation/tree.php index 85d0ef86f5..4c7f33060d 100644 --- a/pandora_console/operation/tree.php +++ b/pandora_console/operation/tree.php @@ -265,9 +265,14 @@ if (is_ajax ()) WHERE id_os = %s AND (%s id_grupo IN (%s))', $id, $extra_sql, $groups_sql); break; case 'module_group': + $extra_sql = substr($extra_sql,1); + $extra_sql = "tagente_modulo.".$extra_sql; $sql = sprintf('SELECT * FROM tagente - WHERE id_agente IN (SELECT id_agente FROM tagente_modulo WHERE id_module_group = %s) - AND (%s id_grupo IN (%s))', $id, $extra_sql, $groups_sql); + WHERE id_agente IN (SELECT tagente_modulo.id_agente FROM tagente_modulo, tagente_estado + WHERE tagente_modulo.id_agente = tagente_estado.id_agente AND tagente_estado.utimestamp !=0 AND + tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo + AND id_module_group = %s + AND ((%s id_grupo IN (%s)))', $id, $extra_sql, $groups_sql); break; case 'policies': if ($id == 0) @@ -341,7 +346,22 @@ if (is_ajax ()) $agent_info["modules"] = $agent_info["monitor_critical"] + $agent_info["monitor_warning"] + $agent_info["monitor_unknown"] + $agent_info["monitor_normal"]; break; case 'module_group': - $agent_info = reporting_get_agent_module_info ($row["id_agente"], ' id_module_group = ' . $id); + $agent_info["monitor_alertsfired"] = agents_get_alerts_fired ($row["id_agente"], "id_module_group = $id"); + + $agent_info["monitor_critical"] = agents_monitor_critical($row["id_agente"], "tagente_modulo.id_module_group = $id"); + $agent_info["monitor_warning"] = agents_monitor_warning ($row["id_agente"], "tagente_modulo.id_module_group = $id"); + $agent_info["monitor_unknown"] = agents_monitor_unknown ($row["id_agente"], "tagente_modulo.id_module_group = $id"); + $agent_info["monitor_normal"] = agents_monitor_ok ($row["id_agente"], "tagente_modulo.id_module_group = $id"); + + $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 'module': switch ($config["dbtype"]) { @@ -704,7 +724,7 @@ function printTree_($type) { WHERE nombre COLLATE utf8_general_ci LIKE '%$search_free%'))"; $list = db_get_all_rows_sql($sql); } else { - $list = db_get_all_rows_in_table('tmodule_group', 'name'); + $list = db_get_all_rows_sql("SELECT distinct id_mg, name FROM tmodule_group, tagente_modulo WHERE tmodule_group.id_mg = tagente_modulo.id_module_group"); if ($list !== false) array_push($list, array('id_mg' => 0, 'name' => 'Not assigned')); } @@ -787,34 +807,10 @@ function printTree_($type) { case 'module_group': $id = $item['id_mg']; $name = $item['name']; - $agentes = db_get_all_rows_sql("SELECT id_agente FROM tagente - WHERE id_agente IN (SELECT id_agente FROM tagente_modulo - WHERE id_module_group=$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 = modules_group_agent_ok($id); + $num_critical = modules_group_agent_critical ($id); + $num_warning = modules_group_agent_warning($id); + $num_unknown = modules_group_agent_unknown($id); break; case 'policies': $id = $item['id'];