diff --git a/lib/App/Netdisco/Util/Nbtstat.pm b/lib/App/Netdisco/Util/Nbtstat.pm index a21f0624..6b77648f 100644 --- a/lib/App/Netdisco/Util/Nbtstat.pm +++ b/lib/App/Netdisco/Util/Nbtstat.pm @@ -158,20 +158,27 @@ sub store_nbt { my ( $hash_ref, $now ) = @_; $now ||= 'LOCALTIMESTAMP'; - schema(vars->{'tenant'})->resultset('NodeNbt')->update_or_create( - { mac => $hash_ref->{'mac'}, - ip => $hash_ref->{'ip'}, - nbname => $hash_ref->{'nbname'}, - domain => $hash_ref->{'domain'}, - server => $hash_ref->{'server'}, - nbuser => $hash_ref->{'nbuser'}, - active => \'true', - time_last => \$now, - }, - { key => 'primary', - for => 'update', - } - ); + schema(vars->{'tenant'})->txn_do(sub { + my $row = schema(vars->{'tenant'})->resultset('NodeNbt')->update_or_new( + { mac => $hash_ref->{'mac'}, + ip => $hash_ref->{'ip'}, + nbname => $hash_ref->{'nbname'}, + domain => $hash_ref->{'domain'}, + server => $hash_ref->{'server'}, + nbuser => $hash_ref->{'nbuser'}, + active => \'true', + time_last => \$now, + }, + { key => 'primary', + for => 'update', + } + ); + + if (! $row->in_storage) { + $row->set_column(time_first => \$now); + $row->insert; + } + }); return; } diff --git a/lib/App/Netdisco/Util/Node.pm b/lib/App/Netdisco/Util/Node.pm index 1ac8f4d6..717d8efb 100644 --- a/lib/App/Netdisco/Util/Node.pm +++ b/lib/App/Netdisco/Util/Node.pm @@ -176,13 +176,13 @@ sub store_arp { debug sprintf 'store_arp - mac %s ip %s', $mac->as_ieee, $ip; schema(vars->{'tenant'})->txn_do(sub { - my $current = schema(vars->{'tenant'})->resultset('NodeIp') + schema(vars->{'tenant'})->resultset('NodeIp') ->search( { ip => $ip, -bool => 'active'}, { columns => [qw/mac ip/] })->update({active => \'false'}); - schema(vars->{'tenant'})->resultset('NodeIp') - ->update_or_create( + my $row = schema(vars->{'tenant'})->resultset('NodeIp') + ->update_or_new( { mac => $mac->as_ieee, ip => $ip, @@ -194,6 +194,11 @@ sub store_arp { key => 'primary', for => 'update', }); + + if (! $row->in_storage) { + $row->set_column(time_first => \$now); + $row->insert; + } }); } diff --git a/lib/App/Netdisco/Worker/Plugin/Macsuck/Nodes.pm b/lib/App/Netdisco/Worker/Plugin/Macsuck/Nodes.pm index 7b0fa81a..ebd2df1d 100644 --- a/lib/App/Netdisco/Worker/Plugin/Macsuck/Nodes.pm +++ b/lib/App/Netdisco/Worker/Plugin/Macsuck/Nodes.pm @@ -249,7 +249,7 @@ sub store_node { })->update( { active => \'false' } ); # new data - $nodes->update_or_create( + my $row = $nodes->update_or_new( { switch => $ip, port => $port, @@ -265,6 +265,11 @@ sub store_node { for => 'update', } ); + + if (! $row->in_storage) { + $row->set_column(time_first => \$now); + $row->insert; + } }); }