From 7298ddd183ae2c8a3dddb051c6730d82ee0e5d57 Mon Sep 17 00:00:00 2001 From: darode Date: Thu, 7 Jun 2012 14:29:00 +0000 Subject: [PATCH] 2012-06-07 Dario Rodriguez * include/functions_modules.php, operation/tree.php: Improved performance of tree view for modules, its not very good but now works... MERGED FROM 4.0.2 git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@6446 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_console/ChangeLog | 8 +++ pandora_console/include/functions_modules.php | 62 +++++++++++++++++++ pandora_console/operation/tree.php | 36 +++-------- 3 files changed, 77 insertions(+), 29 deletions(-) diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index 847edb5543..4bba0d69ca 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,11 @@ +2012-06-07 Dario Rodriguez + + * include/functions_modules.php, + operation/tree.php: Improved performance of tree + view for modules, its not very good but now works... + + MERGED FROM 4.0.2 + 2012-06-07 Juan Manuel Ramon * godmode/menu.php: Hide not valid sections with metaconsole diff --git a/pandora_console/include/functions_modules.php b/pandora_console/include/functions_modules.php index 574e864011..827a900bfe 100644 --- a/pandora_console/include/functions_modules.php +++ b/pandora_console/include/functions_modules.php @@ -1247,4 +1247,66 @@ function modules_get_status($id_agent_module, $db_status, $data, &$status, &$tit } } +// Get unknown agents by using the status code in modules + +function modules_agents_unknown ($module_name) { + + //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 = 3 AND tagente_estado.id_agente = tagente.id_agente AND tagente.id_agente IN (SELECT id_agente FROM tagente_modulo WHERE nombre LIKE '%$module_name%')"); + +} + +// Get ok agents by using the status code in modules. + +function modules_agents_ok ($module_name) { + + //!!!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.id_agente IN (SELECT id_agente FROM tagente_modulo WHERE nombre LIKE '%$module_name%') GROUP BY tagente.id_agente HAVING max_estado = 0) AS S1"); + +} + +// Get critical agents by using the status code in modules. + +function modules_agents_critical ($module_name) { + + //!!!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.id_agente IN (SELECT id_agente FROM tagente_modulo WHERE nombre LIKE '%$module_name%')"); + +} + +// Get warning agents by using the status code in modules. + +function modules_agents_warning ($module_name) { + + //!!!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.id_agente IN (SELECT id_agente FROM tagente_modulo WHERE nombre LIKE '%$module_name%') 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 a035f9d773..d8d43ef39b 100644 --- a/pandora_console/operation/tree.php +++ b/pandora_console/operation/tree.php @@ -632,6 +632,7 @@ if (is_ajax ()) include_once($config['homedir'] . "/include/functions_groups.php"); include_once($config['homedir'] . "/include/functions_os.php"); +include_once($config['homedir'] . "/include/functions_modules.php"); include_once($config['homedir'] . "/include/functions_servers.php"); include_once($config['homedir'] . "/include/functions_reporting.php"); include_once($config['homedir'] . "/include/functions_ui.php"); @@ -851,36 +852,13 @@ function printTree_($type) { break; case 'module': $id = str_replace(array(' ','#'), array('_articapandora_'.ord(' ').'_pandoraartica_', '_articapandora_'.ord('#').'_pandoraartica_'),io_safe_output($item['nombre'])); + $id = str_replace ("/", "_", $id); $name = io_safe_output($item['nombre']); - $name_sql = io_safe_input($item['nombre']); - $agentes = db_get_all_rows_sql("SELECT id_agente FROM tagente - WHERE id_agente IN (SELECT id_agente FROM tagente_modulo - WHERE nombre COLLATE utf8_general_ci LIKE '%$name_sql%')"); - 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; - } - } + $module_name = $item['nombre']; + $num_ok = modules_agents_ok($module_name); + $num_critical = modules_agents_critical($module_name); + $num_warning = modules_agents_warning($module_name); + $num_unknown = modules_agents_unknown($module_name); break; }