* Added a missing modified_date to ip_addresses in Database->get_ip_addresses().

* Updated scan-network to purge old historical ip_addresses when clearing duplicates now.

Signed-off-by: Digimer <digimer@alteeve.ca>
main
Digimer 3 years ago
parent aa64b0f7fa
commit e6dcff1cf1
  1. 10
      Anvil/Tools/Database.pm
  2. 2
      Anvil/Tools/System.pm
  3. 18
      scancore-agents/scan-network/scan-network
  4. 1
      tools/anvil-daemon

@ -3779,7 +3779,15 @@ AND
{ {
# This isn't a network we should know about (ie: it might be a stray 'virbrX' # This isn't a network we should know about (ie: it might be a stray 'virbrX'
# birdge), delete this IP. # birdge), delete this IP.
my $query = "UPDATE ip_addresses SET ip_address_note = 'DELETED' WHERE ip_address_uuid = ".$anvil->Database->quote($ip_address_uuid).";"; my $query = "
UPDATE
ip_addresses
SET
ip_address_note = 'DELETED',
modified_date = ".$anvil->Database->quote($anvil->Database->refresh_timestamp)."
WHERE
ip_address_uuid = ".$anvil->Database->quote($ip_address_uuid)."
;";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query }});
$anvil->Database->write({query => $query, source => $THIS_FILE, line => __LINE__}); $anvil->Database->write({query => $query, source => $THIS_FILE, line => __LINE__});
next; next;

@ -5051,7 +5051,7 @@ sub update_hosts
$anvil->Database->get_ip_addresses({debug => $debug}); $anvil->Database->get_ip_addresses({debug => $debug});
# Load the IPs we manage. If we find any entries for these that we don't expect, we'll remove them. # Load the IPs we manage. If we find any entries for these that we don't expect, we'll remove them.
$anvil->Database->get_ip_addresses({debug => $debug}); $anvil->Network->load_ips({debug => $debug});
foreach my $host_uuid (keys %{$anvil->data->{hosts}{host_uuid}}) foreach my $host_uuid (keys %{$anvil->data->{hosts}{host_uuid}})
{ {

@ -1456,9 +1456,14 @@ ORDER BY
uuid => $ip_address_uuid, uuid => $ip_address_uuid,
}}); }});
my $query = "DELETE FROM ip_addresses WHERE ip_address_uuid = ".$anvil->Database->quote($ip_address_uuid).";"; my $queries = [];
push @{$queries}, "DELETE FROM history.ip_addresses WHERE ip_address_uuid = ".$anvil->Database->quote($ip_address_uuid).";";
push @{$queries}, "DELETE FROM ip_addresses WHERE ip_address_uuid = ".$anvil->Database->quote($ip_address_uuid).";";
foreach my $query (@{$queries})
{
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }});
$anvil->Database->write({query => $query, source => $THIS_FILE, line => __LINE__}); }
$anvil->Database->write({query => $queries, source => $THIS_FILE, line => __LINE__});
$count--; $count--;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { count => $count }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { count => $count }});
@ -1476,9 +1481,14 @@ ORDER BY
uuid => $ip_address_uuid, uuid => $ip_address_uuid,
}}); }});
my $query = "DELETE FROM ip_addresses WHERE ip_address_uuid = ".$anvil->Database->quote($ip_address_uuid).";"; my $queries = [];
push @{$queries}, "DELETE FROM history.ip_addresses WHERE ip_address_uuid = ".$anvil->Database->quote($ip_address_uuid).";";
push @{$queries}, "DELETE FROM ip_addresses WHERE ip_address_uuid = ".$anvil->Database->quote($ip_address_uuid).";";
foreach my $query (@{$queries})
{
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }});
$anvil->Database->write({query => $query, source => $THIS_FILE, line => __LINE__}); }
$anvil->Database->write({query => $queries, source => $THIS_FILE, line => __LINE__});
$count--; $count--;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { count => $count }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { count => $count }});

@ -143,6 +143,7 @@ $anvil->data->{switches}{'refresh-json'} = "";
$anvil->data->{switches}{'run-once'} = 0; $anvil->data->{switches}{'run-once'} = 0;
$anvil->data->{switches}{'main-loop-only'} = 0; $anvil->data->{switches}{'main-loop-only'} = 0;
$anvil->data->{switches}{'no-start'} = 0; $anvil->data->{switches}{'no-start'} = 0;
$anvil->data->{switches}{'purge'} = 0;
$anvil->data->{switches}{'startup-only'} = 0; $anvil->data->{switches}{'startup-only'} = 0;
$anvil->Get->switches; $anvil->Get->switches;

Loading…
Cancel
Save