Fixed write in conf agent from CLI
This commit is contained in:
parent
c9779ef0a8
commit
94553df28f
|
@ -284,19 +284,94 @@ sub api_call($$$;$$$$) {
|
||||||
return $content;
|
return $content;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# Update token conf file agent
|
||||||
|
###############################################################################
|
||||||
|
sub update_conf_txt ($$$$) {
|
||||||
|
my ($conf, $agent_name, $token, $value) = @_;
|
||||||
|
|
||||||
|
# Read the conf of each agent.
|
||||||
|
my $conf_file_txt = enterprise_hook(
|
||||||
|
'read_agent_conf_file',
|
||||||
|
[
|
||||||
|
$conf,
|
||||||
|
$agent_name
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
# Check if there is agent conf.
|
||||||
|
if(!$conf_file_txt){
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
my $updated = 0;
|
||||||
|
my $txt_content = "";
|
||||||
|
|
||||||
|
my @lines = split /\n/, $conf_file_txt;
|
||||||
|
|
||||||
|
foreach my $line (@lines) {
|
||||||
|
if ($line =~ /^\s*$token\s/ || $line =~ /^#$token\s/ || $line =~ /^#\s$token\s/) {
|
||||||
|
$txt_content .= $token.' '.$value."\n";
|
||||||
|
$updated = 1;
|
||||||
|
} else {
|
||||||
|
$txt_content .= $line."\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($updated == 0) {
|
||||||
|
$txt_content .= "\n$token $value\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
# Write the conf.
|
||||||
|
my $result = enterprise_hook(
|
||||||
|
'write_agent_conf_file',
|
||||||
|
[
|
||||||
|
$conf,
|
||||||
|
$agent_name,
|
||||||
|
$txt_content
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# Disable a entire group
|
# Disable a entire group
|
||||||
###############################################################################
|
###############################################################################
|
||||||
sub pandora_disable_group ($$$) {
|
sub pandora_disable_group ($$$) {
|
||||||
my ($conf, $dbh, $group) = @_;
|
my ($conf, $dbh, $group) = @_;
|
||||||
|
|
||||||
|
my @agents_bd = [];
|
||||||
|
my $result = 0;
|
||||||
|
|
||||||
if ($group == 0){
|
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');
|
||||||
|
|
||||||
|
# Update bbdd.
|
||||||
db_do ($dbh, "UPDATE tagente SET disabled = 1");
|
db_do ($dbh, "UPDATE tagente SET disabled = 1");
|
||||||
}
|
}
|
||||||
else {
|
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.
|
||||||
db_do ($dbh, "UPDATE tagente SET disabled = 1 WHERE id_grupo = $group");
|
db_do ($dbh, "UPDATE tagente SET disabled = 1 WHERE id_grupo = $group");
|
||||||
}
|
}
|
||||||
exit;
|
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
@ -305,69 +380,35 @@ sub pandora_disable_group ($$$) {
|
||||||
sub pandora_enable_group ($$$) {
|
sub pandora_enable_group ($$$) {
|
||||||
my ($conf, $dbh, $group) = @_;
|
my ($conf, $dbh, $group) = @_;
|
||||||
|
|
||||||
|
my @agents_bd = [];
|
||||||
|
my $result = 0;
|
||||||
|
|
||||||
if ($group == 0){
|
if ($group == 0){
|
||||||
# Extraigo todos los nombres de los agentes de pandora si es para all = 0
|
# Extract all the names of the pandora agents if it is for all = 0.
|
||||||
# my @agents = get_db_rows ($dbh, 'SELECT nombre FROM tagente');
|
@agents_bd = get_db_rows ($dbh, 'SELECT nombre FROM tagente');
|
||||||
|
|
||||||
my @agents = glob($conf->{incomingdir}.'/conf/*');
|
# Update bbdd.
|
||||||
|
$result = db_do ($dbh, "UPDATE tagente SET disabled = 0");
|
||||||
#my %remote_agents = map {
|
|
||||||
# if ( $_ =~ /.*\/(.*?)\.conf$/) {
|
|
||||||
# $1 => 1
|
|
||||||
# } else {
|
|
||||||
# undef
|
|
||||||
# }
|
|
||||||
#} @agents;
|
|
||||||
|
|
||||||
use Data::Dumper;
|
|
||||||
|
|
||||||
foreach my $route_agent (@agents) {
|
|
||||||
print Dumper('++++++++++++++++++++++++++++++++++++++++++++++++++++++');
|
|
||||||
# Leo el conf de cada agente
|
|
||||||
#my $conf_txt = enterprise_hook('read_agent_conf_file',[$conf, $remote_agent]);
|
|
||||||
|
|
||||||
#my $agent_conf_file = $pa_config->{incomingdir}.'/conf/'.md5(encode_utf8(safe_output($remote_agent))).'.conf';
|
|
||||||
|
|
||||||
# If the module is not local, do nothing
|
|
||||||
if(!defined($route_agent) || !(-f $route_agent)){
|
|
||||||
next;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($route_agent =~ /.srv./) {
|
|
||||||
next;
|
|
||||||
}
|
|
||||||
|
|
||||||
my $conf_file_txt = read_file($route_agent);
|
|
||||||
if(!$conf_file_txt) {
|
|
||||||
next;
|
|
||||||
}
|
|
||||||
|
|
||||||
my $validate_conf = enterprise_hook('validate_readed_conf_file',[$conf_file_txt]);
|
|
||||||
print Dumper($validate_conf);
|
|
||||||
if (!$validate_conf) {
|
|
||||||
next;
|
|
||||||
}
|
|
||||||
|
|
||||||
print Dumper($conf_file_txt);
|
|
||||||
|
|
||||||
print Dumper('-----------------------------------------------------------');
|
|
||||||
|
|
||||||
# # De los agentes que existan
|
|
||||||
# # checheo el campo disabled se lo pongo a 0 con expresion regular imagino
|
|
||||||
# my $content = $conf_txt
|
|
||||||
|
|
||||||
# # Escribo el conf
|
|
||||||
# write_agent_conf_file($pa_config, $agent_name, $content);
|
|
||||||
}
|
|
||||||
|
|
||||||
# actualizo la bbdd
|
|
||||||
db_do ($dbh, "UPDATE tagente SET disabled = 0");
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
# my @remote_agents = get_db_rows ($dbh, 'SELECT nombre FROM tagente WHERE id_grupo = ?', $group);
|
# Extract all the names of the pandora agents if it is for group.
|
||||||
db_do ($dbh, "UPDATE tagente SET disabled = 0 WHERE id_grupo = $group");
|
@agents_bd = get_db_rows ($dbh, 'SELECT nombre FROM tagente WHERE id_grupo = ?', $group);
|
||||||
|
|
||||||
|
# Update bbdd.
|
||||||
|
$result = db_do ($dbh, "UPDATE tagente SET disabled = 0 WHERE id_grupo = $group");
|
||||||
}
|
}
|
||||||
exit;
|
|
||||||
|
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',
|
||||||
|
'0'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
##############################################################################
|
##############################################################################
|
||||||
|
|
Loading…
Reference in New Issue