2011-12-02 Sergio Martin <sergio.martin@artica.es>

* include/functions_modules.php
	include/functions_api.php
	include/functions.php
	extensions/snmp_explorer.php
	godmode/agentes/module_manager_editor_common.php
	godmode/agentes/configurar_agente.php: limited the 
	modules creation to not allows to create one if exists
	a module with the same name in the agent to avoid
	recreate a module when go back in the browser.
	Bugfix: 3416129



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@5227 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
zarzuelo 2011-12-02 08:52:54 +00:00
parent 7b4e536199
commit ae69df1839
7 changed files with 119 additions and 14 deletions

View File

@ -1,3 +1,16 @@
2011-12-02 Sergio Martin <sergio.martin@artica.es>
* include/functions_modules.php
include/functions_api.php
include/functions.php
extensions/snmp_explorer.php
godmode/agentes/module_manager_editor_common.php
godmode/agentes/configurar_agente.php: limited the
modules creation to not allows to create one if exists
a module with the same name in the agent to avoid
recreate a module when go back in the browser.
Bugfix: 3416129
2011-12-01 Juan Manuel Ramon <juanmanuel.ramon@artica.es>
* extensions/snmp_explorer.php: Removed trace.

View File

@ -144,6 +144,9 @@ function snmp_explorer() {
$result = false;
$errors = array();
$done = 0;
foreach($id_snmp as $id) {
if (isset($interfaces[$id]['ifName']) && $interfaces[$id]['ifName']['value'] != ""){
$ifname = $interfaces[$id]['ifName']['value'];
@ -205,10 +208,47 @@ function snmp_explorer() {
$values['id_modulo'] = 2;
$result = modules_create_agent_module ($id_agent, $name, $values);
if(is_error($result)) {
if(!isset($errors[$result])) {
$errors[$result] = 0;
}
$errors[$result]++;
}
else {
$done++;
}
}
}
ui_print_result_message ($result, __('Successfully modules created'), __('Could not be created'));
if($done > 0) {
ui_print_success_message(__('Successfully modules created')." ($done)");
}
if(!empty($errors)) {
$msg = __('Could not be created').':';
foreach($errors as $code => $number) {
switch($code) {
case ERR_EXIST:
$msg .= '<br>'.__('Another module already exists with the same name')." ($number)";
break;
case ERR_INCOMPLETE:
$msg .= '<br>'.__('Some required fields are missed').': ('.__('name').') '." ($number)";
break;
case ERR_DB:
case ERR_GENERIC:
default:
$msg .= '<br>'.__('Processing errors')." ($number)";
break;
}
}
ui_print_error_message($msg);
}
}
// Create the interface list for the interface

View File

@ -828,9 +828,24 @@ if ($create_module) {
else {
$id_agent_module = modules_create_agent_module ($id_agente, $name, $values, false, $id_tag);
}
if ($id_agent_module === false) {
echo '<h3 class="error">'.__('There was a problem adding module').'</h3>';
if (is_error($id_agent_module)) {
$msg = __('There was a problem adding module').'. ';
switch($id_agent_module) {
case ERR_EXIST:
$msg .= __('Another module already exists with the same name').'.';
break;
case ERR_INCOMPLETE:
$msg .= __('Some required fields are missed').': ('.__('name').')';
break;
case ERR_DB:
case ERR_GENERIC:
default:
// No more info
break;
}
$id_agent_module = false;
echo '<h3 class="error">'.$msg.'</h3>';
$edit_module = true;
$moduletype = $id_module;
db_pandora_audit("Agent management",

View File

@ -244,7 +244,7 @@ $table_advanced->data[6][0] = __('Tags available');
if ($__code_from == 'modules') {
$__table_modules = 'ttag_module';
$__id_where = 'b.id_agente_modulo';
$__id = $id_agent_module;
$__id = (int)$id_agent_module;
// Code comes from policy module editor
}else {
global $__id_pol_mod;

View File

@ -37,6 +37,17 @@ define ('EVENT_PROCESS', 2);
define ('AGENT_ENABLED',0);
define ('AGENT_DISABLED',1);
/* Error report codes */
define ('ERR_GENERIC',-10000);
define ('ERR_EXIST',-20000);
define ('ERR_INCOMPLETE', -30000);
define ('ERR_DB', -40000);
define ('ERR_FILE', -50000);
/* Visual console constants */
define("MIN_WIDTH",300);
define("MIN_HEIGHT",120);
@ -1100,6 +1111,21 @@ function is_ajax () {
return defined ('AJAX');
}
/**
* Check if a code is an error code
*
* @param int code of an operation. Tipically the id of a module, agent... or a code error
*
* @return bool true if a result code is an error or false otherwise
*/
function is_error($code) {
if($code <= ERR_GENERIC) {
return true;
}
else {
return false;
}
}
/**
* Transform an array of database result into an indexed array.
*

View File

@ -800,10 +800,13 @@ function set_create_network_module($id, $thrash1, $other, $thrash3) {
$idModule = modules_create_agent_module($idAgent, $name, $values, true);
if ($idModule === false)
returnError('error_create_network_module', 'Error in creation network module.');
else
if (is_error($idModule)) {
// TODO: Improve the error returning more info
returnError('error_create_network_module', __('Error in creation network module.'));
}
else {
returnData('string', array('type' => 'string', 'data' => $idModule));
}
}
/**

View File

@ -239,17 +239,25 @@ function modules_create_agent_module ($id_agent, $name, $values = false, $disabl
return false;
}
if (empty ($name))
return false;
if (empty ($name)) {
return ERR_INCOMPLETE;
}
if (! is_array ($values))
$values = array ();
$values['nombre'] = $name;
$values['id_agente'] = (int) $id_agent;
$exists = (bool)db_get_value_filter('id_agente_modulo', 'tagente_modulo', array('nombre' => $name, 'id_agente' => (int)$id_agent));
if($exists) {
return ERR_EXIST;
}
$id_agent_module = db_process_sql_insert ('tagente_modulo', $values);
if ($id_agent_module === false)
return false;
return ERR_DB;
$return_tag = true;
if (($tags !== false) || (empty($tags)))
@ -259,7 +267,7 @@ function modules_create_agent_module ($id_agent, $name, $values = false, $disabl
db_process_sql_delete ('tagente_modulo',
array ('id_agente_modulo' => $id_agent_module));
return false;
return ERR_DB;
}
switch ($config["dbtype"]) {
@ -305,7 +313,7 @@ function modules_create_agent_module ($id_agent, $name, $values = false, $disabl
db_process_sql_delete ('tagente_modulo',
array ('id_agente_modulo' => $id_agent_module));
return false;
return ERR_DB;
}
return $id_agent_module;