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:
commit
efac993111
|
@ -21,7 +21,7 @@ use JSON qw(decode_json encode_json);
|
|||
use MIME::Base64;
|
||||
use Encode qw(decode encode_utf8);
|
||||
use LWP::Simple;
|
||||
use Data::Dumper;
|
||||
#use Data::Dumper;
|
||||
|
||||
# Default lib dir for RPM and DEB packages
|
||||
BEGIN { push @INC, '/usr/lib/perl5'; }
|
||||
|
@ -375,29 +375,53 @@ sub pandora_disable_group ($$$) {
|
|||
exit;
|
||||
}
|
||||
|
||||
if ($group == 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');
|
||||
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]);
|
||||
|
||||
# Update bbdd.
|
||||
db_do ($dbh, "UPDATE tagente SET disabled = 1");
|
||||
}
|
||||
else {
|
||||
# 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);
|
||||
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);
|
||||
}
|
||||
|
||||
# Update bbdd.
|
||||
db_do ($dbh, "UPDATE tagente SET disabled = 1 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){
|
||||
# Extract all the names of the pandora agents if it is for all = 0.
|
||||
@agents_bd = get_db_rows ($dbh, 'SELECT nombre FROM tagente');
|
||||
|
||||
foreach my $name_agent (@agents_bd) {
|
||||
# Check the standby field I put it to 0.
|
||||
my $new_conf = update_conf_txt(
|
||||
$conf,
|
||||
$name_agent->{'nombre'},
|
||||
'standby',
|
||||
'1'
|
||||
);
|
||||
# Update bbdd.
|
||||
$result = db_update ($dbh, "UPDATE tagente SET disabled = 1");
|
||||
}
|
||||
else {
|
||||
# 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);
|
||||
|
||||
# Update bbdd.
|
||||
$result = db_update ($dbh, "UPDATE tagente SET disabled = 1 WHERE id_grupo = $group");
|
||||
}
|
||||
|
||||
foreach my $name_agent (@agents_bd) {
|
||||
# Check the standby field I put it to 0.
|
||||
my $new_conf = update_conf_txt(
|
||||
$conf,
|
||||
$name_agent->{'nombre'},
|
||||
'standby',
|
||||
'1'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
|
@ -1138,7 +1162,8 @@ sub cli_disable_group() {
|
|||
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;
|
||||
|
||||
# use Data::Dumper;
|
||||
|
||||
|
||||
foreach my $agent (@agents) {
|
||||
if($status ne '') {
|
||||
|
@ -8721,4 +8744,4 @@ sub pandora_validate_alert_id($$$$) {
|
|||
);
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue