From 2c223f4d10edf882b819bd990f179ef26fedb6a6 Mon Sep 17 00:00:00 2001 From: enriquecd Date: Mon, 9 Apr 2018 11:43:41 +0200 Subject: [PATCH] Add cli cluster functions - #2007 --- pandora_server/util/pandora_manage.pl | 140 +++++++++++++++++++++++++- 1 file changed, 139 insertions(+), 1 deletion(-) diff --git a/pandora_server/util/pandora_manage.pl b/pandora_server/util/pandora_manage.pl index 293d07c805..980f5fbe51 100644 --- a/pandora_server/util/pandora_manage.pl +++ b/pandora_server/util/pandora_manage.pl @@ -36,7 +36,7 @@ use Encode::Locale; Encode::Locale::decode_argv; # version: define current version -my $version = "7.0NG.720 PS180409"; +my $version = "7.0NG.720 PS180406"; # save program name for logging my $progname = basename($0); @@ -129,6 +129,12 @@ sub help_screen{ help_screen_line('--migration_agent_queue', ' []', 'Migrate agent only metaconsole'); help_screen_line('--migration_agent', ' ', 'Is migrating the agent only metaconsole'); help_screen_line('--apply_module_template', ' ', 'Apply module template to agent'); + help_screen_line('--new_cluster', ' ', 'Creating a new cluster'); + help_screen_line('--add_cluster_agent', '', 'Adding agent to cluster'); + help_screen_line('--add_cluster_item', ' ', 'Adding item to cluster'); + help_screen_line('--delete_cluster', '', 'Deleting cluster'); + help_screen_line('--delete_cluster_agent', ' ', 'Deleting cluster agent'); + help_screen_line('--delete_cluster_item', '', 'Deleting cluster item'); print "\nMODULES:\n\n" unless $param ne ''; help_screen_line('--create_data_module', " [ \n\t \n\t \n\t \n\t \n\t ]", 'Add data server module to agent'); help_screen_line('--create_web_module', " [ \n\t \n\t \n\t \n\t \n\t ].\n\t The valid data types are web_data, web_proc, web_content_data or web_content_string", 'Add web server module to agent'); @@ -6082,6 +6088,31 @@ sub pandora_manage_main ($$$) { param_check($ltotal, 2, 2); cli_apply_module_template(); } + elsif ($param eq '--new_cluster') { + param_check($ltotal, 4, 0); + cli_new_cluster(); + } + elsif ($param eq '--add_cluster_agent') { + param_check($ltotal, 1, 0); + cli_add_cluster_agent(); + } + elsif ($param eq '--add_cluster_item') { + param_check($ltotal, 1, 0); + cli_add_cluster_item(); + } + elsif ($param eq '--delete_cluster') { + param_check($ltotal, 1, 0); + cli_delete_cluster(); + } + elsif ($param eq '--delete_cluster_agent') { + param_check($ltotal, 2, 0); + cli_delete_cluster_agent(); + } + elsif ($param eq '--delete_cluster_item') { + param_check($ltotal, 1, 0); + cli_delete_cluster_item(); + } + elsif ($param eq '--migration_agent_queue') { param_check($ltotal, 4, 1); cli_migration_agent_queue(); @@ -6549,3 +6580,110 @@ sub cli_apply_module_template() { } } +############################################################################## +# Create an cluster. +# Related option: --new_cluster +############################################################################## +sub cli_new_cluster() { + my ($cluster_name,$cluster_type,$description,$group_id) = @ARGV[2..5]; + + # Call the API. + my $result = api_call( $conf, 'set', 'new_cluster', undef, undef, "$cluster_name|$cluster_type|$description|$group_id"); + + if( defined($result) && "$result" ne "" ){ + print "\n1\n"; + } + else{ + print "\n0\n"; + } +} + +############################################################################## +# Assign an agent to cluster. +# Related option: --add_cluster_agent +############################################################################## +sub cli_add_cluster_agent() { + my ($other) = @ARGV[2..2]; + + # Call the API. + my $result = api_call( $conf, 'set', 'add_cluster_agent', undef, undef, $other); + + if( defined($result) && "$result" ne "" ){ + print "\n1\n"; + } + else{ + print "\n0\n"; + } +} + +############################################################################## +# Add item to cluster. +# Related option: --add_cluster_item +############################################################################## +sub cli_add_cluster_item() { + my ($other) = @ARGV[2..2]; + + # Call the API. + my $result = api_call( $conf, 'set', 'add_cluster_item', undef, undef, $other); + + if( defined($result) && "$result" ne "" ){ + print "\n1\n"; + } + else{ + print "\n0\n"; + } +} + +############################################################################## +# Delete cluster. +# Related option: --delete_cluster +############################################################################## +sub cli_delete_cluster() { + my ($id) = @ARGV[2..2]; + + # Call the API. + my $result = api_call( $conf, 'set', 'delete_cluster', $id); + + if( defined($result) && "$result" ne "" ){ + print "\n1\n"; + } + else{ + print "\n0\n"; + } +} + +############################################################################## +# Delete cluster item. +# Related option: --delete_cluster_item +############################################################################## +sub cli_delete_cluster_agent() { + my ($id_agent,$id_cluster) = @ARGV[2..3]; + + # Call the API. + my $result = api_call( $conf, 'set', 'delete_cluster_agent', undef, undef, "$id_agent|$id_cluster"); + + if( defined($result) && "$result" ne "" ){ + print "\n1\n"; + } + else{ + print "\n0\n"; + } +} + +############################################################################## +# Delete cluster item. +# Related option: --delete_cluster_item +############################################################################## +sub cli_delete_cluster_item() { + my ($id) = @ARGV[2..2]; + + # Call the API. + my $result = api_call( $conf, 'set', 'delete_cluster_item', $id); + + if( defined($result) && "$result" ne "" ){ + print "\n1\n"; + } + else{ + print "\n0\n"; + } +}