From 7689c34fd32de7f5b8863305fa670c1477ad93bd Mon Sep 17 00:00:00 2001 From: zarzuelo Date: Wed, 18 Jan 2012 12:25:03 +0000 Subject: [PATCH] 2012-01-18 Sergio Martin * util/pandora_manage.pl: Add option to CLI to get all policies or the policies with a given agent git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@5389 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_server/ChangeLog | 5 ++++ pandora_server/util/pandora_manage.pl | 41 ++++++++++++++++++++++++++- 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/pandora_server/ChangeLog b/pandora_server/ChangeLog index 712facc6e6..df964654ac 100644 --- a/pandora_server/ChangeLog +++ b/pandora_server/ChangeLog @@ -1,3 +1,8 @@ +2012-01-18 Sergio Martin + + * util/pandora_manage.pl: Add option to CLI to + get all policies or the policies with a given agent + 2012-01-18 Sergio Martin * util/pandora_manage.pl: Added new options to diff --git a/pandora_server/util/pandora_manage.pl b/pandora_server/util/pandora_manage.pl index 9ffb00a4a9..c7c83d98d9 100755 --- a/pandora_server/util/pandora_manage.pl +++ b/pandora_server/util/pandora_manage.pl @@ -100,7 +100,7 @@ sub help_screen{ help_screen_line('--get_module_data', ' []', 'Show the data of a module in the last X seconds (interval) in CSV format'); 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('--update_module', ' ', 'Update a module field'); - help_screen_line('--get_agents_module_current_data', '', 'Get the agent and current data of all the modules with the same name'); + help_screen_line('--get_agents_module_current_data', '', 'Get the agent and current data of all the modules with a given name'); print "ALERTS:\n\n" unless $param ne ''; help_screen_line('--create_template_module', ' ', 'Add alert template to module'); help_screen_line('--delete_template_module', ' ', 'Delete alert template from module'); @@ -140,6 +140,7 @@ sub help_screen{ help_screen_line('--create_policy_plugin_module', ' [ ]', 'Add plug-in module to policy'); help_screen_line('--validate_policy_alerts', '', 'Validate the alerts of a given policy'); help_screen_line('--get_policy_modules', '', 'Get the modules of a policy'); + help_screen_line('--get_policies', '[]', 'Get all the policies (without parameters) or the policies of a given agent (agent name as parameter)'); print "TOOLS:\n\n" unless $param ne ''; help_screen_line('--exec_from_file', ' ', 'Execute any CLI option with macros from CSV file'); @@ -2478,6 +2479,40 @@ sub cli_get_policy_modules() { } } +############################################################################## +# Show all the policies (without parameters) or the policies of given agent +# Related option: --get_policies +############################################################################## + +sub cli_get_policies() { + my $agent_name = @ARGV[2]; + my $policies; + + if(defined($agent_name)) { + my $id_agent = get_agent_id($dbh,$agent_name); + exist_check($id_agent,'agent',$agent_name); + + $policies = enterprise_hook('get_agent_policies',[$dbh,$id_agent]); + + if(scalar(@{$policies}) == 0) { + print "[INFO] No policies found on agent '$agent_name'\n\n"; + exit; + } + } + else { + $policies = enterprise_hook('get_policies',[$dbh]); + if(scalar(@{$policies}) == 0) { + print "[INFO] No policies found\n\n"; + exit; + } + } + + print "id_policy, policy_name\n"; + foreach my $module (@{$policies}) { + print $module->{'id'}.",".safe_output($module->{'name'})."\n"; + } +} + ############################################################################## # Disable policy alerts. # Related option: --disable_policy_alerts @@ -2958,6 +2993,10 @@ sub pandora_manage_main ($$$) { param_check($ltotal, 1); cli_get_policy_modules(); } + elsif ($param eq '--get_policies') { + param_check($ltotal, 1, 1); + cli_get_policies(); + } else { print "[ERROR] Invalid option '$param'.\n\n"; $param = '';