diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index 53442a9979..b88e6c7a3f 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,20 @@ +2012-11-14 Ramon Novoa + + * include/functions_modules.php, + pandoradb.sql, + pandoradb.postgreSQL.sql, + pandoradb.oracle.sql, + 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, + godmode/agentes/agent_template.php, + godmode/agentes/module_manager.php, + godmode/agentes/agent_manager.php: Added support for server-side + module status calculation. + + * godmode/agentes/configurar_agente.php: Show 'None' when no server is + selected for an agent. + 2012-11-13 Miguel de Dios * godmode/reporting/reporting_builder.php, 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 dceab04653..225ca8bf4f 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 @@ -58,6 +58,13 @@ ALTER TABLE `tincidencia` ADD COLUMN `id_agent` int(10) unsigned NULL default 0; -- --------------------------------------------------------------------- ALTER TABLE `tagente` ADD COLUMN `url_address` mediumtext NULL; ALTER TABLE `tagente` ADD COLUMN `quiet` tinyint(1) NOT NULL DEFAULT '0'; +ALTER TABLE `tagente` ADD COLUMN `normal_count` bigint(20) unsigned NOT NULL default '0'; +ALTER TABLE `tagente` ADD COLUMN `warning_count` bigint(20) unsigned NOT NULL default '0'; +ALTER TABLE `tagente` ADD COLUMN `critical_count` bigint(20) unsigned NOT NULL default '0'; +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 `critical_count` bigint(20) unsigned NOT NULL default '0'; +ALTER TABLE `tagente` ADD COLUMN `total_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 bb5750d5d5..bea9c05fc8 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 @@ -77,6 +77,12 @@ ALTER TABLE tincidencia ADD (id_agent NUMBER(10,0) default 0 NULL); -- ----------------------------------------------------- ALTER TABLE tagente ADD (url_address CLOB default '' NULL); ALTER TABLE tagente ADD (quiet NUMBER(5, 0) default 0 NOT NULL); +ALTER TABLE tagente ADD (normal_count NUMBER(20, 0) default 0 NOT NULL); +ALTER TABLE tagente ADD (warning_count NUMBER(20, 0) default 0 NOT NULL); +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); -- ----------------------------------------------------- -- 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 9afc656f5e..b81ce16005 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 @@ -71,6 +71,12 @@ ALTER TABLE "tincidencia" ADD COLUMN "id_agent" INTEGER NULL DEFAULT 0; -- ----------------------------------------------------- ALTER TABLE "tagente" ADD COLUMN "url_address" text NULL default ''; ALTER TABLE "tagente" ADD COLUMN "quiet" SMALLINT NOT NULL default 0; +ALTER TABLE "tagente" ADD COLUMN "normal_count" INTEGER NOT NULL default 0; +ALTER TABLE "tagente" ADD COLUMN "warning_count" INTEGER NOT NULL default 0; +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; -- ----------------------------------------------------- -- Table "talert_special_days" diff --git a/pandora_console/godmode/agentes/agent_manager.php b/pandora_console/godmode/agentes/agent_manager.php index 53db670a45..5925b18ed3 100644 --- a/pandora_console/godmode/agentes/agent_manager.php +++ b/pandora_console/godmode/agentes/agent_manager.php @@ -213,12 +213,9 @@ $table->data[5][1] .= ui_print_os_icon ($id_os, false, true); $table->data[5][1] .= ''; // Network server -$none = ''; -if ($server_name == '' && $id_agente) - $none = __('None'); $table->data[6][0] = __('Server'); $table->data[6][1] = html_print_select (servers_get_names (), - 'server_name', $server_name, '', $none, 0, true); + 'server_name', $server_name, '', __('None'), 0, true); // Description $table->data[7][0] = __('Description'); diff --git a/pandora_console/godmode/agentes/agent_template.php b/pandora_console/godmode/agentes/agent_template.php index 9cd633ba69..8045a56095 100644 --- a/pandora_console/godmode/agentes/agent_template.php +++ b/pandora_console/godmode/agentes/agent_template.php @@ -105,6 +105,9 @@ if (isset ($_POST["template_id"])) { 'id_agente' => $id_agente, 'utimestamp' => 0); db_process_sql_insert('tagente_estado', $values); + + // Update module status count + db_process_sql ('UPDATE tagente SET total_count=total_count+1, notinit_count=notinit_count+1 WHERE id_agente=' . (int)$id_agente); } else { echo '

'.__('Error adding module').'

'; diff --git a/pandora_console/godmode/agentes/configurar_agente.php b/pandora_console/godmode/agentes/configurar_agente.php index 0b3208780c..b5c9135e2a 100644 --- a/pandora_console/godmode/agentes/configurar_agente.php +++ b/pandora_console/godmode/agentes/configurar_agente.php @@ -1036,7 +1036,7 @@ if ($create_module) { // ================= if ($delete_module) { // DELETE agent module ! $id_borrar_modulo = (int) get_parameter_get ("delete_module",0); - $module_data = db_get_row ('tagente_modulo', 'id_agente_modulo', $id_borrar_modulo); + $module_data = db_get_row_sql ('SELECT * FROM tagente_modulo, tagente_estado WHERE tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo AND tagente_modulo.id_agente_modulo=' . $id_borrar_modulo); $id_grupo = (int) agents_get_agent_group($id_agente); if (! check_acl ($config["id_user"], $id_grupo, "AW")) { @@ -1069,8 +1069,23 @@ if ($delete_module) { // DELETE agent module ! 'disabled' => 1, 'delete_pending' => 1); $result = db_process_sql_update('tagente_modulo', $values, array('id_agente_modulo' => $id_borrar_modulo)); - if ($result === false) + if ($result === false) { $error++; + } else { + // Update module status count + if ($module_data['utimestamp'] == 0) { + db_process_sql ('UPDATE tagente SET notinit_count=notinit_count-1 WHERE id_agente=' . $module_data['id_agente']); + } else if ($module_data['estado'] == 0) { + db_process_sql ('UPDATE tagente SET normal_count=normal_count-1 WHERE id_agente=' . $module_data['id_agente']); + } else if ($module_data['estado'] == 1) { + db_process_sql ('UPDATE tagente SET critical_count=critical_count-1 WHERE id_agente=' . $module_data['id_agente']); + } else if ($module_data['estado'] == 2) { + db_process_sql ('UPDATE tagente SET warning_count=warning_count-1 WHERE id_agente=' . $module_data['id_agente']); + } else if ($module_data['estado'] == 3) { + db_process_sql ('UPDATE tagente SET unknown_count=unknown_count-1 WHERE id_agente=' . $module_data['id_agente']); + } + db_process_sql ('UPDATE tagente SET total_count=total_count-1 WHERE id_agente=' . $module_data['id_agente']); + } $result = db_process_sql_delete('tagente_estado', array('id_agente_modulo' => $id_borrar_modulo)); if ($result === false) diff --git a/pandora_console/godmode/agentes/module_manager.php b/pandora_console/godmode/agentes/module_manager.php index 1637798301..35b52438fa 100644 --- a/pandora_console/godmode/agentes/module_manager.php +++ b/pandora_console/godmode/agentes/module_manager.php @@ -132,9 +132,27 @@ if ($multiple_delete) { // error. NOTICE that we don't delete all data here, just marking for deletion // and delete some simple data. $status = ''; + $module = db_get_row_sql ('SELECT * FROM tagente_modulo, tagente_estado WHERE tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo AND tagente_modulo.id_agente_modulo=' . (int)$id_agent_module_del); if (db_process_sql("UPDATE tagente_modulo - SET nombre = 'pendingdelete', disabled = 1, delete_pending = 1 WHERE id_agente_modulo = ".$id_agent_module_del, "affected_rows", '', true, $status, false) === false) + SET nombre = 'pendingdelete', disabled = 1, delete_pending = 1 WHERE id_agente_modulo = ".$id_agent_module_del, "affected_rows", '', true, $status, false) === false) { $error++; + } else { + // Update module status count + if ($module !== false) { + if ($module['utimestamp'] == 0) { + db_process_sql ('UPDATE tagente SET notinit_count=notinit_count-1 WHERE id_agente=' . $module['id_agente']); + } else if ($module['estado'] == 0) { + db_process_sql ('UPDATE tagente SET normal_count=normal_count-1 WHERE id_agente=' . $module['id_agente']); + } else if ($module['estado'] == 1) { + db_process_sql ('UPDATE tagente SET critical_count=critical_count-1 WHERE id_agente=' . $module['id_agente']); + } else if ($module['estado'] == 2) { + db_process_sql ('UPDATE tagente SET warning_count=warning_count-1 WHERE id_agente=' . $module['id_agente']); + } else if ($module['estado'] == 3) { + db_process_sql ('UPDATE tagente SET unknown_count=unknown_count-1 WHERE id_agente=' . $module['id_agente']); + } + db_process_sql ('UPDATE tagente SET total_count=total_count-1 WHERE id_agente=' . $module['id_agente']); + } + } switch ($config["dbtype"]) { case "mysql": @@ -610,4 +628,4 @@ html_print_input_hidden ('multiple_delete', 1); html_print_submit_button (__('Delete'), 'multiple_delete', false, 'class="sub delete"'); echo ''; echo '' -?> \ No newline at end of file +?> diff --git a/pandora_console/include/functions_modules.php b/pandora_console/include/functions_modules.php index 7aa4f9035c..2afdaca9c8 100644 --- a/pandora_console/include/functions_modules.php +++ b/pandora_console/include/functions_modules.php @@ -197,6 +197,9 @@ function modules_copy_agent_module_to_agent ($id_agent_module, $id_destiny_agent function modules_delete_agent_module ($id_agent_module) { if (!$id_agent_module) return false; + + // Read module data + $module = db_get_row_sql ('SELECT * FROM tagente_modulo, tagente_estado WHERE tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo AND tagente_modulo.id_agente_modulo=' . (int)$id_agent_module); $where = array ('id_agent_module' => $id_agent_module); @@ -214,6 +217,20 @@ function modules_delete_agent_module ($id_agent_module) { $where); db_process_sql_delete('ttag_module', $where); + // Update module status count + if ($module['utimestamp'] == 0) { + db_process_sql ('UPDATE tagente SET notinit_count=notinit_count-1 WHERE id_agente=' . $module['id_agente']); + } else if ($module['estado'] == 0) { + db_process_sql ('UPDATE tagente SET normal_count=normal_count-1 WHERE id_agente=' . $module['id_agente']); + } else if ($module['estado'] == 1) { + db_process_sql ('UPDATE tagente SET critical_count=critical_count-1 WHERE id_agente=' . $module['id_agente']); + } else if ($module['estado'] == 2) { + db_process_sql ('UPDATE tagente SET warning_count=warning_count-1 WHERE id_agente=' . $module['id_agente']); + } else if ($module['estado'] == 3) { + db_process_sql ('UPDATE tagente SET unknown_count=unknown_count-1 WHERE id_agente=' . $module['id_agente']); + } + db_process_sql ('UPDATE tagente SET total_count=total_count-1 WHERE id_agente=' . $module['id_agente']); + return true; } @@ -366,7 +383,10 @@ function modules_create_agent_module ($id_agent, $name, $values = false, $disabl return ERR_DB; } - + + // Update module status count + db_process_sql ('UPDATE tagente SET total_count=total_count+1, notinit_count=notinit_count+1 WHERE id_agente=' . (int)$id_agent); + return $id_agent_module; } diff --git a/pandora_console/pandoradb.oracle.sql b/pandora_console/pandoradb.oracle.sql index da7c8701f1..c31b12cb21 100644 --- a/pandora_console/pandoradb.oracle.sql +++ b/pandora_console/pandoradb.oracle.sql @@ -79,7 +79,13 @@ CREATE TABLE tagente ( --set it to one to update the position data (altitude, longitude, latitude) when getting information from the agent or to 0 to keep the last value and don\'t update it update_gis_data NUMBER(5, 0) DEFAULT 1 NOT NULL, url_address CLOB DEFAULT '' NULL, - quiet NUMBER(5, 0) default 0 NOT NULL + quiet NUMBER(5, 0) default 0 NOT NULL, + normal_count NUMBER(20, 0) default 0 NOT NULL, + warning_count NUMBER(20, 0) default 0 NOT NULL, + 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 ); 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 18fd5796b7..5fa48bc92c 100644 --- a/pandora_console/pandoradb.postgreSQL.sql +++ b/pandora_console/pandoradb.postgreSQL.sql @@ -77,7 +77,13 @@ CREATE TABLE "tagente" ( --set it to one to update the position data (altitude, longitude, latitude) when getting information from the agent or to 0 to keep the last value and don\'t update it "update_gis_data" SMALLINT NOT NULL DEFAULT 1, "url_address" TEXT NULL default '', - "quiet" SMALLINT NOT NULL default 0 + "quiet" SMALLINT NOT NULL default 0, + "normal_count" INTEGER NOT NULL default 0, + "warning_count" INTEGER NOT NULL default 0, + "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 ); 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 4fd746c891..4ab62b7558 100644 --- a/pandora_console/pandoradb.sql +++ b/pandora_console/pandoradb.sql @@ -71,6 +71,12 @@ CREATE TABLE IF NOT EXISTS `tagente` ( `update_gis_data` TINYINT(1) NOT NULL DEFAULT '1' COMMENT 'set it to one to update the position data (altitude, longitude, latitude) when getting information from the agent or to 0 to keep the last value and do not update it' , `url_address` mediumtext NULL, `quiet` tinyint(1) NOT NULL default '0', + `normal_count` bigint(20) unsigned NOT NULL default '0', + `warning_count` bigint(20) unsigned NOT NULL default '0', + `critical_count` bigint(20) unsigned NOT NULL default '0', + `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', PRIMARY KEY (`id_agente`), KEY `nombre` (`nombre`), KEY `direccion` (`direccion`),