Merge branch 'ent-8843-disabled-group-en-cli-meta' into 'develop'

Meta disable groups CLI

See merge request artica/pandorafms!4833
This commit is contained in:
Daniel Rodriguez 2022-06-07 11:14:56 +00:00
commit efac993111

View File

@ -21,7 +21,7 @@ use JSON qw(decode_json encode_json);
use MIME::Base64; use MIME::Base64;
use Encode qw(decode encode_utf8); use Encode qw(decode encode_utf8);
use LWP::Simple; use LWP::Simple;
use Data::Dumper; #use Data::Dumper;
# Default lib dir for RPM and DEB packages # Default lib dir for RPM and DEB packages
BEGIN { push @INC, '/usr/lib/perl5'; } BEGIN { push @INC, '/usr/lib/perl5'; }
@ -375,19 +375,42 @@ sub pandora_disable_group ($$$) {
exit; exit;
} }
if(is_metaconsole($conf) == 1) {
my $servers = enterprise_hook('get_metaconsole_setup_servers',[$dbh]);
my @servers_id = split(',',$servers);
foreach my $server (@servers_id) {
my $dbh_metaconsole = enterprise_hook('get_node_dbh',[$conf, $server, $dbh]);
if ($group == 0){
# Extract all the names of the pandora agents if it is for all = 0.
@agents_bd = get_db_rows ($dbh_metaconsole, 'SELECT id_agente FROM tagente');
}
else {
# Extract all the names of the pandora agents if it is for group.
@agents_bd = get_db_rows ($dbh_metaconsole, 'SELECT id_agente FROM tagente WHERE id_grupo = ?', $group);
}
foreach my $id_agent (@agents_bd) {
# Call the API.
$result += api_call(
$conf, 'set', 'disabled_and_standby', $id_agent->{'id_agente'}, $server, '1|1'
);
}
}
} else {
if ($group == 0){ if ($group == 0){
# Extract all the names of the pandora agents if it is for all = 0. # Extract all the names of the pandora agents if it is for all = 0.
@agents_bd = get_db_rows ($dbh, 'SELECT nombre FROM tagente'); @agents_bd = get_db_rows ($dbh, 'SELECT nombre FROM tagente');
# Update bbdd. # Update bbdd.
db_do ($dbh, "UPDATE tagente SET disabled = 1"); $result = db_update ($dbh, "UPDATE tagente SET disabled = 1");
} }
else { else {
# Extract all the names of the pandora agents if it is for group. # Extract all the names of the pandora agents if it is for group.
@agents_bd = get_db_rows ($dbh, 'SELECT nombre FROM tagente WHERE id_grupo = ?', $group); @agents_bd = get_db_rows ($dbh, 'SELECT nombre FROM tagente WHERE id_grupo = ?', $group);
# Update bbdd. # Update bbdd.
db_do ($dbh, "UPDATE tagente SET disabled = 1 WHERE id_grupo = $group"); $result = db_update ($dbh, "UPDATE tagente SET disabled = 1 WHERE id_grupo = $group");
} }
foreach my $name_agent (@agents_bd) { foreach my $name_agent (@agents_bd) {
@ -399,6 +422,7 @@ sub pandora_disable_group ($$$) {
'1' '1'
); );
} }
}
return $result; return $result;
} }
@ -1138,7 +1162,8 @@ sub cli_disable_group() {
print_log "[INFO] Disabling group '$group_name'\n\n"; print_log "[INFO] Disabling group '$group_name'\n\n";
} }
pandora_disable_group ($conf, $dbh, $id_group); my $result = pandora_disable_group ($conf, $dbh, $id_group);
print_log "[INFO] Disabled ".$result." agents from group ".$group_name."\n\n";
} }
############################################################################## ##############################################################################
@ -5539,8 +5564,6 @@ sub cli_get_agents() {
my $head_print = 0; my $head_print = 0;
# use Data::Dumper;
foreach my $agent (@agents) { foreach my $agent (@agents) {
if($status ne '') { if($status ne '') {