From 945a3572b53d912d621f15cf883c739c25cababe Mon Sep 17 00:00:00 2001 From: juanmanuelr Date: Tue, 29 Nov 2011 10:05:25 +0000 Subject: [PATCH] 2011-11-29 Juan Manuel Ramon * util/pandora_manage.pl: Added checks of agent and module names at creation time. Fixes: #3439878 git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@5191 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_server/ChangeLog | 7 +++++++ pandora_server/util/pandora_manage.pl | 24 +++++++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/pandora_server/ChangeLog b/pandora_server/ChangeLog index cebc422661..5e003d795f 100644 --- a/pandora_server/ChangeLog +++ b/pandora_server/ChangeLog @@ -1,3 +1,10 @@ +2011-11-29 Juan Manuel Ramon + + * util/pandora_manage.pl: Added checks of agent and module names at + creation time. + + Fixes: #3439878 + 2011-11-26 Junichi Satoh * FreeBSD/pandora_server.conf: Synchronized with the generic diff --git a/pandora_server/util/pandora_manage.pl b/pandora_server/util/pandora_manage.pl index bad0a2f009..edc5442eb3 100755 --- a/pandora_server/util/pandora_manage.pl +++ b/pandora_server/util/pandora_manage.pl @@ -338,6 +338,14 @@ sub notexists_error ($$) { exit 1; } +############################################################################### +# Print a 'exists' error and exit the program. +############################################################################### +sub exists_error ($$) { + print (STDERR "[ERROR] Error: The $_[0] '$_[1]' already exists.\n\n"); + exit 1; +} + ############################################################################### # Check the return of 'get id' and call the error if its equal to -1. ############################################################################### @@ -347,6 +355,15 @@ sub exist_check ($$$) { } } +############################################################################### +# Check the return of 'get id' and call the error if its not equal to -1. +############################################################################### +sub non_exist_check ($$$) { + if($_[0] != -1) { + exists_error($_[1],$_[2]); + } +} + ############################################################################### # Check the parameters. # Param 0: # of received parameters @@ -487,6 +504,8 @@ sub cli_create_agent() { exist_check($id_group,'group',$group_name); my $os_id = get_os_id($dbh,$os_name); exist_check($id_group,'operating system',$group_name); + my $agent_exists = get_agent_id($dbh,$agent_name); + non_exist_check($agent_exists, 'agent name', $agent_name); pandora_create_agent ($conf, $server_name, $agent_name, $address, $id_group, 0, $os_id, $description, $interval, $dbh); } @@ -521,6 +540,10 @@ sub cli_create_data_module() { my $module_type_def; print "[INFO] Adding module '$module_name' to agent '$agent_name'\n\n"; + + my $agent_id = get_agent_id($dbh,$agent_name); + my $module_exists = get_agent_module_id($dbh, $module_name, $agent_id); + non_exist_check($module_exists, 'module name', $module_name); # If the module is local, we add it to the conf file if(defined($definition_file) && (-e $definition_file) && (-e $conf->{incomingdir}.'/conf/'.md5($agent_name).'.conf')){ @@ -575,7 +598,6 @@ sub cli_create_data_module() { exit; } - my $agent_id = get_agent_id($dbh,$agent_name); exist_check($agent_id,'agent',$agent_name); my $module_group_id = get_module_group_id($dbh,$module_group);