From 4b5566d01f05e02a39d666108b52192c5eb98190 Mon Sep 17 00:00:00 2001 From: ramonn Date: Tue, 20 Nov 2012 16:14:45 +0000 Subject: [PATCH] 2012-11-20 Ramon Novoa * include/functions_groups.php, include/functions_agents.php, include/functions_modules.php, include/functions_treeview.php, include/functions_os.php, pandoradb.sql, pandoradb.postgreSQL.sql, install.php, pandoradb.oracle.sql, operation/tree.php, extras/pandoradb_migrate_4.0.x_to_5.0.mysql.sql, extras/pandoradb_migrate_4.0.x_to_5.0.oracle.sql, extras/pandoradb_migrate_4.0.x_to_5.0.postgreSQL.sql: Improved tree view performance. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@7170 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_console/ChangeLog | 17 ++ .../pandoradb_migrate_4.0.x_to_5.0.mysql.sql | 1 + .../pandoradb_migrate_4.0.x_to_5.0.oracle.sql | 1 + ...doradb_migrate_4.0.x_to_5.0.postgreSQL.sql | 1 + pandora_console/include/functions_agents.php | 49 +---- pandora_console/include/functions_groups.php | 201 +----------------- pandora_console/include/functions_modules.php | 162 +------------- pandora_console/include/functions_os.php | 150 +------------ .../include/functions_treeview.php | 35 +-- pandora_console/operation/tree.php | 165 +++----------- pandora_console/pandoradb.oracle.sql | 3 +- pandora_console/pandoradb.postgreSQL.sql | 3 +- pandora_console/pandoradb.sql | 1 + 13 files changed, 83 insertions(+), 706 deletions(-) diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index 5064c6fd7d..d76bc3661f 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,20 @@ +2012-11-20 Ramon Novoa + + * include/functions_groups.php, + include/functions_agents.php, + include/functions_modules.php, + include/functions_treeview.php, + include/functions_os.php, + pandoradb.sql, + pandoradb.postgreSQL.sql, + install.php, + pandoradb.oracle.sql, + operation/tree.php, + extras/pandoradb_migrate_4.0.x_to_5.0.mysql.sql, + extras/pandoradb_migrate_4.0.x_to_5.0.oracle.sql, + extras/pandoradb_migrate_4.0.x_to_5.0.postgreSQL.sql: Improved tree + view performance. + 2012-11-20 Dario Rodriguez * operation/integria_incidents/incident.list.php: Fixed a problem with diff --git a/pandora_console/extras/pandoradb_migrate_4.0.x_to_5.0.mysql.sql b/pandora_console/extras/pandoradb_migrate_4.0.x_to_5.0.mysql.sql index 59a89b55d8..674ee18312 100644 --- a/pandora_console/extras/pandoradb_migrate_4.0.x_to_5.0.mysql.sql +++ b/pandora_console/extras/pandoradb_migrate_4.0.x_to_5.0.mysql.sql @@ -64,6 +64,7 @@ ALTER TABLE `tagente` ADD COLUMN `critical_count` bigint(20) unsigned NOT NULL d ALTER TABLE `tagente` ADD COLUMN `unknown_count` bigint(20) unsigned NOT NULL default '0'; ALTER TABLE `tagente` ADD COLUMN `notinit_count` bigint(20) unsigned NOT NULL default '0'; ALTER TABLE `tagente` ADD COLUMN `total_count` bigint(20) unsigned NOT NULL default '0'; +ALTER TABLE `tagente` ADD COLUMN `fired_count` bigint(20) unsigned NOT NULL default '0'; -- --------------------------------------------------------------------- -- Table `talert_special_days` diff --git a/pandora_console/extras/pandoradb_migrate_4.0.x_to_5.0.oracle.sql b/pandora_console/extras/pandoradb_migrate_4.0.x_to_5.0.oracle.sql index bea9c05fc8..8080d97ee2 100644 --- a/pandora_console/extras/pandoradb_migrate_4.0.x_to_5.0.oracle.sql +++ b/pandora_console/extras/pandoradb_migrate_4.0.x_to_5.0.oracle.sql @@ -83,6 +83,7 @@ ALTER TABLE tagente ADD (critical_count NUMBER(20, 0) default 0 NOT NULL); ALTER TABLE tagente ADD (unknown_count NUMBER(20, 0) default 0 NOT NULL); ALTER TABLE tagente ADD (notinit_count NUMBER(20, 0) default 0 NOT NULL); ALTER TABLE tagente ADD (total_count NUMBER(20, 0) default 0 NOT NULL); +ALTER TABLE tagente ADD (fired_count NUMBER(20, 0) default 0 NOT NULL); -- ----------------------------------------------------- -- Table talert_special_days diff --git a/pandora_console/extras/pandoradb_migrate_4.0.x_to_5.0.postgreSQL.sql b/pandora_console/extras/pandoradb_migrate_4.0.x_to_5.0.postgreSQL.sql index b81ce16005..d276693fae 100644 --- a/pandora_console/extras/pandoradb_migrate_4.0.x_to_5.0.postgreSQL.sql +++ b/pandora_console/extras/pandoradb_migrate_4.0.x_to_5.0.postgreSQL.sql @@ -77,6 +77,7 @@ ALTER TABLE "tagente" ADD COLUMN "critical_count" INTEGER NOT NULL default 0; ALTER TABLE "tagente" ADD COLUMN "unknown_count" INTEGER NOT NULL default 0; ALTER TABLE "tagente" ADD COLUMN "notinit_count" INTEGER NOT NULL default 0; ALTER TABLE "tagente" ADD COLUMN "total_count" INTEGER NOT NULL default 0; +ALTER TABLE "tagente" ADD COLUMN "fired_count" INTEGER NOT NULL default 0; -- ----------------------------------------------------- -- Table "talert_special_days" diff --git a/pandora_console/include/functions_agents.php b/pandora_console/include/functions_agents.php index 385d82dd27..ea4c1e0a53 100644 --- a/pandora_console/include/functions_agents.php +++ b/pandora_console/include/functions_agents.php @@ -1892,15 +1892,7 @@ function agents_monitor_critical ($id_agent, $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); + return db_get_sql ("SELECT critical_count FROM tagente WHERE id_agente = $id_agent" . $filter); } // Get warning monitors by using the status code in modules. @@ -1911,15 +1903,7 @@ function agents_monitor_warning ($id_agent, $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); + return db_get_sql ("SELECT warning_count FROM tagente WHERE id_agente = $id_agent" . $filter); } // Get unknown monitors by using the status code in modules. @@ -1930,15 +1914,7 @@ function agents_monitor_unknown ($id_agent, $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); + return db_get_sql ("SELECT unknown_count FROM tagente WHERE id_agente = $id_agent" . $filter); } // Get ok monitors by using the status code in modules. @@ -1948,15 +1924,7 @@ function agents_monitor_ok ($id_agent, $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); + return db_get_sql ("SELECT normal_count FROM tagente WHERE id_agente = $id_agent" . $filter); } /** @@ -1990,14 +1958,7 @@ function agents_monitor_notinit ($id_agent, $filter="") { $filter = " AND ".$filter; } - return db_get_sql ("SELECT COUNT( DISTINCT tagente_estado.id_agente_modulo ) - FROM tagente_estado, tagente, tagente_modulo - WHERE tagente.disabled = 0 AND tagente.id_agente = tagente_estado.id_agente - AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo - AND tagente_modulo.disabled = 0 - AND tagente_modulo.id_tipo_modulo NOT IN (21,22,23) - AND utimestamp = 0 - AND tagente.id_agente = $id_agent ".$filter); + return db_get_sql ("SELECT notinit_count FROM tagente WHERE id_agente = $id_agent" . $filter); } /** diff --git a/pandora_console/include/functions_groups.php b/pandora_console/include/functions_groups.php index 579f82666e..595b8e67fd 100644 --- a/pandora_console/include/functions_groups.php +++ b/pandora_console/include/functions_groups.php @@ -854,50 +854,7 @@ function groups_agent_unknown ($group_array) { $group_clause = implode (",", $group_array); $group_clause = "(" . $group_clause . ")"; - // Agent of module group X and critical status - $agents_critical = "SELECT tagente.id_agente - FROM tagente_estado, tagente, tagente_modulo - WHERE tagente_estado.id_agente = tagente.id_agente - AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo - AND tagente.disabled = 0 - AND tagente_modulo.disabled = 0 - AND estado = 1 - AND tagente_estado.utimestamp != 0 - AND tagente.id_grupo IN $group_clause - GROUP by tagente.id_agente"; - - // Agent of module group X and warning status - $agents_warning = "SELECT tagente.id_agente - FROM tagente_estado, tagente, tagente_modulo - WHERE tagente_estado.id_agente = tagente.id_agente - AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo - AND tagente.disabled = 0 - AND tagente_modulo.disabled = 0 - AND estado = 2 - AND tagente_estado.utimestamp != 0 - AND tagente.id_grupo IN $group_clause - GROUP by tagente.id_agente"; - - // Agent of module group X and unknown status - $agents_unknown = "SELECT tagente.id_agente - FROM tagente_estado, tagente, tagente_modulo - WHERE tagente_estado.id_agente = tagente.id_agente - AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo - AND tagente.disabled = 0 - AND tagente_modulo.disabled = 0 - AND estado = 3 - AND tagente_estado.utimestamp != 0 - AND tagente.id_grupo IN $group_clause - GROUP by tagente.id_agente"; - - return db_get_sql ("SELECT COUNT(*) FROM ( SELECT DISTINCT tagente.id_agente - FROM tagente, tagente_modulo, tagente_estado - WHERE tagente.id_agente = tagente_modulo.id_agente - AND tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo - AND tagente.id_grupo IN $group_clause - AND tagente.id_agente NOT IN ($agents_critical) - AND tagente.id_agente NOT IN ($agents_warning) - AND tagente.id_agente IN ($agents_unknown) ) AS t"); + return db_get_sql ("SELECT COUNT(*) FROM tagente WHERE critical_count=0 AND warning_count=0 AND unknown_count>0 AND id_grupo IN $group_clause"); } // Get ok agents by using the status code in modules. @@ -915,71 +872,7 @@ function groups_agent_ok ($group_array) { $group_clause = implode (",", $group_array); $group_clause = "(" . $group_clause . ")"; - // Agent of module group X and critical status - $agents_critical = "SELECT tagente.id_agente - FROM tagente_estado, tagente, tagente_modulo - WHERE tagente_estado.id_agente = tagente.id_agente - AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo - AND tagente.disabled = 0 - AND tagente_modulo.disabled = 0 - AND estado = 1 - AND tagente_estado.utimestamp != 0 - AND tagente.id_grupo IN $group_clause - group by tagente.id_agente"; - - // Agent of module group X and warning status - $agents_warning = "SELECT tagente.id_agente - FROM tagente_estado, tagente, tagente_modulo - WHERE tagente_estado.id_agente = tagente.id_agente - AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo - AND tagente.disabled = 0 - AND tagente_modulo.disabled = 0 - AND estado = 2 - AND tagente_estado.utimestamp != 0 - AND tagente.id_grupo IN $group_clause - group by tagente.id_agente"; - - // Agent of module group X and unknown status - $agents_unknown = "SELECT tagente.id_agente - FROM tagente_estado, tagente, tagente_modulo - WHERE tagente_estado.id_agente = tagente.id_agente - AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo - AND tagente.disabled = 0 - AND tagente_modulo.disabled = 0 - AND estado = 3 - AND tagente_estado.utimestamp != 0 - AND tagente.id_grupo IN $group_clause - group by tagente.id_agente"; - - // Agent of module group X and ok status - $agents_ok = "SELECT tagente.id_agente - FROM tagente_estado, tagente, tagente_modulo - WHERE tagente_estado.id_agente = tagente.id_agente - AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo - AND tagente.disabled = 0 - AND tagente_modulo.disabled = 0 - AND estado = 0 - AND tagente_estado.utimestamp != 0 - AND tagente.id_grupo IN $group_clause - group by tagente.id_agente"; - - // Agents without modules has a normal status - $void_agents = "SELECT tagente.id_agente FROM tagente - WHERE tagente.disabled = 0 - AND tagente.id_grupo IN $group_clause - AND tagente.id_agente NOT IN (SELECT tagente_estado.id_agente FROM tagente_estado)"; - - return db_get_sql ("SELECT COUNT(*) FROM ( SELECT DISTINCT tagente.id_agente - FROM tagente, tagente_modulo, tagente_estado - WHERE tagente.id_agente = tagente_modulo.id_agente - AND tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo - - AND tagente.id_grupo IN $group_clause - AND tagente.id_agente NOT IN ($agents_critical) - AND tagente.id_agente NOT IN ($agents_warning) - AND tagente.id_agente NOT IN ($agents_unknown) - AND tagente.id_agente IN ($agents_ok) UNION $void_agents) AS t"); - + return db_get_sql ("SELECT COUNT(*) FROM tagente WHERE normal_count=total_count AND id_grupo IN $group_clause"); } // Get critical agents by using the status code in modules. @@ -996,15 +889,8 @@ function groups_agent_critical ($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 - //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_grupo IN $group_clause"); + return db_get_sql ("SELECT COUNT(*) FROM tagente WHERE critical_count>0 AND id_grupo IN $group_clause"); } @@ -1022,41 +908,7 @@ function groups_agent_warning ($group_array) { $group_clause = implode (",", $group_array); $group_clause = "(" . $group_clause . ")"; - - // Agent of group X and critical status - $agents_critical = "SELECT tagente.id_agente - FROM tagente_estado, tagente, tagente_modulo - WHERE tagente_estado.id_agente = tagente.id_agente - AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo - AND tagente.disabled = 0 - AND tagente_modulo.disabled = 0 - AND estado = 1 - AND tagente_estado.utimestamp != 0 - AND tagente.id_grupo IN $group_clause - group by tagente.id_agente"; - - // Agent of group X and warning status - $agents_warning = "SELECT tagente.id_agente - FROM tagente_estado, tagente, tagente_modulo - WHERE tagente_estado.id_agente = tagente.id_agente - AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo - AND tagente.disabled = 0 - AND tagente_modulo.disabled = 0 - AND estado = 2 - AND tagente_estado.utimestamp != 0 - AND tagente.id_grupo IN $group_clause - group by tagente.id_agente"; - - - return db_get_sql ("SELECT COUNT(*) FROM ( SELECT DISTINCT tagente.id_agente - FROM tagente, tagente_modulo, tagente_estado - WHERE tagente.id_agente = tagente_modulo.id_agente - AND tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo - - AND tagente.id_grupo IN $group_clause - AND tagente.id_agente NOT IN ($agents_critical) - AND tagente.id_agente IN ($agents_warning) ) AS t"); - + return db_get_sql ("SELECT COUNT(*) FROM tagente WHERE critical_count=0 AND warning_count>0 AND id_grupo IN $group_clause"); } @@ -1076,16 +928,8 @@ function groups_monitor_not_init ($group_array) { $group_clause = implode (",", $group_array); $group_clause = "(" . $group_clause . ")"; - //TODO REVIEW ORACLE AND POSTGRES - - return db_get_sql ("SELECT COUNT(tagente_estado.id_agente_estado) - FROM tagente_estado, tagente, tagente_modulo - WHERE tagente.id_grupo IN $group_clause AND tagente.disabled = 0 - AND tagente.id_agente = tagente_estado.id_agente - AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo - AND tagente_modulo.disabled = 0 - AND tagente_modulo.id_tipo_modulo NOT IN (21,22,23,24) AND utimestamp = 0"); - + //TODO REVIEW ORACLE AND POSTGRES + return db_get_sql ("SELECT SUM(notinit_count) FROM tagente WHERE id_grupo IN $group_clause"); } // Get monitor OK, except disabled and non-init @@ -1105,12 +949,7 @@ function groups_monitor_ok ($group_array) { $group_clause = "(" . $group_clause . ")"; //TODO REVIEW ORACLE AND POSTGRES - - return db_get_sql ("SELECT COUNT(tagente_estado.id_agente_estado) - FROM tagente_estado, tagente, tagente_modulo - WHERE tagente.id_grupo IN $group_clause AND tagente.disabled = 0 - AND tagente_estado.id_agente = tagente.id_agente AND tagente_estado.estado = 0 - AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo AND tagente_modulo.disabled = 0 AND tagente_estado.utimestamp != 0"); + return db_get_sql ("SELECT SUM(normal_count) FROM tagente WHERE id_grupo IN $group_clause"); } // Get monitor CRITICAL, except disabled and non-init @@ -1130,13 +969,7 @@ function groups_monitor_critical ($group_array) { $group_clause = "(" . $group_clause . ")"; //TODO REVIEW ORACLE AND POSTGRES - - return db_get_sql ("SELECT COUNT(tagente_estado.id_agente_estado) - FROM tagente_estado, tagente, tagente_modulo - WHERE tagente.id_grupo IN $group_clause AND tagente.disabled = 0 - AND tagente_estado.id_agente = tagente.id_agente AND tagente_estado.estado = 1 - AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo AND tagente_modulo.disabled = 0 AND tagente_estado.utimestamp != 0"); - + return db_get_sql ("SELECT SUM(critical_count) FROM tagente WHERE id_grupo IN $group_clause"); } // Get monitor WARNING, except disabled and non-init @@ -1155,14 +988,8 @@ function groups_monitor_warning ($group_array) { $group_clause = implode (",", $group_array); $group_clause = "(" . $group_clause . ")"; - //TODO REVIEW ORACLE AND POSTGRES - - return db_get_sql ("SELECT COUNT(tagente_estado.id_agente_estado) - FROM tagente_estado, tagente, tagente_modulo - WHERE tagente.id_grupo IN $group_clause AND tagente.disabled = 0 - AND tagente_estado.id_agente = tagente.id_agente AND tagente_estado.estado = 2 - AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo AND tagente_modulo.disabled = 0 AND tagente_estado.utimestamp != 0"); - + //TODO REVIEW ORACLE AND POSTGRES + return db_get_sql ("SELECT SUM(warning_count) FROM tagente WHERE id_grupo IN $group_clause"); } // Get monitor UNKNOWN, except disabled and non-init @@ -1182,13 +1009,7 @@ function groups_monitor_unknown ($group_array) { $group_clause = "(" . $group_clause . ")"; //TODO REVIEW ORACLE AND POSTGRES - - return db_get_sql ("SELECT COUNT(tagente_estado.id_agente_estado) - FROM tagente_estado, tagente, tagente_modulo - WHERE tagente.id_grupo IN $group_clause AND tagente.disabled = 0 - AND tagente_estado.id_agente = tagente.id_agente AND tagente_estado.estado = 3 - AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo AND tagente_modulo.disabled = 0 AND tagente_estado.utimestamp != 0"); - + return db_get_sql ("SELECT SUM(unknown_count) FROM tagente WHERE id_grupo IN $group_clause"); } // Get alerts defined for a given group, except disabled diff --git a/pandora_console/include/functions_modules.php b/pandora_console/include/functions_modules.php index 2afdaca9c8..3013457d9c 100644 --- a/pandora_console/include/functions_modules.php +++ b/pandora_console/include/functions_modules.php @@ -1453,183 +1453,29 @@ function modules_agents_warning ($module_name) { // Get unknown agents by using the status code in modules function modules_group_agent_unknown ($module_group) { - - // Agent of module group X and critical status - $agents_critical = "SELECT tagente.id_agente - FROM tagente_estado, tagente, tagente_modulo - WHERE tagente_estado.id_agente = tagente.id_agente - AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo - AND tagente.disabled = 0 - AND tagente_modulo.disabled = 0 - AND estado = 1 - AND tagente_estado.utimestamp != 0 - AND tagente_modulo.id_module_group = $module_group - group by tagente.id_agente"; - // Agent of module group X and warning status - $agents_warning = "SELECT tagente.id_agente - FROM tagente_estado, tagente, tagente_modulo - WHERE tagente_estado.id_agente = tagente.id_agente - AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo - AND tagente.disabled = 0 - AND tagente_modulo.disabled = 0 - AND estado = 2 - AND tagente_estado.utimestamp != 0 - AND tagente_modulo.id_module_group = $module_group - group by tagente.id_agente"; - - // Agent of module group X and unknown status - $agents_unknown = "SELECT tagente.id_agente - FROM tagente_estado, tagente, tagente_modulo - WHERE tagente_estado.id_agente = tagente.id_agente - AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo - AND tagente.disabled = 0 - AND tagente_modulo.disabled = 0 - AND estado = 3 - AND tagente_estado.utimestamp != 0 - AND tagente_modulo.id_module_group = $module_group - group by tagente.id_agente"; - - return db_get_sql ("SELECT COUNT(*) FROM ( SELECT DISTINCT tagente.id_agente - FROM tagente, tagente_modulo, tagente_estado - WHERE tagente.id_agente = tagente_modulo.id_agente - AND tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo - - AND tagente_modulo.id_module_group = $module_group - AND tagente.id_agente NOT IN ($agents_critical) - AND tagente.id_agente NOT IN ($agents_warning) - AND tagente.id_agente IN ($agents_unknown) ) AS t"); - + return db_get_sql ("SELECT COUNT(*) FROM tagente, tagente_modulo WHERE tagente.id_agente=tagente_modulo.id_agente AND critical_count=0 AND warning_count=0 AND unknown_count>0 AND id_module_group = $module_group"); } // Get ok agents by using the status code in modules. function modules_group_agent_ok ($module_group) { - // Agent of module group X and critical status - $agents_critical = "SELECT tagente.id_agente - FROM tagente_estado, tagente, tagente_modulo - WHERE tagente_estado.id_agente = tagente.id_agente - AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo - AND tagente.disabled = 0 - AND tagente_modulo.disabled = 0 - AND estado = 1 - AND tagente_estado.utimestamp != 0 - AND tagente_modulo.id_module_group = $module_group - group by tagente.id_agente"; - - // Agent of module group X and warning status - $agents_warning = "SELECT tagente.id_agente - FROM tagente_estado, tagente, tagente_modulo - WHERE tagente_estado.id_agente = tagente.id_agente - AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo - AND tagente.disabled = 0 - AND tagente_modulo.disabled = 0 - AND estado = 2 - AND tagente_estado.utimestamp != 0 - AND tagente_modulo.id_module_group = $module_group - group by tagente.id_agente"; - - // Agent of module group X and unknown status - $agents_unknown = "SELECT tagente.id_agente - FROM tagente_estado, tagente, tagente_modulo - WHERE tagente_estado.id_agente = tagente.id_agente - AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo - AND tagente.disabled = 0 - AND tagente_modulo.disabled = 0 - AND estado = 3 - AND tagente_estado.utimestamp != 0 - AND tagente_modulo.id_module_group = $module_group - group by tagente.id_agente"; - - // Agent of module group X and ok status - $agents_ok = "SELECT tagente.id_agente - FROM tagente_estado, tagente, tagente_modulo - WHERE tagente_estado.id_agente = tagente.id_agente - AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo - AND tagente.disabled = 0 - AND tagente_modulo.disabled = 0 - AND estado = 0 - AND tagente_estado.utimestamp != 0 - AND tagente_modulo.id_module_group = $module_group - group by tagente.id_agente"; - - return db_get_sql ("SELECT COUNT(*) FROM ( SELECT DISTINCT tagente.id_agente - FROM tagente, tagente_modulo, tagente_estado - WHERE tagente.id_agente = tagente_modulo.id_agente - AND tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo - - AND tagente_modulo.id_module_group = $module_group - AND tagente.id_agente NOT IN ($agents_critical) - AND tagente.id_agente NOT IN ($agents_warning) - AND tagente.id_agente NOT IN ($agents_unknown) - AND tagente.id_agente IN ($agents_ok) ) AS t"); - + return db_get_sql ("SELECT COUNT(*) FROM tagente, tagente_modulo WHERE tagente.id_agente=tagente_modulo.id_agente AND normal_count=total_count AND id_module_group = $module_group"); } // Get critical agents by using the status code in modules. function modules_group_agent_critical ($module_group) { - // Agent of module group X and critical status - $agents_critical = "SELECT tagente.id_agente - FROM tagente_estado, tagente, tagente_modulo - WHERE tagente_estado.id_agente = tagente.id_agente - AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo - AND tagente.disabled = 0 - AND tagente_modulo.disabled = 0 - AND estado = 1 - AND tagente_estado.utimestamp != 0 - AND tagente_modulo.id_module_group = $module_group - group by tagente.id_agente"; - - return db_get_sql ("SELECT COUNT(*) FROM ( SELECT DISTINCT tagente.id_agente - FROM tagente, tagente_modulo, tagente_estado - WHERE tagente.id_agente = tagente_modulo.id_agente - AND tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo - - AND tagente_modulo.id_module_group = $module_group - AND tagente.id_agente IN ($agents_critical) ) AS t"); - + return db_get_sql ("SELECT COUNT(*) FROM tagente, tagente_modulo WHERE tagente.id_agente=tagente_modulo.id_agente AND critical_count>0 AND id_module_group = $module_group"); } // Get warning agents by using the status code in modules. function modules_group_agent_warning ($module_group) { - // Agent of module group X and critical status - $agents_critical = "SELECT tagente.id_agente - FROM tagente_estado, tagente, tagente_modulo - WHERE tagente_estado.id_agente = tagente.id_agente - AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo - AND tagente.disabled = 0 - AND tagente_modulo.disabled = 0 - AND estado = 1 - AND tagente_estado.utimestamp != 0 - AND tagente_modulo.id_module_group = $module_group - group by tagente.id_agente"; - - // Agent of module group X and warning status - $agents_warning = "SELECT tagente.id_agente - FROM tagente_estado, tagente, tagente_modulo - WHERE tagente_estado.id_agente = tagente.id_agente - AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo - AND tagente.disabled = 0 - AND tagente_modulo.disabled = 0 - AND estado = 2 - AND tagente_estado.utimestamp != 0 - AND tagente_modulo.id_module_group = $module_group - group by tagente.id_agente"; - - return db_get_sql ("SELECT COUNT(*) FROM ( SELECT DISTINCT tagente.id_agente - FROM tagente, tagente_modulo, tagente_estado - WHERE tagente.id_agente = tagente_modulo.id_agente - AND tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo - - AND tagente_modulo.id_module_group = $module_group - AND tagente.id_agente NOT IN ($agents_critical) - AND tagente.id_agente IN ($agents_warning) ) AS t"); - + return db_get_sql ("SELECT COUNT(*) FROM tagente, tagente_modulo WHERE tagente.id_agente=tagente_modulo.id_agente AND critical_count=0 AND warning_count>0 AND id_module_group = $module_group"); } ?> diff --git a/pandora_console/include/functions_os.php b/pandora_console/include/functions_os.php index b6d5b0a0de..6a0bfc6b4b 100755 --- a/pandora_console/include/functions_os.php +++ b/pandora_console/include/functions_os.php @@ -20,170 +20,28 @@ function os_agents_critical ($id_os) { //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_os = $id_os"); + return db_get_sql ("SELECT COUNT(*) FROM tagente WHERE critical_count>0 AND id_os=$id_os"); } // Get ok agents by using the status code in modules. function os_agents_ok($id_os) { - - // Agent of OS X and critical status - $agents_critical = "SELECT tagente.id_agente - FROM tagente_estado, tagente, tagente_modulo - WHERE tagente_estado.id_agente = tagente.id_agente - AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo - AND tagente.disabled = 0 - AND tagente_modulo.disabled = 0 - AND estado = 1 - AND tagente_estado.utimestamp != 0 - AND tagente.id_os = $id_os - group by tagente.id_agente"; - - // Agent of OS X and warning status - $agents_warning = "SELECT tagente.id_agente - FROM tagente_estado, tagente, tagente_modulo - WHERE tagente_estado.id_agente = tagente.id_agente - AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo - AND tagente.disabled = 0 - AND tagente_modulo.disabled = 0 - AND estado = 2 - AND tagente_estado.utimestamp != 0 - AND tagente.id_os = $id_os - group by tagente.id_agente"; - - // Agent of OS X and unknown status - $agents_unknown = "SELECT tagente.id_agente - FROM tagente_estado, tagente, tagente_modulo - WHERE tagente_estado.id_agente = tagente.id_agente - AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo - AND tagente.disabled = 0 - AND tagente_modulo.disabled = 0 - AND estado = 3 - AND tagente_estado.utimestamp != 0 - AND tagente.id_os = $id_os - group by tagente.id_agente"; - - // Agent of OS X and ok status - $agents_ok = "SELECT tagente.id_agente - FROM tagente_estado, tagente, tagente_modulo - WHERE tagente_estado.id_agente = tagente.id_agente - AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo - AND tagente.disabled = 0 - AND tagente_modulo.disabled = 0 - AND estado = 0 - AND tagente_estado.utimestamp != 0 - AND tagente.id_os = $id_os - group by tagente.id_agente"; - - // Agents without modules has a normal status - $void_agents = "SELECT id_agente FROM tagente - WHERE disabled = 0 - AND id_os = $id_os - AND id_agente NOT IN (SELECT id_agente FROM tagente_estado)"; - - return db_get_sql ("SELECT COUNT(*) FROM ( SELECT DISTINCT tagente.id_agente - FROM tagente, tagente_modulo, tagente_estado - WHERE tagente.id_agente = tagente_modulo.id_agente - AND tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo - - AND tagente.id_os = $id_os - AND tagente.id_agente NOT IN ($agents_critical) - AND tagente.id_agente NOT IN ($agents_warning) - AND tagente.id_agente NOT IN ($agents_unknown) - AND tagente.id_agente IN ($agents_ok) - UNION $void_agents) AS t"); + return db_get_sql ("SELECT COUNT(*) FROM tagente WHERE normal_count=total_count AND id_os=$id_os"); } // Get warning agents by using the status code in modules. function os_agents_warning ($id_os) { - - // Agent of OS X and critical status - $agents_critical = "SELECT tagente.id_agente - FROM tagente_estado, tagente, tagente_modulo - WHERE tagente_estado.id_agente = tagente.id_agente - AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo - AND tagente.disabled = 0 - AND tagente_modulo.disabled = 0 - AND estado = 1 - AND tagente_estado.utimestamp != 0 - AND tagente.id_os = $id_os - group by tagente.id_agente"; - // Agent of OS X and warning status - $agents_warning = "SELECT tagente.id_agente - FROM tagente_estado, tagente, tagente_modulo - WHERE tagente_estado.id_agente = tagente.id_agente - AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo - AND tagente.disabled = 0 - AND tagente_modulo.disabled = 0 - AND estado = 2 - AND tagente_estado.utimestamp != 0 - AND tagente.id_os = $id_os - group by tagente.id_agente"; - - return db_get_sql ("SELECT COUNT(*) FROM ( SELECT DISTINCT tagente.id_agente - FROM tagente, tagente_modulo, tagente_estado - WHERE tagente.id_agente = tagente_modulo.id_agente - AND tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo - - AND tagente.id_os = $id_os - AND tagente.id_agente NOT IN ($agents_critical) - AND tagente.id_agente IN ($agents_warning) ) AS t"); - + return db_get_sql ("SELECT COUNT(*) FROM tagente WHERE critical_count=0 AND warning_count>0 AND id_os=$id_os"); } // Get unknown agents by using the status code in modules. function os_agents_unknown ($id_os) { - - // Agent of module group X and critical status - $agents_critical = "SELECT tagente.id_agente - FROM tagente_estado, tagente, tagente_modulo - WHERE tagente_estado.id_agente = tagente.id_agente - AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo - AND tagente.disabled = 0 - AND tagente_modulo.disabled = 0 - AND estado = 1 - AND tagente_estado.utimestamp != 0 - AND tagente.id_os = $id_os - group by tagente.id_agente"; - // Agent of module group X and warning status - $agents_warning = "SELECT tagente.id_agente - FROM tagente_estado, tagente, tagente_modulo - WHERE tagente_estado.id_agente = tagente.id_agente - AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo - AND tagente.disabled = 0 - AND tagente_modulo.disabled = 0 - AND estado = 2 - AND tagente_estado.utimestamp != 0 - AND tagente.id_os = $id_os - group by tagente.id_agente"; - - // Agent of module group X and unknown status - $agents_unknown = "SELECT tagente.id_agente - FROM tagente_estado, tagente, tagente_modulo - WHERE tagente_estado.id_agente = tagente.id_agente - AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo - AND tagente.disabled = 0 - AND tagente_modulo.disabled = 0 - AND estado = 3 - AND tagente_estado.utimestamp != 0 - AND tagente.id_os = $id_os - group by tagente.id_agente"; - - return db_get_sql ("SELECT COUNT(*) FROM ( SELECT DISTINCT tagente.id_agente - FROM tagente, tagente_modulo, tagente_estado - WHERE tagente.id_agente = tagente_modulo.id_agente - AND tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo - - AND tagente.id_os = $id_os - AND tagente.id_agente NOT IN ($agents_critical) - AND tagente.id_agente NOT IN ($agents_warning) - AND tagente.id_agente IN ($agents_unknown) ) AS t"); - + return db_get_sql ("SELECT COUNT(*) FROM tagente WHERE critical_count=0 AND warning_count=0 AND unknown_count>0 AND id_os=$id_os"); } ?> diff --git a/pandora_console/include/functions_treeview.php b/pandora_console/include/functions_treeview.php index d8377b610a..3fc3ed3390 100755 --- a/pandora_console/include/functions_treeview.php +++ b/pandora_console/include/functions_treeview.php @@ -201,21 +201,7 @@ function treeview_printTree($type) { $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 tagente.id_grupo - FROM tagente, tagente_estado - WHERE tagente.id_agente = tagente_estado.id_agente AND - tagente_estado.utimestamp != 0 - UNION - SELECT tagente.id_grupo - FROM tagente - WHERE disabled = 0 - AND id_agente NOT IN (SELECT tagente.id_agente - FROM tagente, tagente_modulo - WHERE tagente.id_agente = tagente_modulo.id_agente - AND tagente.disabled = 0 - AND tagente_modulo.disabled = 0 - group by tagente.id_agente - having COUNT(*) > 0)"); + $full_groups = db_get_all_rows_sql("SELECT DISTINCT id_grupo FROM tagente WHERE total_count > 0"); $fgroups = array(); @@ -302,9 +288,7 @@ function treeview_printTree($type) { default: case 'os': //Skip agent with all modules in not init status - - $sql_search .= " AND id_agente NOT IN (SELECT tagente_estado.id_agente FROM - tagente_estado GROUP BY id_agente HAVING SUM(utimestamp) = 0)"; + $sql_search .= " AND total_count<>notinit_count"; $sql = agents_get_agents(array ( 'order' => 'nombre COLLATE utf8_general_ci ASC', @@ -343,9 +327,7 @@ function treeview_printTree($type) { break; case 'module_group': //Skip agents which only have not init modules - $sql_search .= " AND id_agente NOT IN (SELECT tagente_estado.id_agente FROM - tagente_estado GROUP BY id_agente HAVING SUM(utimestamp) = 0)"; - + $sql_search .= " AND total_count<>notinit_count"; $sql = agents_get_agents(array ( 'order' => 'nombre COLLATE utf8_general_ci ASC', 'disabled' => 0, @@ -357,14 +339,7 @@ function treeview_printTree($type) { true); // Skip agents without modules - $sql .= ' AND id_agente IN - (SELECT tagente.id_agente - FROM tagente, tagente_modulo - WHERE tagente.id_agente = tagente_modulo.id_agente - AND tagente.disabled = 0 - AND tagente_modulo.disabled = 0 - GROUP BY tagente.id_agente - HAVING COUNT(*) > 0)'; + $sql .= ' AND tagente.total_count>0'; $sql_module_groups = sprintf("SELECT * FROM tmodule_group WHERE id_mg IN (SELECT id_module_group FROM tagente_modulo WHERE id_agente IN (%s))", $sql); @@ -599,7 +574,7 @@ function treeview_printTree($type) { $id = $item['id_os']; $name = $item['name']; $iconImg = html_print_image(str_replace('.png' ,'_small.png', ui_print_os_icon ($item['id_os'], false, true, false)) . " ", true); - $numh_ok = os_agents_ok($id); + $num_ok = os_agents_ok($id); $num_critical = os_agents_critical($id); $num_warning = os_agents_warning($id); $num_unknown = os_agents_unknown($id); diff --git a/pandora_console/operation/tree.php b/pandora_console/operation/tree.php index b574bc46f0..8304d5e5fa 100644 --- a/pandora_console/operation/tree.php +++ b/pandora_console/operation/tree.php @@ -90,9 +90,7 @@ if (is_ajax ()) case 'group': //Skip agents which only have not init modules - - $search_sql .= " AND id_agente NOT IN (SELECT tagente_estado.id_agente FROM - tagente_estado GROUP BY id_agente HAVING SUM(utimestamp) = 0)"; + $search_sql .= " AND total_count<>notinit_count"; $sql = agents_get_agents(array ( 'order' => 'nombre COLLATE utf8_general_ci ASC', @@ -107,10 +105,8 @@ if (is_ajax ()) break; case 'os': - //Skip agents which only have not init modules - - $search_sql .= " AND id_agente NOT IN (SELECT tagente_estado.id_agente FROM - tagente_estado GROUP BY id_agente HAVING SUM(utimestamp) = 0)"; + //Skip agents which only have not init modules + $search_sql .= " AND total_count<>notinit_count"; $sql = agents_get_agents(array ( @@ -126,13 +122,8 @@ if (is_ajax ()) break; case 'module_group': - //Skip agents which only have not init modules - - $search_sql .= " AND id_agente NOT IN (SELECT tagente_estado.id_agente FROM tagente_estado - WHERE id_agente_modulo IN - (SELECT id_agente_modulo FROM tagente_modulo - WHERE id_module_group = $id) - GROUP BY id_agente HAVING SUM(utimestamp) = 0)"; + //Skip agents which only have not init modules + $search_sql .= " AND total_count<>notinit_count"; $sql = agents_get_agents(array ( 'order' => 'nombre COLLATE utf8_general_ci ASC', @@ -145,14 +136,10 @@ if (is_ajax ()) true); // Skip agents without modules - $sql .= ' AND id_agente IN - (SELECT tagente.id_agente - FROM tagente, tagente_modulo - WHERE tagente.id_agente = tagente_modulo.id_agente - AND id_module_group = ' . $id . ' AND tagente.disabled = 0 - AND tagente_modulo.disabled = 0 - group by tagente.id_agente - having COUNT(*) > 0)'; + $sql .= ' AND total_count>0 AND disabled=0 AND id_agente IN + (SELECT DISTINCT (id_agente) + FROM tagente_modulo + WHERE id_module_group = ' . $id . ')'; break; case 'policies': @@ -221,10 +208,11 @@ if (is_ajax ()) } $sql .= ' AND tagente.disabled = 0'. $search_sql; - - $countRows = db_get_num_rows($sql); } - + + $rows = db_get_all_rows_sql($sql); + $countRows = count ($rows); + //Empty Branch if ($countRows === 0) { echo "
    \n"; @@ -240,116 +228,21 @@ if (is_ajax ()) } //Branch with items - $new = true; $count = 0; echo "
      \n"; - while($row = db_get_all_row_by_steps_sql($new, $result, $sql)) { - $new = false; + foreach ($rows as $row) { $count++; - switch ($type) { - case 'group': - case 'os': - $agent_info["monitor_alertsfired"] = agents_get_alerts_fired ($row["id_agente"], array("disabled" => 0)); - - $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"] = agents_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 'policies': - - $filter = "tagente_modulo.id_policy_module = 0"; - - if ($id) { - $filter = "tagente_modulo.id_policy_module = " . $id . " "; - } - - $filter .= " AND tagente_modulo.disabled = 0 "; - - $agent_info["monitor_alertsfired"] = agents_get_alerts_fired ($row["id_agente"], $filter); - - $agent_info["monitor_critical"] = agents_monitor_critical ($row["id_agente"], $filter); - $agent_info["monitor_warning"] = agents_monitor_warning ($row["id_agente"], $filter); - $agent_info["monitor_unknown"] = agents_monitor_unknown ($row["id_agente"], $filter); - $agent_info["monitor_normal"] = agents_monitor_ok ($row["id_agente"], $filter); - - $agent_info["alert_img"] = agents_tree_view_alert_img ($agent_info["monitor_alertsfired"]); - - $agent_info["status_img"] = agents_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_group': - $agent_info["monitor_alertsfired"] = agents_get_alerts_fired ($row["id_agente"], "id_module_group = $id AND disabled = 0"); - - $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"] = agents_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"]) { - case "mysql": - $agent_info["monitor_alertsfired"] = agents_get_alerts_fired ($row["id_agente"], ' tagente_modulo.nombre COLLATE utf8_general_ci = "' . $name . '" AND disabled = 0'); - $agent_info["monitor_critical"] = agents_monitor_critical($row["id_agente"], ' tagente_modulo.nombre COLLATE utf8_general_ci = "' . $name . '"'); - $agent_info["monitor_warning"] = agents_monitor_warning ($row["id_agente"], ' tagente_modulo.nombre COLLATE utf8_general_ci = "' . $name . '"'); - $agent_info["monitor_unknown"] = agents_monitor_unknown ($row["id_agente"], ' tagente_modulo.nombre COLLATE utf8_general_ci = "' . $name . '"'); - $agent_info["monitor_normal"] = agents_monitor_ok ($row["id_agente"], ' tagente_modulo.nombre COLLATE utf8_general_ci = "' . $name . '"'); - - $agent_info["alert_img"] = agents_tree_view_alert_img ($agent_info["monitor_alertsfired"]); - - $agent_info["status_img"] = agents_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 "postgresql": - case "oracle": - //TODO REVIEW ORACLE AND POSTGRESQL - $agent_info["monitor_alertsfired"] = agents_get_alerts_fired ($row["id_agente"], ' tagente_modulo.nombre = \'' . $name . '\' AND disabled = 0'); - $agent_info["monitor_critical"] = agents_monitor_critical($row["id_agente"], ' tagente_modulo.nombre = \'' . $name . '\''); - $agent_info["monitor_warning"] = agents_monitor_warning ($row["id_agente"], ' tagente_modulo.nombre = \'' . $name . '\''); - $agent_info["monitor_unknown"] = agents_monitor_unknown ($row["id_agente"], ' tagente_modulo.nombre = \'' . $name . '\''); - $agent_info["monitor_normal"] = agents_monitor_ok ($row["id_agente"], ' tagente_modulo.nombre = \'' . $name . '\''); - - $agent_info["alert_img"] = agents_tree_view_alert_img ($agent_info["monitor_alertsfired"]); - - $agent_info["status_img"] = agents_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; - } + + $agent_info["monitor_alertsfired"] = $row["fired_count"]; + $agent_info["monitor_critical"] = $row["critical_count"]; + $agent_info["monitor_warning"] = $row["warning_count"]; + $agent_info["monitor_unknown"] = $row["unknown_count"]; + $agent_info["monitor_normal"] = $row["normal_count"]; + $agent_info["modules"] = $row["total_count"]; + + $agent_info["alert_img"] = agents_tree_view_alert_img ($agent_info["monitor_alertsfired"]); + $agent_info["status_img"] = agents_tree_view_status_img ($agent_info["monitor_critical"], $agent_info["monitor_warning"], $agent_info["monitor_unknown"]); // Filter by status (only in policy view) if ($type == 'policies') { @@ -497,8 +390,10 @@ if (is_ajax ()) } // This line checks for initializated modules or (non-initialized) asyncronous modules $sql .= ' AND disabled = 0 AND (utimestamp > 0 OR id_tipo_modulo IN (21,22,23))'; - $countRows = db_get_num_rows($sql); - + + $rows = db_get_all_rows_sql($sql); + $countRows = count ($rows); + if ($countRows === 0) { echo "
        \n"; echo "
      • "; @@ -526,11 +421,9 @@ if (is_ajax ()) return; } - $new = true; $count = 0; echo "
          \n"; - while ($row = db_get_all_row_by_steps_sql($new, $result, $sql)) { - $new = false; + foreach ($rows as $row) { $count++; echo "
        • "; diff --git a/pandora_console/pandoradb.oracle.sql b/pandora_console/pandoradb.oracle.sql index c31b12cb21..2dedaa292d 100644 --- a/pandora_console/pandoradb.oracle.sql +++ b/pandora_console/pandoradb.oracle.sql @@ -85,7 +85,8 @@ CREATE TABLE tagente ( critical_count NUMBER(20, 0) default 0 NOT NULL, unknown_count NUMBER(20, 0) default 0 NOT NULL, notinit_count NUMBER(20, 0) default 0 NOT NULL, - total_count NUMBER(20, 0) default 0 NOT NULL + total_count NUMBER(20, 0) default 0 NOT NULL, + fired_count NUMBER(20, 0) default 0 NOT NULL ); CREATE INDEX tagente_nombre_idx ON tagente(nombre); CREATE INDEX tagente_direccion_idx ON tagente(direccion); diff --git a/pandora_console/pandoradb.postgreSQL.sql b/pandora_console/pandoradb.postgreSQL.sql index 5fa48bc92c..361a66335d 100644 --- a/pandora_console/pandoradb.postgreSQL.sql +++ b/pandora_console/pandoradb.postgreSQL.sql @@ -83,7 +83,8 @@ CREATE TABLE "tagente" ( "critical_count" INTEGER NOT NULL default 0, "unknown_count" INTEGER NOT NULL default 0, "notinit_count" INTEGER NOT NULL default 0, - "total_count" INTEGER NOT NULL default 0 + "total_count" INTEGER NOT NULL default 0, + "fired_count" INTEGER NOT NULL default 0 ); CREATE INDEX "tagente_nombre_idx" ON "tagente"("nombre"); CREATE INDEX "tagente_direccion_idx" ON "tagente"("direccion"); diff --git a/pandora_console/pandoradb.sql b/pandora_console/pandoradb.sql index 4ab62b7558..4f73a54129 100644 --- a/pandora_console/pandoradb.sql +++ b/pandora_console/pandoradb.sql @@ -77,6 +77,7 @@ CREATE TABLE IF NOT EXISTS `tagente` ( `unknown_count` bigint(20) unsigned NOT NULL default '0', `notinit_count` bigint(20) unsigned NOT NULL default '0', `total_count` bigint(20) unsigned NOT NULL default '0', + `fired_count` bigint(20) unsigned NOT NULL default '0', PRIMARY KEY (`id_agente`), KEY `nombre` (`nombre`), KEY `direccion` (`direccion`),