From f3312d5da02850b4f6ffd808b1775b4e8c53e87d Mon Sep 17 00:00:00 2001 From: ramonn <noreply@pandorafms.org> Date: Fri, 21 Dec 2012 14:53:11 +0000 Subject: [PATCH] 2012-12-21 Ramon Novoa <rnovoa@artica.es> * godmode/agentes/agent_template.php, godmode/agentes/configurar_agente.php, godmode/agentes/module_manager.php, include/functions_modules.php: Implemented a real not-init status. Small fixes. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@7325 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_console/ChangeLog | 8 ++++ .../godmode/agentes/agent_template.php | 15 ++++++- .../godmode/agentes/configurar_agente.php | 7 ++-- .../godmode/agentes/module_manager.php | 7 ++-- pandora_console/include/functions_modules.php | 41 +++++++++++++------ 5 files changed, 57 insertions(+), 21 deletions(-) diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index bec6bd6145..87f5dd3b55 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,11 @@ +2012-12-21 Ramon Novoa <rnovoa@artica.es> + + * godmode/agentes/agent_template.php, + godmode/agentes/configurar_agente.php, + godmode/agentes/module_manager.php, + include/functions_modules.php: Implemented a real not-init status. + Small fixes. + 2012-12-21 Sergio Martin <sergio.martin@artica.es> * include/functions_ui.php diff --git a/pandora_console/godmode/agentes/agent_template.php b/pandora_console/godmode/agentes/agent_template.php index 8045a56095..86a68c0b89 100644 --- a/pandora_console/godmode/agentes/agent_template.php +++ b/pandora_console/godmode/agentes/agent_template.php @@ -95,19 +95,30 @@ if (isset ($_POST["template_id"])) { ); $id_agente_modulo = db_process_sql_insert('tagente_modulo', $values); + // Set the initial module status + if ($row2["type"] == 21 || $row2["type"] == 22 || $row2["type"] == 23) { + $status = 0; + } else { + $status = 4; + } + // Create with different estado if proc type or data type if ($id_agente_modulo !== false) { $values = array( 'id_agente_modulo' => $id_agente_modulo, 'datos' => 0, 'timestamp' => '01-01-1970 00:00:00', - 'estado' => 0, + 'estado' => $status, '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); + if ($status == 4) { + db_process_sql ('UPDATE tagente SET total_count=total_count+1, notinit_count=notinit_count+1 WHERE id_agente=' . (int)$id_agente); + } else { + db_process_sql ('UPDATE tagente SET total_count=total_count+1, normal_count=normal_count+1 WHERE id_agente=' . (int)$id_agente); + } } else { echo '<h3 class="error">'.__('Error adding module').'</h3>'; diff --git a/pandora_console/godmode/agentes/configurar_agente.php b/pandora_console/godmode/agentes/configurar_agente.php index b06bb917cf..72b56673de 100644 --- a/pandora_console/godmode/agentes/configurar_agente.php +++ b/pandora_console/godmode/agentes/configurar_agente.php @@ -1078,9 +1078,7 @@ if ($delete_module) { // DELETE agent module ! $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) { + 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']); @@ -1088,7 +1086,10 @@ if ($delete_module) { // DELETE agent module ! 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']); + } else if ($module_data['estado'] == 4) { + db_process_sql ('UPDATE tagente SET notinit_count=notinit_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']); } diff --git a/pandora_console/godmode/agentes/module_manager.php b/pandora_console/godmode/agentes/module_manager.php index b72bcb794f..df5f4dee3a 100644 --- a/pandora_console/godmode/agentes/module_manager.php +++ b/pandora_console/godmode/agentes/module_manager.php @@ -140,9 +140,7 @@ if ($multiple_delete) { 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) { + 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']); @@ -150,7 +148,10 @@ if ($multiple_delete) { 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']); + } else if ($module['estado'] == 4) { + db_process_sql ('UPDATE tagente SET notinit_count=notinit_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']); } } diff --git a/pandora_console/include/functions_modules.php b/pandora_console/include/functions_modules.php index 3013457d9c..1027317b76 100644 --- a/pandora_console/include/functions_modules.php +++ b/pandora_console/include/functions_modules.php @@ -218,9 +218,7 @@ function modules_delete_agent_module ($id_agent_module) { 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) { + 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']); @@ -228,6 +226,8 @@ function modules_delete_agent_module ($id_agent_module) { 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']); + } else if ($module['estado'] == 4) { + db_process_sql ('UPDATE tagente SET notinit_count=notinit_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']); @@ -337,18 +337,26 @@ function modules_create_agent_module ($id_agent, $name, $values = false, $disabl return ERR_DB; } - + + if (isset ($values['id_tipo_modulo']) && ($values['id_tipo_modulo'] == 21 || $values['id_tipo_modulo'] == 22 || $values['id_tipo_modulo'] == 23)) { + // Async modules start in normal status + $status = 0; + } else { + // Sync modules start in unknown status + $status = 4; + } switch ($config["dbtype"]) { case "mysql": $result = db_process_sql_insert ('tagente_estado', array ('id_agente_modulo' => $id_agent_module, 'datos' => 0, 'timestamp' => '01-01-1970 00:00:00', - 'estado' => 0, + 'estado' => $status, 'id_agente' => (int) $id_agent, 'utimestamp' => 0, 'status_changes' => 0, - 'last_status' => 0 + 'last_status' => $status, + 'last_known_status' => $status )); break; case "postgresql": @@ -356,11 +364,12 @@ function modules_create_agent_module ($id_agent, $name, $values = false, $disabl array ('id_agente_modulo' => $id_agent_module, 'datos' => 0, 'timestamp' => null, - 'estado' => 0, + 'estado' => $status, 'id_agente' => (int) $id_agent, 'utimestamp' => 0, 'status_changes' => 0, - 'last_status' => 0 + 'last_status' => $status, + 'last_known_status' => $status )); break; case "oracle": @@ -368,11 +377,12 @@ function modules_create_agent_module ($id_agent, $name, $values = false, $disabl array ('id_agente_modulo' => $id_agent_module, 'datos' => 0, 'timestamp' => '#to_date(\'1970-01-01 00:00:00\', \'YYYY-MM-DD HH24:MI:SS\')', - 'estado' => 0, + 'estado' => $status, 'id_agente' => (int) $id_agent, 'utimestamp' => 0, 'status_changes' => 0, - 'last_status' => 0 + 'last_status' => $status, + 'last_known_status' => $status )); break; } @@ -385,7 +395,12 @@ function modules_create_agent_module ($id_agent, $name, $values = false, $disabl } // 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); + if ($status == 0) { + db_process_sql ('UPDATE tagente SET total_count=total_count+1, normal_count=normal_count+1 WHERE id_agente=' . (int)$id_agent); + } else { + 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; } @@ -1335,8 +1350,8 @@ function modules_get_status($id_agent_module, $db_status, $data, &$status, &$tit $title = ""; // This module is initialized ? (has real data) - $module_init = db_get_value ('utimestamp', 'tagente_estado', 'id_agente_modulo', $id_agent_module); - if ($module_init == 0) { + //$module_init = db_get_value ('utimestamp', 'tagente_estado', 'id_agente_modulo', $id_agent_module); + if ($db_status == 4) { $status = STATUS_MODULE_NO_DATA; $title = __('NOT INIT'); }