simplified agents

This commit is contained in:
fbsanchez 2020-04-16 14:06:41 +02:00
parent 0614c4b6ce
commit fa0b5760a9
2 changed files with 42 additions and 11 deletions

View File

@ -1059,18 +1059,20 @@ sub PandoraFMS::Recon::Base::report_scanned_agents($;$) {
);
# Add found IP addresses to the agent.
foreach my $ip_addr ($self->get_addresses($data->{'agent'}{'direccion'})) {
my $addr_id = get_addr_id($self->{'dbh'}, $ip_addr);
$addr_id = add_address($self->{'dbh'}, $ip_addr) unless ($addr_id > 0);
next unless ($addr_id > 0);
if (ref($data->{'other_ips'}) eq 'ARRAY') {
foreach my $ip_addr (@{$data->{'other_ips'}}) {
my $addr_id = get_addr_id($self->{'dbh'}, $ip_addr);
$addr_id = add_address($self->{'dbh'}, $ip_addr) unless ($addr_id > 0);
next unless ($addr_id > 0);
# Assign the new address to the agent
my $agent_addr_id = get_agent_addr_id($self->{'dbh'}, $addr_id, $agent_id);
if ($agent_addr_id <= 0) {
db_do(
$self->{'dbh'}, 'INSERT INTO taddress_agent (`id_a`, `id_agent`)
VALUES (?, ?)', $addr_id, $agent_id
);
# Assign the new address to the agent
my $agent_addr_id = get_agent_addr_id($self->{'dbh'}, $addr_id, $agent_id);
if ($agent_addr_id <= 0) {
db_do(
$self->{'dbh'}, 'INSERT INTO taddress_agent (`id_a`, `id_agent`)
VALUES (?, ?)', $addr_id, $agent_id
);
}
}
}

View File

@ -172,6 +172,9 @@ sub new {
# Visited devices (initially empty).
visited_devices => {},
# Inverse relationship for visited devices (initially empty).
addresses => {},
# Per device VLAN cache.
vlan_cache => {},
vlan_cache_enabled => 1, # User configuration. Globally disables the VLAN cache.
@ -309,6 +312,26 @@ sub add_addresses($$$) {
my ($self, $device, $ip_address) = @_;
$self->{'visited_devices'}->{$device}->{'addr'}->{$ip_address} = '';
# Inverse relationship.
$self->{'addresses'}{$ip_address} = $device;
# Update IP references.
if (ref($self->{'agents_found'}{$device}) eq 'HASH') {
my @addresses = $self->get_addresses($device);
$self->{'agents_found'}{$device}{'other_ips'} = \@addresses;
$self->call('message', 'New IP detected for '.$device.': '.$ip_address, 5);
}
}
################################################################################
# Get main address from given address (multi addressed devices).
################################################################################
sub get_main_address($$) {
my ($self, $addr) = @_;
return $self->{'addresses'}{$addr};
}
################################################################################
@ -1322,6 +1345,10 @@ sub remote_arp($$) {
sub prepare_agent($$) {
my ($self, $addr) = @_;
# Avoid multi-ip agent. No reference, is first encounter.
my $main_address = $self->get_main_address($addr);
return unless is_empty($main_address);
# Resolve hostnames.
my $host_name = (($self->{'resolve_names'} == 1) ? gethostbyaddr(inet_aton($addr), AF_INET) : $addr);
@ -1333,12 +1360,14 @@ sub prepare_agent($$) {
# Already initialized.
return if ref($self->{'agents_found'}->{$host_name}) eq 'HASH';
my @addresses = $self->get_addresses($addr);
$self->{'agents_found'}->{$addr} = {
'agent' => {
'nombre' => $host_name,
'direccion' => $addr,
'alias' => $host_name,
},
'other_ips' => \@addresses,
'pen' => $self->{'pen'}{$addr},
'modules' => [],
};