diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index d98070dc77..840631d721 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,24 @@ +2013-02-14 Sergio Martin + + * pandoradb_data.sql: Fixed the macros of the + default plugin MySQL + + * include/functions_groups.php + include/functions_api.php + include/functions_ui.php + include/functions_agents.php + include/functions_modules.php + include/constants.php + operation/agentes/estado_ultimopaquete.php + godmode/db/db_sanity.php + godmode/agentes/agent_template.php + godmode/agentes/configurar_agente.php + godmode/servers/plugin.php: Create a function to disable + modules fixing the status counts and replace the old way of + do it in all the console. Fixin a lot of old way of create + and delete modules too to use the centralized function and + dont break counts. BUG 3604463 + 2013-02-14 Miguel de Dios * include/constants.php: added constant for module type of diff --git a/pandora_console/godmode/agentes/agent_template.php b/pandora_console/godmode/agentes/agent_template.php index 917f6b6473..3fd7001d29 100644 --- a/pandora_console/godmode/agentes/agent_template.php +++ b/pandora_console/godmode/agentes/agent_template.php @@ -66,7 +66,6 @@ if (isset ($_POST["template_id"])) { 'id_agente' => $id_agente, 'id_tipo_modulo' => $row2["type"], 'descripcion' => __('Created by template ').$name_template. ' . '.$row2["description"], - 'nombre' => $row2["name"], 'max' => $row2["max"], 'min' => $row2["min"], 'module_interval' => $row2["module_interval"], @@ -98,47 +97,21 @@ if (isset ($_POST["template_id"])) { 'unknown_instructions' => $row2['unknown_instructions'] ); + $name = $row2["name"]; + // Check if this module exists in the agent - $module_name_check = db_get_value_filter('id_agente_modulo', 'tagente_modulo', array('delete_pending' => 0, 'nombre' => $row2["name"], 'id_agente' => $id_agente)); + $module_name_check = db_get_value_filter('id_agente_modulo', 'tagente_modulo', array('delete_pending' => 0, 'nombre' => $name, 'id_agente' => $id_agente)); if ($module_name_check !== false) { $modules_already_added[] = $row2["name"]; $error_count++; } else { + $id_agente_modulo = modules_create_agent_module($id_agente, $name, $values); - $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) { - $success_count++; - $values = array( - 'id_agente_modulo' => $id_agente_modulo, - 'datos' => 0, - 'timestamp' => '01-01-1970 00:00:00', - 'estado' => $status, - 'id_agente' => $id_agente, - 'utimestamp' => 0); - db_process_sql_insert('tagente_estado', $values); - - // Update module status count - 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 + if ($id_agente_modulo === false) { $error_count++; + } } } } diff --git a/pandora_console/godmode/agentes/configurar_agente.php b/pandora_console/godmode/agentes/configurar_agente.php index b862f04742..71b9224242 100644 --- a/pandora_console/godmode/agentes/configurar_agente.php +++ b/pandora_console/godmode/agentes/configurar_agente.php @@ -1234,9 +1234,9 @@ if (!empty($duplicate_module)) { // DUPLICATE agent module ! // MODULE ENABLE/DISABLE // ===================== if($enable_module) { - $result = db_process_sql_update('tagente_modulo', array('disabled' => 0), array('id_agente_modulo' => $enable_module)); + $result = modules_change_disabled($enable_module, 0); - if ($result) { + if ($result === NOERR) { db_pandora_audit("Module management", 'Enable ' . $enable_module); } else { @@ -1248,9 +1248,9 @@ if($enable_module) { } if($disable_module) { - $result = db_process_sql_update('tagente_modulo', array('disabled' => 1), array('id_agente_modulo' => $disable_module)); + $result = modules_change_disabled($disable_module, 1); - if ($result) { + if ($result === NOERR) { db_pandora_audit("Module management", 'Disable ' . $disable_module); } else { diff --git a/pandora_console/godmode/db/db_sanity.php b/pandora_console/godmode/db/db_sanity.php index d17eb788a0..e5ad3eea80 100644 --- a/pandora_console/godmode/db/db_sanity.php +++ b/pandora_console/godmode/db/db_sanity.php @@ -93,9 +93,14 @@ elseif ($sanity == 2) { modules_delete_agent_module($row['id_agente_modulo']); } + echo "Deleting bad module (id 0)
"; - db_process_sql_delete('tagente_modulo', array('id_modulo' => 0)); + $bad_modules = db_get_all_rows_filter('tagente_modulo', array('id_modulo' => 0)); + + foreach($bad_modules as $bm) { + modules_delete_agent_module ($bm['id_agente_modulo']); + } } echo "
"; diff --git a/pandora_console/godmode/servers/plugin.php b/pandora_console/godmode/servers/plugin.php index 3ae3c897f9..87dde91b2d 100644 --- a/pandora_console/godmode/servers/plugin.php +++ b/pandora_console/godmode/servers/plugin.php @@ -416,7 +416,12 @@ else { echo "

".__('Plugin deleted successfully')."

"; } if ($plugin_id != 0) { - $result = db_process_sql_delete('tagente_modulo', array('id_plugin' => $plugin_id)); + // Delete all the modules with this plugin + $plugin_modules = db_get_all_rows_filter('tagente_modulo', array('id_plugin' => $plugin_id)); + + foreach($plugin_modules as $pm) { + modules_delete_agent_module ($pm['id_agente_modulo']); + } } } @@ -454,7 +459,7 @@ else { echo $row["execute"]; echo ""; echo "" . html_print_image('images/config.png', true, array("title" => __("Edit"))) . "  "; - echo "" . html_print_image("images/cross.png", true, array("border" => '0')) . ""; + echo "" . html_print_image("images/cross.png", true, array("border" => '0')) . ""; echo ""; } echo ""; diff --git a/pandora_console/include/constants.php b/pandora_console/include/constants.php index eb26b3c057..b9666eb2eb 100644 --- a/pandora_console/include/constants.php +++ b/pandora_console/include/constants.php @@ -131,7 +131,8 @@ define('GENERIC_SIZE_TEXT', 25); /* Agent module status */ define('AGENT_MODULE_STATUS_CRITICAL_BAD', 1); -define('AGENT_MODULE_STATUS_CRITICAL_ALERT', 4); +define('AGENT_MODULE_STATUS_CRITICAL_ALERT', 100); +define('AGENT_MODULE_STATUS_NO_DATA', 4); define('AGENT_MODULE_STATUS_NORMAL', 0); define('AGENT_MODULE_STATUS_WARNING', 2); define('AGENT_MODULE_STATUS_UNKNOW', 3); @@ -228,4 +229,4 @@ define ('MODULE_SNMP', 2); define ('MODULE_PLUGIN', 4); define ('MODULE_WMI', 6); define ('MODULE_WEB', 7); -?> \ No newline at end of file +?> diff --git a/pandora_console/include/functions_agents.php b/pandora_console/include/functions_agents.php index 4f0d84d75b..1462bc44e2 100644 --- a/pandora_console/include/functions_agents.php +++ b/pandora_console/include/functions_agents.php @@ -94,38 +94,20 @@ function agents_create_agent ($name, $id_group, $interval, $ip_address, $values // Create address for this agent in taddress agents_add_address ($id_agent, $ip_address); - // Create special module agent_keepalive - $id_agent_module = db_process_sql_insert ('tagente_modulo', - array ('nombre' => 'agent_keepalive', - 'id_agente' => $id_agent, - 'id_tipo_modulo' => 100, + // Create special module agent_keepalive + $values_modules = array ('id_tipo_modulo' => 100, 'descripcion' => __('Agent keepalive monitor'), 'id_modulo' => 1, 'min_warning' => 0, - 'max_warning' => 1)); + 'max_warning' => 1); + + $id_agent_module = modules_create_agent_module($id_agent, 'agent_keepalive', $values_modules); if ($id_agent_module === false) { db_process_sql_rollback (); return false; } - $result = db_process_sql_insert ('tagente_estado', - array ('id_agente_modulo' => $id_agent_module, - 'datos' => '', - 'timestamp' => 0, - 'estado' => 0, - 'id_agente' => $id_agent, - 'last_try' => 0, - 'utimestamp' => 0, - 'current_interval' => 0, - 'running_by' => 0, - 'last_execution_try' => 0)); - - if ($result === false) { - db_process_sql_rollback (); - return false; - } - db_process_sql_commit (); db_pandora_audit ("Agent management", "New agent '$name' created"); diff --git a/pandora_console/include/functions_api.php b/pandora_console/include/functions_api.php index a9bf193a03..4f35cd6880 100644 --- a/pandora_console/include/functions_api.php +++ b/pandora_console/include/functions_api.php @@ -4301,7 +4301,7 @@ function api_set_delete_module($id, $id2, $other, $trash1) { } if (!$simulate) { - $return = db_process_sql_delete('tagente_modulo', array('id_agente_modulo' => $idAgentModule)); + $return = modules_delete_agent_module($idAgentModule); } else { $return = true; @@ -4451,8 +4451,8 @@ function api_set_new_module($id, $id2, $other, $trash1) { } $values['id_modulo'] = 2; - - $return = db_process_sql_insert('tagente_modulo', $values); + + $return = modules_create_agent_module($values['id_agente'], $values['nombre'], $values); $data['type'] = 'string'; if ($return === false) { @@ -5291,8 +5291,15 @@ function api_set_new_note_incident($id, $id2, $other, $thrash2) { function api_set_disable_module ($agent_name, $module_name, $thrast3, $thrash4) { $id_agent = agents_get_agent_id($agent_name); $id_agent_module = db_get_value_filter('id_agente_modulo', 'tagente_modulo', array('id_agente' => $id_agent, 'nombre' => $module_name)); - db_process_sql("UPDATE tagente_modulo SET disabled = 1 WHERE id_agente_modulo = $id_agent_module"); - returnData('string', array('type' => 'string', 'data' => __('Correct module disable'))); + + $result = modules_change_disabled($id_agent_module, 1); + + if($result === NOERR) { + returnData('string', array('type' => 'string', 'data' => __('Correct module disable'))); + } + else { + returnData('string', array('type' => 'string', 'data' => __('Error disabling module'))); + } } @@ -5308,8 +5315,15 @@ function api_set_disable_module ($agent_name, $module_name, $thrast3, $thrash4) function api_set_enable_module ($agent_name, $module_name, $thrast3, $thrash4) { $id_agent = agents_get_agent_id($agent_name); $id_agent_module = db_get_value_filter('id_agente_modulo', 'tagente_modulo', array('id_agente' => $id_agent, 'nombre' => $module_name)); - db_process_sql("UPDATE tagente_modulo SET disabled = 0 WHERE id_agente_modulo = $id_agent_module"); - returnData('string', array('type' => 'string', 'data' => __('Correct module enable'))); + + $result = modules_change_disabled($id_agent_module, 1); + + if($result === NOERR) { + returnData('string', array('type' => 'string', 'data' => __('Correct module enable'))); + } + else { + returnData('string', array('type' => 'string', 'data' => __('Error enabling module'))); + } } diff --git a/pandora_console/include/functions_groups.php b/pandora_console/include/functions_groups.php index 35dfe3a921..a18e6f1b0e 100644 --- a/pandora_console/include/functions_groups.php +++ b/pandora_console/include/functions_groups.php @@ -960,7 +960,7 @@ function groups_monitor_not_init ($group_array) { $group_clause = "(" . $group_clause . ")"; //TODO REVIEW ORACLE AND POSTGRES - return db_get_sql ("SELECT SUM(notinit_count) FROM tagente WHERE id_grupo IN $group_clause"); + return db_get_sql ("SELECT SUM(notinit_count) FROM tagente WHERE disabled = 0 AND id_grupo IN $group_clause"); } // Get monitor OK, except disabled and non-init @@ -980,7 +980,7 @@ function groups_monitor_ok ($group_array) { $group_clause = "(" . $group_clause . ")"; //TODO REVIEW ORACLE AND POSTGRES - return db_get_sql ("SELECT SUM(normal_count) FROM tagente WHERE id_grupo IN $group_clause"); + return db_get_sql ("SELECT SUM(normal_count) FROM tagente WHERE disabled = 0 AND id_grupo IN $group_clause"); } // Get monitor CRITICAL, except disabled and non-init @@ -1000,7 +1000,7 @@ function groups_monitor_critical ($group_array) { $group_clause = "(" . $group_clause . ")"; //TODO REVIEW ORACLE AND POSTGRES - return db_get_sql ("SELECT SUM(critical_count) FROM tagente WHERE id_grupo IN $group_clause"); + return db_get_sql ("SELECT SUM(critical_count) FROM tagente WHERE disabled = 0 AND id_grupo IN $group_clause"); } // Get monitor WARNING, except disabled and non-init @@ -1020,7 +1020,7 @@ function groups_monitor_warning ($group_array) { $group_clause = "(" . $group_clause . ")"; //TODO REVIEW ORACLE AND POSTGRES - return db_get_sql ("SELECT SUM(warning_count) FROM tagente WHERE id_grupo IN $group_clause"); + return db_get_sql ("SELECT SUM(warning_count) FROM tagente WHERE disabled = 0 AND id_grupo IN $group_clause"); } // Get monitor UNKNOWN, except disabled and non-init @@ -1040,7 +1040,7 @@ function groups_monitor_unknown ($group_array) { $group_clause = "(" . $group_clause . ")"; //TODO REVIEW ORACLE AND POSTGRES - return db_get_sql ("SELECT SUM(unknown_count) FROM tagente WHERE id_grupo IN $group_clause"); + return db_get_sql ("SELECT SUM(unknown_count) FROM tagente WHERE disabled = 0 AND 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 52b8ab4acf..54c988b1b0 100644 --- a/pandora_console/include/functions_modules.php +++ b/pandora_console/include/functions_modules.php @@ -48,49 +48,21 @@ function modules_copy_agent_module_to_agent ($id_agent_module, $id_destiny_agent $modules = agents_get_modules ($id_destiny_agent, false, array ('nombre' => $module['nombre'], 'disabled' => false)); - // These are the modules that exists in the target + // The module already exist in the target if (! empty ($modules)) return array_pop (array_keys ($modules)); $modulesDisabled = agents_get_modules ($id_destiny_agent, false, array ('nombre' => $module['nombre'], 'disabled' => true)); + // If the module exist but disabled, we enable it if (!empty($modulesDisabled)) { //the foreach have only one loop but extract the array index, and it's id_agente_modulo foreach ($modulesDisabled as $id => $garbage) { $id_module = $id; - switch ($config['dbtype']) { - case "mysql": - case "postgresql": - db_process_sql_update('tagente_modulo', array('disabled' => false, 'delete_pending' => false), - array('id_agente_modulo' => $id_module, 'disabled' => true)); - break; - case "oracle": - db_process_sql_update('tagente_modulo', array('disabled' => false, 'delete_pending' => false), - array('id_agente_modulo' => $id_module, 'disabled' => true), 'AND', false); - break; - } + modules_change_disabled($id_module, 0); } - $values = array (); - $values['id_agente_modulo'] = $id_module; - - /* PHP copy arrays on assignment */ - $new_module = $module; - - /* Rewrite different values */ - $new_module['id_agente'] = $id_destiny_agent; - $new_module['ip_target'] = agents_get_address ($id_destiny_agent); - $new_module['policy_linked'] = 0; - $new_module['id_policy_module'] = 0; - - /* Unset numeric indexes or SQL would fail */ - $len = count ($new_module) / 2; - for ($i = 0; $i < $len; $i++) - unset ($new_module[$i]); - /* Unset original agent module id */ - unset ($new_module['id_agente_modulo']); - $id_new_module = $id_module; } else { @@ -98,7 +70,6 @@ function modules_copy_agent_module_to_agent ($id_agent_module, $id_destiny_agent $new_module = $module; /* Rewrite different values */ - $new_module['id_agente'] = $id_destiny_agent; $new_module['ip_target'] = agents_get_address ($id_destiny_agent); $new_module['policy_linked'] = 0; $new_module['id_policy_module'] = 0; @@ -107,86 +78,62 @@ function modules_copy_agent_module_to_agent ($id_agent_module, $id_destiny_agent $len = count ($new_module) / 2; for ($i = 0; $i < $len; $i++) unset ($new_module[$i]); + /* Unset original agent module id */ unset ($new_module['id_agente_modulo']); + unset ($new_module['id_agente']); + + $id_new_module = modules_create_agent_module($id_destiny_agent, $new_module['nombre'], $new_module); - switch ($config['dbtype']) { - case "mysql": - case "postgresql": - $id_new_module = db_process_sql_insert ('tagente_modulo', - $new_module); - break; - case "oracle": - $id_new_module = db_process_sql_insert ('tagente_modulo', - $new_module, false); - break; - } if ($id_new_module === false) { return false; } - - $values = array (); - $values['id_agente_modulo'] = $id_new_module; } - $values['id_agente'] = $id_destiny_agent; - - switch ($config['dbtype']) { - case "mysql": - case "postgresql": - $result = db_process_sql_insert ('tagente_estado', $values); - break; - case "oracle": - $result = db_process_sql_insert ('tagente_estado', $values, false); - break; + // If the module is synthetic we duplicate the operations too + if($module['id_modulo'] == 5) { + $synth_ops = db_get_all_rows_field_filter('tmodule_synth','id_agent_module_target',$module['id_agente_modulo']); + + if($synth_ops === false) { + $synth_ops = array(); + } + + foreach($synth_ops as $synth_op) { + unset($synth_op['id']); + $synth_op['id_agent_module_target'] = $id_new_module; + switch ($config['dbtype']) { + case "mysql": + case "postgresql": + db_process_sql_insert ('tmodule_synth', + $synth_op); + break; + case "oracle": + db_process_sql_insert ('tmodule_synth', + $synth_op, false); + break; + } + } } - if ($result !== false) { - // If the module is synthetic we duplicate the operations too - if($module['id_modulo'] == 5) { - $synth_ops = db_get_all_rows_field_filter('tmodule_synth','id_agent_module_target',$module['id_agente_modulo']); - - if($synth_ops === false) { - $synth_ops = array(); - } - - foreach($synth_ops as $synth_op) { - unset($synth_op['id']); - $synth_op['id_agent_module_target'] = $id_new_module; - switch ($config['dbtype']) { - case "mysql": - case "postgresql": - db_process_sql_insert ('tmodule_synth', - $synth_op); - break; - case "oracle": - db_process_sql_insert ('tmodule_synth', - $synth_op, false); - break; - } - } - } + // Copy module tags + $source_tags = tags_get_module_tags($id_agent_module); + + if ($source_tags == false) + $source_tags = array(); - // Copy module tags - $source_tags = tags_get_module_tags($id_agent_module); - - if ($source_tags == false) - $source_tags = array(); - - tags_insert_module_tag($id_new_module, $source_tags); - - //Added the config data if necesary - enterprise_include_once('include/functions_config_agents.php'); - - $id_agente = modules_get_agentmodule_agent($id_agent_module); - - $agent_md5 = md5 (agents_get_name($id_agente), false); - $remote_conf = file_exists ($config["remote_config"]."/md5/".$agent_md5.".md5"); - - if ($remote_conf) { - $result = enterprise_hook('config_agents_copy_agent_module_to_agent', - array($id_agent_module, $id_new_module)); - } + tags_insert_module_tag($id_new_module, $source_tags); + + //Added the config data if necesary + enterprise_include_once('include/functions_config_agents.php'); + + $id_agente = modules_get_agentmodule_agent($id_agent_module); + + $agent_md5 = md5 (agents_get_name($id_agente), false); + $remote_conf = file_exists ($config["remote_config"]."/md5/".$agent_md5.".md5"); + + if ($remote_conf) { + $result = enterprise_hook('config_agents_copy_agent_module_to_agent', + array($id_agent_module, $id_new_module)); } if ($result === false) @@ -195,6 +142,75 @@ function modules_copy_agent_module_to_agent ($id_agent_module, $id_destiny_agent return $id_new_module; } +/** + * Enable/Disable a module + * + * @param mixed Agent module id to be disabled. Accepts an array with ids. + * @param integer new value for the field disabled. 0 to enable, 1 to disable + * + * @return True if the module was disabled. False if not. + */ +function modules_change_disabled($id_agent_module, $new_value = 1) { + $id_agent_module = (array) $id_agent_module; + + // Define the operation dependes if is disable or enable + if($new_value == 1) { + $operation = '- 1'; + } + else { + $operation = '+ 1'; + } + + foreach($id_agent_module as $id_module) { + // If the module is already disabled/enabled abort + $current_disabled = db_get_value('disabled', 'tagente_modulo', 'id_agente_modulo', $id_module); + if($current_disabled == $new_value) { + continue; + } + + $status = modules_get_agentmodule_status($id_module); + + $agent_id = modules_get_agentmodule_agent($id_module); + + // Define the field to update depends the status + switch($status) { + case AGENT_MODULE_STATUS_NO_DATA: + $modification = 'notinit_count = notinit_count ' . $operation . ','; + break; + case AGENT_MODULE_STATUS_CRITICAL_BAD: + $modification = 'critical_count = critical_count ' . $operation . ','; + break; + case AGENT_MODULE_STATUS_WARNING: + $modification = 'warning_count = warning_count ' . $operation . ','; + break; + case AGENT_MODULE_STATUS_NORMAL: + $modification = 'normal_count = normal_count ' . $operation . ','; + break; + case AGENT_MODULE_STATUS_UNKNOW: + $modification = 'unknown_count = unknown_count ' . $operation . ','; + break; + default: + $modification = ''; + break; + } + + // Increase total count of the agent + $result = db_process_sql('UPDATE tagente SET ' . $modification . ' total_count = total_count ' . $operation . ' WHERE id_agente = ' . $agent_id); + if(!$result) { + return ERR_GENERIC; + } + } + + $result = db_process_sql_update('tagente_modulo', array('disabled' => $new_value), array('id_agente_modulo' => $id_agent_module)); + + if($result) { + return NOERR; + } + else { + return ERR_GENERIC; + } +} + /** * Deletes a module from an agent. * @@ -225,20 +241,22 @@ function modules_delete_agent_module ($id_agent_module) { $where); db_process_sql_delete('ttag_module', $where); - // Update module status count - 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']); - } else if ($module['estado'] == 4) { - db_process_sql ('UPDATE tagente SET notinit_count=notinit_count-1 WHERE id_agente=' . $module['id_agente']); + // Update module status count only if the module is not disabled + if($module['disabled'] == 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']); + } 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']); + } 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']); } - db_process_sql ('UPDATE tagente SET total_count=total_count-1 WHERE id_agente=' . $module['id_agente']); - return true; } @@ -285,9 +303,18 @@ function modules_update_agent_module ($id, $values, $onlyNoDeletePending = false $where['delete_pending'] = 0; } + // Disable action requires a special function + if(isset($values['disabled'])) { + $result_disable = modules_change_disabled($id, $values['disabled']); + unset($values['disabled']); + } + else { + $result_disable = true; + } + $result = @db_process_sql_update ('tagente_modulo', $values, $where); - if($result === false) { + if($result === false || $result_disable === ERR_GENERIC) { return ERR_DB; } else { @@ -402,14 +429,15 @@ function modules_create_agent_module ($id_agent, $name, $values = false, $disabl return ERR_DB; } - // Update module status count - 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); + // Update module status count if the module is not created disabled + if(!isset ($values['disabled']) || $values['disabled'] == 0) { + 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; } diff --git a/pandora_console/include/functions_ui.php b/pandora_console/include/functions_ui.php index abf5518a60..d3648fe7cf 100644 --- a/pandora_console/include/functions_ui.php +++ b/pandora_console/include/functions_ui.php @@ -1786,7 +1786,7 @@ function ui_toggle($code, $name, $title = '', $hidde_default = true, $return = f // Link to toggle $output = ''; - $output .= ''.$name.' '.html_print_image ($original, true, array ("title" => $title, "id" => "image_".$uniqid)).''; + $output .= ''.$name.' '.html_print_image ($original, true, array ("title" => $title, "id" => "image_".$uniqid)).''; $output .= '

'; // Code into a div diff --git a/pandora_console/operation/agentes/estado_ultimopaquete.php b/pandora_console/operation/agentes/estado_ultimopaquete.php index d1b9504362..f9ed915909 100644 --- a/pandora_console/operation/agentes/estado_ultimopaquete.php +++ b/pandora_console/operation/agentes/estado_ultimopaquete.php @@ -562,4 +562,3 @@ function toggle_full_value(id) { $("#value_module_text_" + id).html(value_title); } -?> \ No newline at end of file diff --git a/pandora_console/pandoradb_data.sql b/pandora_console/pandoradb_data.sql index 0d0d27b463..819924749e 100644 --- a/pandora_console/pandoradb_data.sql +++ b/pandora_console/pandoradb_data.sql @@ -1008,7 +1008,7 @@ INSERT INTO `tplugin` (`id`, `name`, `description`, `max_timeout`, `execute`, `p INSERT INTO `tplugin` (`id`, `name`, `description`, `max_timeout`, `execute`, `plugin_type`, `macros`, `parameters`) VALUES (4,'SMTP Check','This plugin is used to send a mail to a SMTP server and check if works. Parameters in the plugin: IP Address - SMTP Server IP address User - AUTH login Pass - AUTH password Port - SMTP port (optional) Optional parameters: -d Destination email -f Email of the sender -a Authentication system. Could be LOGIN, PLAIN, CRAM-MD5 or DIGEST-MD',10,'/usr/share/pandora_server/util/plugin/SMTP_check.pl',0,'{"1":{"macro":"_field1_","desc":"Target IP","help":"","value":""},"2":{"macro":"_field2_","desc":"Port","help":"","value":""},"3":{"macro":"_field3_","desc":"Username","help":"","value":""},"4":{"macro":"_field4_","desc":"Password","help":"","value":""},"5":{"macro":"_field5_","desc":"Optional parameters","help":"","value":""}}','-h _field1_ -o _field2_ -u _field3_ -p _field4_ _field5_'); -INSERT INTO `tplugin` (`id`, `name`, `description`, `max_timeout`, `execute`, `plugin_type`, `macros`, `parameters`) VALUES (6,'MySQL Plugin','',15,'/usr/share/pandora_server/util/plugin/mysql_plugin.sh',0,'{\"1\":{\"macro\":\"_field1_\",\"desc\":\"IP address\",\"help\":\"IP address\",\"value\":\"-s\"},\"2\":{\"macro\":\"_field2_\",\"desc\":\"Username\",\"help\":\"Username to access to database\",\"value\":\"-u\"},\"3\":{\"macro\":\"_field3_\",\"desc\":\"Password\",\"help\":\"Password to access to database\",\"value\":\"-p\"}}', ''); +INSERT INTO `tplugin` (`id`, `name`, `description`, `max_timeout`, `execute`, `plugin_type`, `macros`, `parameters`) VALUES (6,'MySQL Plugin','',15,'/usr/share/pandora_server/util/plugin/mysql_plugin.sh',0,'{\"1\":{\"macro\":\"_field1_\",\"desc\":\"IP address\",\"help\":\"IP address\",\"value\":\"\"},\"2\":{\"macro\":\"_field2_\",\"desc\":\"Username\",\"help\":\"Username to access to database\",\"value\":\"\"},\"3\":{\"macro\":\"_field3_\",\"desc\":\"Password\",\"help\":\"Password to access to database\",\"value\":\"\"}}', '-s _field1_ -u _field2_ -p _field3_'); INSERT INTO `tagent_custom_fields` VALUES (1,'Serial Number',0),(2,'Department',0),(3,'Additional ID',0);