From 3ffd3faecc4b64bb9189249657dd95aa29d55d08 Mon Sep 17 00:00:00 2001 From: zarzuelo Date: Thu, 21 Oct 2010 14:26:46 +0000 Subject: [PATCH] 2010-10-21 Sergio Martin * lib/PandoraFMS/DB.pm: Added a generic update function to return the number of changes * util/pandora_manage.pl: Added the unblock policies to the CLI and the block/unblock policies when it are applied. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@3441 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_server/ChangeLog | 8 ++++++++ pandora_server/lib/PandoraFMS/DB.pm | 12 ++++++++++++ pandora_server/util/pandora_manage.pl | 27 ++++++++++++++++++++------- 3 files changed, 40 insertions(+), 7 deletions(-) diff --git a/pandora_server/ChangeLog b/pandora_server/ChangeLog index 0f766a92f5..1c35c603e4 100644 --- a/pandora_server/ChangeLog +++ b/pandora_server/ChangeLog @@ -1,3 +1,11 @@ +2010-10-21 Sergio Martin + + * lib/PandoraFMS/DB.pm: Added a generic update function to return + the number of changes + + * util/pandora_manage.pl: Added the unblock policies to the CLI and + the block/unblock policies when it are applied. + 2010-10-21 Junichi Satoh * lib/PandoraFMS/Tools.pm: Fixed timeout option for FreeBSD ping. diff --git a/pandora_server/lib/PandoraFMS/DB.pm b/pandora_server/lib/PandoraFMS/DB.pm index c1b68f8175..258ee178c8 100644 --- a/pandora_server/lib/PandoraFMS/DB.pm +++ b/pandora_server/lib/PandoraFMS/DB.pm @@ -32,6 +32,7 @@ our @EXPORT = qw( db_do db_process_insert db_insert + db_update get_action_id get_agent_id get_agent_name @@ -332,6 +333,17 @@ sub db_insert ($$;@) { return $dbh->{'mysql_insertid'}; } +########################################################################## +## SQL update. Returns the number of updated rows. +########################################################################## +sub db_update ($$;@) { + my ($dbh, $query, @values) = @_; + + my $rows = $dbh->do($query, undef, @values); + + return $rows; +} + ########################################################################## ## SQL insert. Returns the ID of the inserted row. ########################################################################## diff --git a/pandora_server/util/pandora_manage.pl b/pandora_server/util/pandora_manage.pl index b1eda3d1d3..79a012ebee 100755 --- a/pandora_server/util/pandora_manage.pl +++ b/pandora_server/util/pandora_manage.pl @@ -533,6 +533,7 @@ sub help_screen{ help_screen_line('--delete_data', '-m | -a | -g ', 'Delete historic data of a module, the modules of an agent or the modules of the agents of a group'); help_screen_line('--delete_not_policy_modules', '', 'Delete all modules without policy from configuration file'); help_screen_line('--apply_policy', '', 'Force apply a policy'); + help_screen_line('--force_unblock_policies', '', 'Force unblock the policies'); print "\n"; exit; } @@ -1309,6 +1310,14 @@ sub pandora_manage_main ($$$) { my $configuration_data = ""; my $policy_id = enterprise_hook('get_policy_id',[$dbh, $policy_name]); + exist_check($policy_id,'policy',$policy_name); + + my $blocked_policies = enterprise_hook('pandora_block_policies', [$dbh]); + + if($blocked_policies eq '0E0') { + print "[ERROR] The policies are blocked in other terminal.\n\n"; + exit; + } # Get the agents my $array_pointer_ag = enterprise_hook('get_policy_agents',[$dbh, $policy_id]); @@ -1377,14 +1386,14 @@ sub pandora_manage_main ($$$) { } } - #Add the conf information to the agent conf file - enterprise_hook('pandora_create_policy_conf_info',[$conf, $policy_name, $configuration_data,$agent_name,$dbh]); + #Add the conf information to the agent conf file + enterprise_hook('pandora_create_policy_conf_info',[$conf, $policy_name, $configuration_data,$agent_name,$dbh]); + + # Flag applyed the agent + enterprise_hook('pandora_apply_agent_policy',[$policy_id, $id_agent, $dbh]); + } - # Flag applyed the agent - enterprise_hook('pandora_apply_agent_policy',[$policy_id, $id_agent, $dbh]); - } - - # Get policy collections and link it on created modules + # Get policy collections and link it on created modules my $array_pointer_col = enterprise_hook('get_policy_collections',[$dbh, $policy_id]); my $collection_data = ''; @@ -1400,6 +1409,10 @@ sub pandora_manage_main ($$$) { enterprise_hook('pandora_create_collection_conf_info',[$conf, $policy_name, $collection_data,$agent_name,$dbh]); } } + enterprise_hook('pandora_unblock_policies', [$dbh]); + } + elsif ($param eq '--force_unblock_policies') { + enterprise_hook('pandora_unblock_policies', [$dbh]); } else { print "[ERROR] Invalid option '$param'.\n\n";