From cf23636ddfb93469c3540fa902970eba21b7cdab Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Mon, 13 Jan 2014 18:43:59 +0000 Subject: [PATCH] archive disappeared nodes from device - really important! --- Netdisco/lib/App/Netdisco/Core/Macsuck.pm | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/Netdisco/lib/App/Netdisco/Core/Macsuck.pm b/Netdisco/lib/App/Netdisco/Core/Macsuck.pm index 9c92dd53..7426ce9e 100644 --- a/Netdisco/lib/App/Netdisco/Core/Macsuck.pm +++ b/Netdisco/lib/App/Netdisco/Core/Macsuck.pm @@ -57,8 +57,8 @@ sub do_macsuck { my $ip = $device->ip; # would be possible just to use now() on updated records, but by using this - # same value for them all, we _can_ if we want add a job at the end to - # select and do something with the updated set (no reason to yet, though) + # same value for them all, we can if we want add a job at the end to + # select and do something with the updated set (see set archive, below) my $now = 'to_timestamp('. (join '.', gettimeofday) .')'; my $total_nodes = 0; @@ -115,8 +115,18 @@ sub do_macsuck { } } - debug sprintf ' [%s] macsuck - %s forwarding table entries', + debug sprintf ' [%s] macsuck - %s updated forwarding table entries', $ip, $total_nodes; + + # a use for $now ... need to archive dissapeared nodes + my $archived = schema('netdisco')->resultset('Node')->search({ + switch => $ip, + time_last => { '<' => \$now }, + })->update({ active => \'false' }); + + debug sprintf ' [%s] macsuck - removed %s fwd table entries to archive', + $ip, $archived; + $device->update({last_macsuck => \$now}); }