new macro in CLI and API get_module_id. Ticket #3525.
(cherry picked from commit 0035b74f47
)
This commit is contained in:
parent
82a9ebfb7e
commit
ca3f10405c
|
@ -1446,6 +1446,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.
|
* Get modules for an agent, and print all the result like a csv.
|
||||||
*
|
*
|
||||||
|
|
|
@ -114,6 +114,7 @@ sub help_screen{
|
||||||
help_screen_line('--get_all_planned_downtimes', '<name> [<id_group> <type_downtime> <type_execution> <type_periodicity>]', 'Get all planned downtime');
|
help_screen_line('--get_all_planned_downtimes', '<name> [<id_group> <type_downtime> <type_execution> <type_periodicity>]', 'Get all planned downtime');
|
||||||
help_screen_line('--get_planned_downtimes_items', '<name> [<id_group> <type_downtime> <type_execution> <type_periodicity>]', 'Get all items of planned downtimes');
|
help_screen_line('--get_planned_downtimes_items', '<name> [<id_group> <type_downtime> <type_execution> <type_periodicity>]', 'Get all items of planned downtimes');
|
||||||
help_screen_line('--set_planned_downtimes_deleted', '<name> ', 'Deleted a planned downtime');
|
help_screen_line('--set_planned_downtimes_deleted', '<name> ', 'Deleted a planned downtime');
|
||||||
|
help_screen_line('--get_module_id', '<agent_name> <module_name>', 'Get the id of an module');
|
||||||
help_screen_line('--get_agent_group', '<agent_name>', 'Get the group name of an agent');
|
help_screen_line('--get_agent_group', '<agent_name>', 'Get the group name of an agent');
|
||||||
help_screen_line('--get_agent_group_id', '<agent_name>', 'Get the group ID of an agent');
|
help_screen_line('--get_agent_group_id', '<agent_name>', 'Get the group ID of an agent');
|
||||||
help_screen_line('--get_agent_modules', '<agent_name>', 'Get the modules of an agent');
|
help_screen_line('--get_agent_modules', '<agent_name>', 'Get the modules of an agent');
|
||||||
|
@ -3181,6 +3182,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
|
# Show the group name where is a given agent
|
||||||
# Related option: --get_agent_group
|
# Related option: --get_agent_group
|
||||||
|
@ -4573,6 +4594,10 @@ sub pandora_manage_main ($$$) {
|
||||||
param_check($ltotal, 1);
|
param_check($ltotal, 1);
|
||||||
cli_validate_policy_alerts();
|
cli_validate_policy_alerts();
|
||||||
}
|
}
|
||||||
|
elsif ($param eq '--get_module_id') {
|
||||||
|
param_check($ltotal, 2);
|
||||||
|
cli_get_module_id();
|
||||||
|
}
|
||||||
elsif ($param eq '--get_agent_group') {
|
elsif ($param eq '--get_agent_group') {
|
||||||
param_check($ltotal, 1);
|
param_check($ltotal, 1);
|
||||||
cli_get_agent_group();
|
cli_get_agent_group();
|
||||||
|
|
Loading…
Reference in New Issue