Merge branch 'ent-5575-rebuild-recon-y-modulos-con-pen' into 'develop'
Windows environment spaces in binary file names See merge request artica/pandorafms!3188
This commit is contained in:
commit
75f5df874b
|
@ -26,7 +26,7 @@ use Thread::Semaphore;
|
|||
|
||||
use IO::Socket::INET;
|
||||
use POSIX qw(strftime ceil);
|
||||
use JSON qw(decode_json encode_json);
|
||||
use JSON;
|
||||
use Encode qw(encode_utf8);
|
||||
use MIME::Base64;
|
||||
|
||||
|
@ -336,14 +336,14 @@ sub exec_recon_script ($$$) {
|
|||
|
||||
my $macros = safe_output($task->{'macros'});
|
||||
|
||||
# \r and \n should be escaped for decode_json().
|
||||
# \r and \n should be escaped for p_decode_json().
|
||||
$macros =~ s/\n/\\n/g;
|
||||
$macros =~ s/\r/\\r/g;
|
||||
my $decoded_macros;
|
||||
|
||||
if ($macros) {
|
||||
eval {
|
||||
$decoded_macros = decode_json(encode_utf8($macros));
|
||||
$decoded_macros = p_decode_json($pa_config, $macros);
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -980,7 +980,7 @@ sub PandoraFMS::Recon::Base::report_scanned_agents($;$) {
|
|||
my $data;
|
||||
eval {
|
||||
local $SIG{__DIE__};
|
||||
$data = decode_json(decode_base64($row->{'data'}));
|
||||
$data = p_decode_json($self->{'pa_config'}, decode_base64($row->{'data'}));
|
||||
};
|
||||
if ($@) {
|
||||
$self->call('message', "ERROR JSON: $@", 3);
|
||||
|
@ -1245,7 +1245,7 @@ sub PandoraFMS::Recon::Base::report_scanned_agents($;$) {
|
|||
eval {
|
||||
local $SIG{__DIE__};
|
||||
$encoded = encode_base64(
|
||||
encode_json($data)
|
||||
p_encode_json($self->{'pa_config'}, $data)
|
||||
);
|
||||
};
|
||||
|
||||
|
@ -1344,7 +1344,7 @@ sub PandoraFMS::Recon::Base::report_scanned_agents($;$) {
|
|||
eval {
|
||||
local $SIG{__DIE__};
|
||||
$encoded = encode_base64(
|
||||
encode_json($self->{'agents_found'}->{$addr})
|
||||
p_encode_json($self->{'pa_config'}, $self->{'agents_found'}->{$addr})
|
||||
);
|
||||
};
|
||||
|
||||
|
@ -1684,17 +1684,25 @@ sub PandoraFMS::Recon::Base::update_progress ($$) {
|
|||
my ($self, $progress) = @_;
|
||||
|
||||
my $stats = {};
|
||||
if (defined($self->{'summary'}) && $self->{'summary'} ne '') {
|
||||
$stats->{'summary'} = $self->{'summary'};
|
||||
eval {
|
||||
local $SIG{__DIE__};
|
||||
if (defined($self->{'summary'}) && $self->{'summary'} ne '') {
|
||||
$stats->{'summary'} = $self->{'summary'};
|
||||
}
|
||||
|
||||
$stats->{'step'} = $self->{'step'};
|
||||
$stats->{'c_network_name'} = $self->{'c_network_name'};
|
||||
$stats->{'c_network_percent'} = $self->{'c_network_percent'};
|
||||
|
||||
# Store progress, last contact and overall status.
|
||||
db_do ($self->{'dbh'}, 'UPDATE trecon_task SET utimestamp = ?, status = ?, summary = ? WHERE id_rt = ?',
|
||||
time (), $progress, p_encode_json($self->{'pa_config'}, $stats), $self->{'task_id'});
|
||||
};
|
||||
if ($@) {
|
||||
$self->call('message', "Problems updating progress $@", 5);
|
||||
db_do ($self->{'dbh'}, 'UPDATE trecon_task SET utimestamp = ?, status = ?, summary = ? WHERE id_rt = ?',
|
||||
time (), $progress, "{}", $self->{'task_id'});
|
||||
}
|
||||
|
||||
$stats->{'step'} = $self->{'step'};
|
||||
$stats->{'c_network_name'} = $self->{'c_network_name'};
|
||||
$stats->{'c_network_percent'} = $self->{'c_network_percent'};
|
||||
|
||||
# Store progress, last contact and overall status.
|
||||
db_do ($self->{'dbh'}, 'UPDATE trecon_task SET utimestamp = ?, status = ?, summary = ? WHERE id_rt = ?',
|
||||
time (), $progress, encode_json($stats), $self->{'task_id'});
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
|
@ -2109,16 +2109,16 @@ sub snmp_get_value($$$) {
|
|||
my ($self, $device, $oid) = @_;
|
||||
|
||||
my $effective_oid = $oid;
|
||||
if (is_enabled($self->{'translate_snmp'})) {
|
||||
if (is_enabled($self->{'translate_snmp'}) && $oid !~ /^[\.\d]+$/) {
|
||||
$effective_oid = `snmptranslate $oid -On 2>$DEVNULL`;
|
||||
chomp($effective_oid);
|
||||
$effective_oid =~ s/[\r\n]//g;
|
||||
}
|
||||
|
||||
my @output = $self->snmp_get($device, $effective_oid);
|
||||
|
||||
|
||||
foreach my $line (@output) {
|
||||
chomp($line);
|
||||
return $1 if ($line =~ /^$effective_oid\s+=\s+\S+:\s+(.*)$/);
|
||||
$line =~ s/[\r\n]//g;
|
||||
return $1 if ($line =~ /^$effective_oid\s+=\s+\S+:\s+(.*)/);
|
||||
}
|
||||
|
||||
return undef;
|
||||
|
|
|
@ -31,6 +31,9 @@ use LWP::UserAgent;
|
|||
use threads;
|
||||
use threads::shared;
|
||||
|
||||
use JSON;
|
||||
use Encode qw/decode_utf8 encode_utf8/;
|
||||
|
||||
use lib '/usr/lib/perl5';
|
||||
use PandoraFMS::Sendmail;
|
||||
|
||||
|
@ -152,6 +155,8 @@ our @EXPORT = qw(
|
|||
dateTimeToTimestamp
|
||||
get_user_agent
|
||||
ui_get_full_url
|
||||
p_encode_json
|
||||
p_decode_json
|
||||
);
|
||||
|
||||
# ID of the different servers
|
||||
|
@ -1458,7 +1463,7 @@ sub pandora_block_ping($@) {
|
|||
|
||||
if (-x $pa_config->{'fping'}) {
|
||||
# fping timeout in milliseconds
|
||||
$cmd = $pa_config->{'fping'} . " -a -q -t " . (1000 * $pa_config->{'networktimeout'}) . " " . (join (' ', @hosts));
|
||||
$cmd = '"'.$pa_config->{'fping'} . '" -a -q -t ' . (1000 * $pa_config->{'networktimeout'}) . " " . (join (' ', @hosts));
|
||||
@output = `$cmd 2>$DEVNULL`;
|
||||
} else {
|
||||
# Ping scan
|
||||
|
@ -2353,6 +2358,55 @@ sub ui_get_full_url {
|
|||
|
||||
}
|
||||
|
||||
################################################################################
|
||||
# Encodes a json.
|
||||
################################################################################
|
||||
sub p_encode_json {
|
||||
my ($pa_config, $data) = @_;
|
||||
|
||||
# Initialize JSON manager.
|
||||
my $json = JSON->new->allow_nonref;
|
||||
my $encoded_data;
|
||||
|
||||
eval {
|
||||
local $SIG{__DIE__};
|
||||
if ($JSON::VERSION > 2.90) {
|
||||
$encoded_data = $json->encode($data);
|
||||
} else {
|
||||
$encoded_data = encode_utf8($json->encode($data));
|
||||
}
|
||||
};
|
||||
if ($@){
|
||||
if (defined($data)) {
|
||||
logger($pa_config, 'Failed to encode data: '.$@, 5);
|
||||
}
|
||||
}
|
||||
|
||||
return $encoded_data;
|
||||
}
|
||||
|
||||
################################################################################
|
||||
# Dencodes a json.
|
||||
################################################################################
|
||||
sub p_decode_json {
|
||||
my ($pa_config, $data) = @_;
|
||||
|
||||
# Initialize JSON manager.
|
||||
my $json = JSON->new->allow_nonref;
|
||||
my $decoded_data;
|
||||
|
||||
if ($JSON::VERSION > 2.90) {
|
||||
$decoded_data = $json->decode($data);
|
||||
} else {
|
||||
if (!is_empty($decoded_data)) {
|
||||
$decoded_data = decode_json($data);
|
||||
}
|
||||
}
|
||||
|
||||
return $decoded_data;
|
||||
}
|
||||
|
||||
|
||||
1;
|
||||
__END__
|
||||
|
||||
|
|
Loading…
Reference in New Issue