From 0035b74f4790c840423ded42d82b1e458cea9637 Mon Sep 17 00:00:00 2001 From: Daniel Maya Date: Fri, 17 Jun 2016 08:50:30 +0200 Subject: [PATCH] new macro in CLI and API get_module_id. Ticket #3525. --- pandora_console/include/functions_api.php | 33 +++++++++++++++++++++++ pandora_server/util/pandora_manage.pl | 25 +++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/pandora_console/include/functions_api.php b/pandora_console/include/functions_api.php index 356a23c0cc..beb3f1d69c 100644 --- a/pandora_console/include/functions_api.php +++ b/pandora_console/include/functions_api.php @@ -1452,6 +1452,39 @@ function api_get_agent_modules($thrash1, $thrash2, $other, $thrash3) { } } + +/** + * Get modules id for an agent, and print the result like a csv. + * + * @param $id Id of agent. + * @param array $name name of module. + * @param $thrash1 Don't use. + * + * pi.php?op=get&op2=module_id&id=5&other=Host%20Alive&apipass=1234&user=admin&pass=pandora + * + * @param $thrash3 Don't use. + */ +function api_get_module_id($id , $thrash1 , $name, $thrash3) { + if (defined ('METACONSOLE')) { + return; + } + + $sql = sprintf('SELECT id_agente_modulo + FROM tagente_modulo WHERE id_agente = %d + AND nombre = "%s" AND disabled = 0 + AND delete_pending = 0', $id , $name['data']); + + $module_id = db_get_all_rows_sql($sql); + + if (count($module_id) > 0 and $module_id !== false) { + $data = array('type' => 'array', 'data' => $module_id); + returnData('csv', $data, ';'); + } + else { + returnError('error_module_id', 'does not exist module or agent'); + } +} + /** * Get modules for an agent, and print all the result like a csv. * diff --git a/pandora_server/util/pandora_manage.pl b/pandora_server/util/pandora_manage.pl index 511483a825..555206e826 100644 --- a/pandora_server/util/pandora_manage.pl +++ b/pandora_server/util/pandora_manage.pl @@ -116,6 +116,7 @@ sub help_screen{ help_screen_line('--get_all_planned_downtimes', ' [ ]', 'Get all planned downtime'); help_screen_line('--get_planned_downtimes_items', ' [ ]', 'Get all items of planned downtimes'); help_screen_line('--set_planned_downtimes_deleted', ' ', 'Deleted a planned downtime'); + help_screen_line('--get_module_id', ' ', 'Get the id of an module'); help_screen_line('--get_agent_group', '', 'Get the group name of an agent'); help_screen_line('--get_agent_group_id', '', 'Get the group ID of an agent'); help_screen_line('--get_agent_modules', '', 'Get the modules of an agent'); @@ -3230,6 +3231,26 @@ sub cli_validate_policy_alerts() { } } + +############################################################################## +# Show the module id where is a given agent +# Related option: --get_module_id +# perl pandora_manage.pl /etc/pandora/pandora_server.conf --get_module_id 4 'host alive' +############################################################################## + +sub cli_get_module_id() { + (my $agent_id,my $module_name) = @ARGV[2..3]; + + exist_check($agent_id,'agent',$agent_id); + + my $module_id = get_agent_module_id($dbh, $module_name, $agent_id); + exist_check($module_id, 'module name', $module_name); + + print $module_id; + +} + + ############################################################################## # Show the group name where is a given agent # Related option: --get_agent_group @@ -4700,6 +4721,10 @@ sub pandora_manage_main ($$$) { param_check($ltotal, 1); cli_validate_policy_alerts(); } + elsif ($param eq '--get_module_id') { + param_check($ltotal, 2); + cli_get_module_id(); + } elsif ($param eq '--get_agent_group') { param_check($ltotal, 1); cli_get_agent_group();