From 068b17029eea7058a313f72be246c7098972b707 Mon Sep 17 00:00:00 2001 From: Esteban Sanchez Date: Tue, 2 Dec 2008 08:11:42 +0000 Subject: [PATCH] 2008-12-02 Esteban Sanchez * godmode/agentes/manage_config.php: Fixed SQL sentence generation when copying a module. It was causing PHP notices and nothing was being copied. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1272 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_console/ChangeLog | 6 + .../godmode/agentes/manage_config.php | 133 +++++++++++------- 2 files changed, 88 insertions(+), 51 deletions(-) diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index e6aeb58714..848bd5130c 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,9 @@ +2008-12-02 Esteban Sanchez + + * godmode/agentes/manage_config.php: Fixed SQL sentence generation + when copying a module. It was causing PHP notices and nothing was + being copied. + 2008-12-01 Jorge Gonzalez * include/languages/index.pot: Updated po template. diff --git a/pandora_console/godmode/agentes/manage_config.php b/pandora_console/godmode/agentes/manage_config.php index 62d7eb750e..3735544f6b 100644 --- a/pandora_console/godmode/agentes/manage_config.php +++ b/pandora_console/godmode/agentes/manage_config.php @@ -90,31 +90,62 @@ if (isset($_POST["copy"])) { if ($modulos == 1) { echo '

'.__('Copying module').' ['.dame_nombre_agente ($origen).' - '.$module["nombre"].'] -> ['.dame_nombre_agente ($id_agent_dest).']'; - $sql = sprintf ("INSERT INTO tagente_modulo - (id_agente, id_tipo_modulo, descripcion, nombre, max, min, module_interval, tcp_port, tcp_send, tcp_rcv, - snmp_community, snmp_oid, ip_target, id_module_group, flag, id_modulo, disabled, id_export, - plugin_user, plugin_pass, plugin_parameter, id_plugin, post_process, prediction_module, max_timeout) - VALUES (%d,".$module["id_tipo_modulo"].",'".$module["descripcion"]."','".$module["nombre"]."',".$module["max"].",".$module["min"].",".$module["module_interval"].",".$module["tcp_port"].",'".$module["tcp_send"]."','".$module["tcp_rcv"]."', - '".$module["snmp_community"]."','".$module["snmp_oid"]."','%s',".$module["id_module_group"].",".$module["flag"].",".$module["id_modulo"].",".$module["disabled"].",".$module["id_export"].", - '".$module["plugin_user"]."','".$module["plugin_pass"]."','".$module["plugin_parameter"]."',".$module["id_plugin"].",'".$module["post_process"]."',".$module["prediction_module"].",".$module["max_timeout"].")", - $id_agent_dest,get_agent_address ($id_agent_dest)); - + $sql = sprintf ('INSERT INTO tagente_modulo + (id_agente, id_tipo_modulo, descripcion, + nombre, max, min, module_interval, + tcp_port, tcp_send, tcp_rcv, + snmp_community, snmp_oid, ip_target, + id_module_group, flag, id_modulo, + disabled, id_export, + plugin_user, plugin_pass, + plugin_parameter, id_plugin, + post_process, prediction_module, + max_timeout) + VALUES (%d, %d, "%s", "%s", %f, %f, %d, + %d, "%s", "%s", "%s", "%s", "%s", %d, + %d, %d, %d, %d, "%s", "%s", "%s", %d, + %f, %d, %d)', + $id_agent_dest, $module["id_tipo_modulo"], + $module["descripcion"], + $module["nombre"], $module["max"], + $module["min"], + $module["module_interval"], + $module["tcp_port"], + $module["tcp_send"], + $module["tcp_rcv"], + $module["snmp_community"], + $module["snmp_oid"], + get_agent_address ($id_agent_dest), + $module["id_module_group"], + $module["flag"], + $module["id_modulo"], + $module["disabled"], + $module["id_export"], + $module["plugin_user"], + $module["plugin_pass"], + $module["plugin_parameter"], + $module["id_plugin"], + $module["post_process"], + $module["prediction_module"], + $module["max_timeout"]); + $id_new_module = process_sql ($sql, "insert_id"); if (empty ($id_new_module)) { $errors++; } else { switch ($module["id_tipo_modulo"]) { - case 2: - case 6: - case 9: - case 100: - case 21: - case 18: - $sql = sprintf ("INSERT INTO tagente_estado (id_agente_modulo, datos, timestamp, cambio, estado, id_agente, utimestamp) - VALUES (%d, 0,'0000-00-00 00:00:00',0,0, %d, 0)", $id_new_module, $id_agent_dest); - default: - $sql = sprintf ("INSERT INTO tagente_estado (id_agente_modulo, datos, timestamp, cambio, estado, id_agente, utimestamp) - VALUES (%d, 0,'0000-00-00 00:00:00',0,100, %d, 0)", $id_new_module, $id_agent_dest); + case 2: + case 6: + case 9: + case 100: + case 21: + case 18: + $sql = sprintf ("INSERT INTO tagente_estado (id_agente_modulo, datos, timestamp, cambio, estado, id_agente, utimestamp) + VALUES (%d, 0,'0000-00-00 00:00:00',0,0, %d, 0)", $id_new_module, $id_agent_dest); + break; + default: + $sql = sprintf ("INSERT INTO tagente_estado (id_agente_modulo, datos, timestamp, cambio, estado, id_agente, utimestamp) + VALUES (%d, 0,'0000-00-00 00:00:00',0,100, %d, 0)", $id_new_module, $id_agent_dest); } $result = process_sql ($sql); if ($result === false) @@ -170,10 +201,10 @@ if (isset($_POST["copy"])) { $result = get_db_all_row_sql ($sql); if ($result === false) - continue; // This alert is supposed to be part of a - // compound alert but there is no entry for - // it in the tcompound_alert table so we skip this - + /* This alert is supposed to be part of a + compound alert but there is no entry for + it in the tcompound_alert table so we skip this */ + continue; foreach ($result as $comp_alert) { $sql = sprintf ("INSERT INTO tcompound_alert (id_aam, operation) VALUES (%d, '%s')",$new_alert,$comp_alert["operation"]); $result = process_sql ($sql); @@ -201,21 +232,21 @@ if (isset($_POST["copy"])) { // DELETE DATA // ----------- if (isset ($_POST["delete"])) { - echo "

".__('Agent Module Data Deletion')."

"; + echo "

".__('Agent Module Data Deletion')."

"; - if (empty ($destino)) { - echo '

ERROR: '.__('No selected agents to copy').'

'; - return; - } + if (empty ($destino)) { + echo '

ERROR: '.__('No selected agents to copy').'

'; + return; + } - if (empty ($origen_modulo)) { - echo '

ERROR: '.__('No modules have been selected').'

'; - return; - } + if (empty ($origen_modulo)) { + echo '

ERROR: '.__('No modules have been selected').'

'; + return; + } - // If selected modules or alerts + // If selected modules or alerts if (isset($_POST["alerts"])) { $alertas = 1; } else { @@ -223,23 +254,23 @@ if (isset ($_POST["delete"])) { } if (isset($_POST["modules"])) { - $modulos = 1; + $modulos = 1; $alertas = 1; - } else { - $modulos = 0; - } + } else { + $modulos = 0; + } - if (($alertas + $modulos) == 0){ - echo '

ERROR: '.__('You must check modules and/or alerts to be deleted').'

'; - return; - } + if (($alertas + $modulos) == 0){ + echo '

ERROR: '.__('You must check modules and/or alerts to be deleted').'

'; + return; + } - // Deletion - // ---- - $errors = 0; - + // Deletion + // ---- + $errors = 0; + process_sql ("SET AUTOCOMMIT = 0;"); - process_sql ("START TRANSACTION;"); //Start a transaction + process_sql ("START TRANSACTION;"); //Start a transaction function temp_sql_delete ($table, $row, $value) { global $errors; //Globalize the errors variable @@ -251,7 +282,7 @@ if (isset ($_POST["delete"])) { $errors++; } - foreach ($origen_modulo as $id_module_src) { + foreach ($origen_modulo as $id_module_src) { $nombre_src = get_db_value ("nombre", "tagente_modulo", "id_agente_modulo", $id_module_src); foreach ($destino as $agent_dest) { @@ -270,12 +301,12 @@ if (isset ($_POST["delete"])) { //Standard data temp_sql_delete ("tagente_datos", "id_agente_modulo", $id_module_dest); - //Incremental Data + //Incremental Data temp_sql_delete ("tagente_datos_inc", "id_agente_modulo", $id_module_dest); //String data - temp_sql_delete ("tagente_datos_string", "id_agente_modulo", $id_module_dest); - + temp_sql_delete ("tagente_datos_string", "id_agente_modulo", $id_module_dest); + //Events (up/down monitors) temp_sql_delete ("tevento", "id_agentmodule", $id_module_dest);