mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-31 01:35:36 +02:00
Merge branch 'ent-3687-get-agents-id-name-by-alias-api-cli' into 'develop'
Added API and cli function get_agents_id_by_alias See merge request artica/pandorafms!2802
This commit is contained in:
commit
b7d8323583
@ -14226,6 +14226,46 @@ function api_get_agents_id_name_by_cluster_name($cluster_name, $trash1, $trash2,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get agents alias, id and server id (if Metaconsole) given agent alias
|
||||||
|
* matching part of it.
|
||||||
|
*
|
||||||
|
* @param string $alias
|
||||||
|
* @param $trash1
|
||||||
|
* @param $trash2
|
||||||
|
* @param string $returnType
|
||||||
|
* Example:
|
||||||
|
* api.php?op=get&op2=agents_id_name_by_alias&return_type=json&apipass=1234&user=admin&pass=pandora&id=pandrora&id2=strict
|
||||||
|
*/
|
||||||
|
function api_get_agents_id_name_by_alias($alias, $strict, $trash2, $returnType)
|
||||||
|
{
|
||||||
|
global $config;
|
||||||
|
|
||||||
|
if ($strict == 'strict') {
|
||||||
|
$where_clause = " alias = '$alias'";
|
||||||
|
} else {
|
||||||
|
$where_clause = " upper(alias) LIKE upper('%$alias%')";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_metaconsole()) {
|
||||||
|
$all_agents = db_get_all_rows_sql("SELECT alias, id_agente, id_tagente,id_tmetaconsole_setup as 'id_server', server_name FROM tmetaconsole_agent WHERE $where_clause");
|
||||||
|
} else {
|
||||||
|
$all_agents = db_get_all_rows_sql("SELECT alias, id_agente from tagente WHERE $where_clause");
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($all_agents !== false) {
|
||||||
|
$data = [
|
||||||
|
'type' => 'json',
|
||||||
|
'data' => $all_agents,
|
||||||
|
];
|
||||||
|
|
||||||
|
returnData('json', $data, JSON_FORCE_OBJECT);
|
||||||
|
} else {
|
||||||
|
returnError('error_agents', 'Alias did not match any agent.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function api_get_modules_id_name_by_cluster_id($cluster_id)
|
function api_get_modules_id_name_by_cluster_id($cluster_id)
|
||||||
{
|
{
|
||||||
global $config;
|
global $config;
|
||||||
|
@ -118,12 +118,22 @@ sub help_screen{
|
|||||||
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_id> <module_name>', 'Get the id of an module');
|
help_screen_line('--get_module_id', '<agent_id> <module_name>', 'Get the id of an module');
|
||||||
|
<<<<<<< HEAD
|
||||||
|
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_modules', '<agent_name>', 'Get the modules of an agent');
|
||||||
|
help_screen_line('--get_agents_id_name_by_alias', '<agent_alias>', '[<strict>]', 'List id and alias of agents mathing given alias');
|
||||||
|
help_screen_line('--get_agents', '[<group_name> <os_name> <status> <max_modules> <filter_substring> <policy_name>]', "Get \n\t list of agents with optative filter parameters");
|
||||||
|
help_screen_line('--delete_conf_file', '<agent_name>', 'Delete a local conf of a given agent');
|
||||||
|
help_screen_line('--clean_conf_file', '<agent_name>', "Clean a local conf of a given agent deleting all modules, \n\t policies, file collections and comments");
|
||||||
|
=======
|
||||||
help_screen_line('--get_agent_group', '<agent_name> [<use_alias>]', 'Get the group name of an agent');
|
help_screen_line('--get_agent_group', '<agent_name> [<use_alias>]', 'Get the group name of an agent');
|
||||||
help_screen_line('--get_agent_group_id', '<agent_name> [<use_alias>]', 'Get the group ID of an agent');
|
help_screen_line('--get_agent_group_id', '<agent_name> [<use_alias>]', 'Get the group ID of an agent');
|
||||||
help_screen_line('--get_agent_modules', '<agent_name> [<use_alias>]', 'Get the modules of an agent');
|
help_screen_line('--get_agent_modules', '<agent_name> [<use_alias>]', 'Get the modules of an agent');
|
||||||
help_screen_line('--get_agents', '[<group_name> <os_name> <status> <max_modules> <filter_substring> <policy_name> <use_alias>]', "Get \n\t list of agents with optative filter parameters");
|
help_screen_line('--get_agents', '[<group_name> <os_name> <status> <max_modules> <filter_substring> <policy_name> <use_alias>]', "Get \n\t list of agents with optative filter parameters");
|
||||||
help_screen_line('--delete_conf_file', '<agent_name> [<use_alias>]', 'Delete a local conf of a given agent');
|
help_screen_line('--delete_conf_file', '<agent_name> [<use_alias>]', 'Delete a local conf of a given agent');
|
||||||
help_screen_line('--clean_conf_file', '<agent_name> [<use_alias>]', "Clean a local conf of a given agent deleting all modules, \n\t policies, file collections and comments");
|
help_screen_line('--clean_conf_file', '<agent_name> [<use_alias>]', "Clean a local conf of a given agent deleting all modules, \n\t policies, file collections and comments");
|
||||||
|
>>>>>>> origin/develop
|
||||||
help_screen_line('--get_bad_conf_files', '', 'Get the files bad configured (without essential tokens)');
|
help_screen_line('--get_bad_conf_files', '', 'Get the files bad configured (without essential tokens)');
|
||||||
help_screen_line('--locate_agent', '<agent_name> [<use_alias>]', 'Search a agent into of nodes of metaconsole. Only Enterprise.');
|
help_screen_line('--locate_agent', '<agent_name> [<use_alias>]', 'Search a agent into of nodes of metaconsole. Only Enterprise.');
|
||||||
help_screen_line('--migration_agent_queue', '<id_node> <source_node_name> <target_node_name> [<db_only>]', 'Migrate agent only metaconsole');
|
help_screen_line('--migration_agent_queue', '<id_node> <source_node_name> <target_node_name> [<db_only>]', 'Migrate agent only metaconsole');
|
||||||
@ -4849,6 +4859,49 @@ sub cli_get_agent_modules() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
##############################################################################
|
||||||
|
# Show id, name and id_server of an agent given alias
|
||||||
|
# Related option: --get_agents_id_name_by_alias
|
||||||
|
##############################################################################
|
||||||
|
|
||||||
|
sub cli_get_agents_id_name_by_alias() {
|
||||||
|
my $agent_alias = @ARGV[2];
|
||||||
|
my $strict = @ARGV[3];
|
||||||
|
my @agents;
|
||||||
|
my $where_value;
|
||||||
|
|
||||||
|
if($strict eq 'strict') {
|
||||||
|
$where_value = $agent_alias;
|
||||||
|
} else {
|
||||||
|
$where_value = "%".$agent_alias."%";
|
||||||
|
}
|
||||||
|
|
||||||
|
if(is_metaconsole($conf) == 1) {
|
||||||
|
@agents = get_db_rows($dbh,"SELECT alias, id_agente, id_tagente, id_tmetaconsole_setup as 'id_server', server_name FROM tmetaconsole_agent WHERE UPPER(alias) LIKE UPPER(?)", $where_value);
|
||||||
|
} else {
|
||||||
|
@agents = get_db_rows($dbh,"SELECT alias, id_agente FROM tagente WHERE UPPER(alias) LIKE UPPER(?)", $where_value);
|
||||||
|
}
|
||||||
|
if(scalar(@agents) == 0) {
|
||||||
|
print "[ERROR] No agents retrieved.\n\n";
|
||||||
|
} else {
|
||||||
|
if(is_metaconsole($conf) == 1) {
|
||||||
|
print "alias, id_agente, id_tagente, id_server, server_name\n";
|
||||||
|
|
||||||
|
foreach my $agent (@agents) {
|
||||||
|
|
||||||
|
print safe_output($agent->{'alias'}).", ".$agent->{'id_agente'}.", ".$agent->{'id_tagente'}.", ".$agent->{'id_server'}.", ".$agent->{'server_name'}."\n";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
print "alias, id_agente\n";
|
||||||
|
|
||||||
|
foreach my $agent (@agents) {
|
||||||
|
print $agent->{'id_agente'}.",".safe_output($agent->{'alias'})."\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
sub cli_create_synthetic() {
|
sub cli_create_synthetic() {
|
||||||
my $name_module = @ARGV[2];
|
my $name_module = @ARGV[2];
|
||||||
my $synthetic_type = @ARGV[3];
|
my $synthetic_type = @ARGV[3];
|
||||||
@ -7426,6 +7479,10 @@ sub pandora_manage_main ($$$) {
|
|||||||
param_check($ltotal, 2, 1);
|
param_check($ltotal, 2, 1);
|
||||||
cli_get_agent_modules();
|
cli_get_agent_modules();
|
||||||
}
|
}
|
||||||
|
elsif ($param eq '--get_agents_id_name_by_alias') {
|
||||||
|
param_check($ltotal, 2,1);
|
||||||
|
cli_get_agents_id_name_by_alias();
|
||||||
|
}
|
||||||
elsif ($param eq '--get_policy_modules') {
|
elsif ($param eq '--get_policy_modules') {
|
||||||
param_check($ltotal, 1);
|
param_check($ltotal, 1);
|
||||||
cli_get_policy_modules();
|
cli_get_policy_modules();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user