#949 replace now() with LOCALTIMESTAMP and cast to_timestamp() as ::timestamp
This commit is contained in:
@@ -23,12 +23,12 @@ __PACKAGE__->result_source_instance->view_definition(<<ENDSQL
|
|||||||
sum(CASE
|
sum(CASE
|
||||||
WHEN ( (dp.type IS NULL OR dp.type !~* '^(53|ieee8023adLag|propVirtual|l2vlan|l3ipvlan|135|136|137)\$')
|
WHEN ( (dp.type IS NULL OR dp.type !~* '^(53|ieee8023adLag|propVirtual|l2vlan|l3ipvlan|135|136|137)\$')
|
||||||
AND dp.up_admin = 'up' AND dp.up != 'up'
|
AND dp.up_admin = 'up' AND dp.up != 'up'
|
||||||
AND (age(now(), to_timestamp(extract(epoch from d.last_discover) - (d.uptime/100))) < ?::interval)
|
AND (age(LOCALTIMESTAMP, to_timestamp(extract(epoch from d.last_discover) - (d.uptime/100))::timestamp) < ?::interval)
|
||||||
AND (last_node.time_last IS NULL OR (age(now(), last_node.time_last)) > ?::interval) )
|
AND (last_node.time_last IS NULL OR (age(LOCALTIMESTAMP, last_node.time_last)) > ?::interval) )
|
||||||
THEN 1
|
THEN 1
|
||||||
WHEN ( (dp.type IS NULL OR dp.type !~* '^(53|ieee8023adLag|propVirtual|l2vlan|l3ipvlan|135|136|137)\$')
|
WHEN ( (dp.type IS NULL OR dp.type !~* '^(53|ieee8023adLag|propVirtual|l2vlan|l3ipvlan|135|136|137)\$')
|
||||||
AND dp.up_admin = 'up' AND dp.up != 'up'
|
AND dp.up_admin = 'up' AND dp.up != 'up'
|
||||||
AND (age(now(), to_timestamp(extract(epoch from d.last_discover) - (d.uptime - dp.lastchange)/100)) > ?::interval) )
|
AND (age(LOCALTIMESTAMP, to_timestamp(extract(epoch from d.last_discover) - (d.uptime - dp.lastchange)/100)::timestamp) > ?::interval) )
|
||||||
THEN 1
|
THEN 1
|
||||||
ELSE 0
|
ELSE 0
|
||||||
END) as ports_free
|
END) as ports_free
|
||||||
|
|||||||
@@ -70,9 +70,9 @@ sub with_is_free {
|
|||||||
# NOTE this query is in `git grep 'THREE PLACES'`
|
# NOTE this query is in `git grep 'THREE PLACES'`
|
||||||
\["me.up_admin = 'up' AND me.up != 'up' AND "
|
\["me.up_admin = 'up' AND me.up != 'up' AND "
|
||||||
."(me.type IS NULL OR me.type !~* '^(53|ieee8023adLag|propVirtual|l2vlan|l3ipvlan|135|136|137)\$') AND "
|
."(me.type IS NULL OR me.type !~* '^(53|ieee8023adLag|propVirtual|l2vlan|l3ipvlan|135|136|137)\$') AND "
|
||||||
."((age(now(), to_timestamp(extract(epoch from device.last_discover) - (device.uptime/100))) < ?::interval "
|
."((age(LOCALTIMESTAMP, to_timestamp(extract(epoch from device.last_discover) - (device.uptime/100))::timestamp) < ?::interval "
|
||||||
."AND (last_node.time_last IS NULL OR age(now(), last_node.time_last) > ?::interval)) "
|
."AND (last_node.time_last IS NULL OR age(LOCALTIMESTAMP, last_node.time_last) > ?::interval)) "
|
||||||
."OR age(now(), to_timestamp(extract(epoch from device.last_discover) - (device.uptime - me.lastchange)/100)) > ?::interval)",
|
."OR age(LOCALTIMESTAMP, to_timestamp(extract(epoch from device.last_discover) - (device.uptime - me.lastchange)/100)::timestamp) > ?::interval)",
|
||||||
[{} => $interval],[ {} => $interval],[ {} => $interval]] },
|
[{} => $interval],[ {} => $interval],[ {} => $interval]] },
|
||||||
join => [qw/device last_node/],
|
join => [qw/device last_node/],
|
||||||
});
|
});
|
||||||
@@ -107,14 +107,14 @@ sub only_free_ports {
|
|||||||
],
|
],
|
||||||
-or => [
|
-or => [
|
||||||
-and => [
|
-and => [
|
||||||
\["age(now(), to_timestamp(extract(epoch from device.last_discover) - (device.uptime/100))) < ?::interval",
|
\["age(LOCALTIMESTAMP, to_timestamp(extract(epoch from device.last_discover) - (device.uptime/100))::timestamp) < ?::interval",
|
||||||
[{} => $interval]],
|
[{} => $interval]],
|
||||||
-or => [
|
-or => [
|
||||||
'last_node.time_last' => undef,
|
'last_node.time_last' => undef,
|
||||||
\["age(now(), last_node.time_last) > ?::interval", [{} => $interval]],
|
\["age(LOCALTIMESTAMP, last_node.time_last) > ?::interval", [{} => $interval]],
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
\["age(now(), to_timestamp(extract(epoch from device.last_discover) - (device.uptime - me.lastchange)/100)) > ?::interval",
|
\["age(LOCALTIMESTAMP, to_timestamp(extract(epoch from device.last_discover) - (device.uptime - me.lastchange)/100)::timestamp) > ?::interval",
|
||||||
[{} => $interval]],
|
[{} => $interval]],
|
||||||
],
|
],
|
||||||
},{ join => [qw/device last_node/] },
|
},{ join => [qw/device last_node/] },
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ register_worker({ phase => 'early',
|
|||||||
# select and do something with the updated set (see set archive, below)
|
# select and do something with the updated set (see set archive, below)
|
||||||
vars->{'timestamp'} = ($job->is_offline and $job->entered)
|
vars->{'timestamp'} = ($job->is_offline and $job->entered)
|
||||||
? (schema('netdisco')->storage->dbh->quote($job->entered) .'::timestamp')
|
? (schema('netdisco')->storage->dbh->quote($job->entered) .'::timestamp')
|
||||||
: 'to_timestamp('. (join '.', gettimeofday) .')';
|
: 'to_timestamp('. (join '.', gettimeofday) .')::timestamp';
|
||||||
|
|
||||||
# initialise the cache
|
# initialise the cache
|
||||||
vars->{'arps'} ||= [];
|
vars->{'arps'} ||= [];
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ register_worker({ phase => 'main', driver => 'snmp' }, sub {
|
|||||||
my @subnets = gather_subnets($device);
|
my @subnets = gather_subnets($device);
|
||||||
# TODO: IPv6 subnets
|
# TODO: IPv6 subnets
|
||||||
|
|
||||||
my $now = 'to_timestamp('. (join '.', gettimeofday) .')';
|
my $now = 'to_timestamp('. (join '.', gettimeofday) .')::timestamp';
|
||||||
store_subnet($_, $now) for @subnets;
|
store_subnet($_, $now) for @subnets;
|
||||||
|
|
||||||
return Status->info(sprintf ' [%s] arpnip - processed %s Subnet entries',
|
return Status->info(sprintf ' [%s] arpnip - processed %s Subnet entries',
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ register_worker({ phase => 'early',
|
|||||||
# select and do something with the updated set (see set archive, below)
|
# select and do something with the updated set (see set archive, below)
|
||||||
vars->{'timestamp'} = ($job->is_offline and $job->entered)
|
vars->{'timestamp'} = ($job->is_offline and $job->entered)
|
||||||
? (schema('netdisco')->storage->dbh->quote($job->entered) .'::timestamp')
|
? (schema('netdisco')->storage->dbh->quote($job->entered) .'::timestamp')
|
||||||
: 'to_timestamp('. (join '.', gettimeofday) .')';
|
: 'to_timestamp('. (join '.', gettimeofday) .')::timestamp';
|
||||||
|
|
||||||
# initialise the cache
|
# initialise the cache
|
||||||
vars->{'fwtable'} ||= {};
|
vars->{'fwtable'} ||= {};
|
||||||
@@ -225,13 +225,13 @@ All four fields in the tuple are required. If you don't know the VLAN ID,
|
|||||||
Netdisco supports using ID "0".
|
Netdisco supports using ID "0".
|
||||||
|
|
||||||
Optionally, a fifth argument can be the literal string passed to the time_last
|
Optionally, a fifth argument can be the literal string passed to the time_last
|
||||||
field of the database record. If not provided, it defaults to C<now()>.
|
field of the database record. If not provided, it defaults to C<LOCALTIMESTAMP>.
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
sub store_node {
|
sub store_node {
|
||||||
my ($ip, $vlan, $port, $mac, $now) = @_;
|
my ($ip, $vlan, $port, $mac, $now) = @_;
|
||||||
$now ||= 'now()';
|
$now ||= 'LOCALTIMESTAMP';
|
||||||
$vlan ||= 0;
|
$vlan ||= 0;
|
||||||
|
|
||||||
schema('netdisco')->txn_do(sub {
|
schema('netdisco')->txn_do(sub {
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ register_worker({ phase => 'main', driver => 'snmp' }, sub {
|
|||||||
my $snmp = App::Netdisco::Transport::SNMP->reader_for($device)
|
my $snmp = App::Netdisco::Transport::SNMP->reader_for($device)
|
||||||
or return Status->defer("macsuck failed: could not SNMP connect to $device");
|
or return Status->defer("macsuck failed: could not SNMP connect to $device");
|
||||||
|
|
||||||
my $now = 'to_timestamp('. (join '.', gettimeofday) .')';
|
my $now = 'to_timestamp('. (join '.', gettimeofday) .')::timestamp';
|
||||||
|
|
||||||
my $cd11_txrate = $snmp->cd11_txrate;
|
my $cd11_txrate = $snmp->cd11_txrate;
|
||||||
return unless $cd11_txrate and scalar keys %$cd11_txrate;
|
return unless $cd11_txrate and scalar keys %$cd11_txrate;
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ register_worker({ phase => 'main' }, sub {
|
|||||||
-bool => 'me.active',
|
-bool => 'me.active',
|
||||||
-bool => 'nodes.active',
|
-bool => 'nodes.active',
|
||||||
'nodes.switch' => $host,
|
'nodes.switch' => $host,
|
||||||
'me.time_last' => \[ '>= now() - ?::interval', $interval ],
|
'me.time_last' => \[ '>= LOCALTIMESTAMP - ?::interval', $interval ],
|
||||||
},{
|
},{
|
||||||
join => 'nodes',
|
join => 'nodes',
|
||||||
columns => 'ip',
|
columns => 'ip',
|
||||||
@@ -32,7 +32,7 @@ register_worker({ phase => 'main' }, sub {
|
|||||||
|
|
||||||
# Unless we have IPs don't bother
|
# Unless we have IPs don't bother
|
||||||
if (scalar @ips) {
|
if (scalar @ips) {
|
||||||
my $now = 'to_timestamp('. (join '.', gettimeofday) .')';
|
my $now = 'to_timestamp('. (join '.', gettimeofday) .')::timestamp';
|
||||||
my $resolved_nodes = nbtstat_resolve_async(\@ips);
|
my $resolved_nodes = nbtstat_resolve_async(\@ips);
|
||||||
|
|
||||||
# update node_nbt with status entries
|
# update node_nbt with status entries
|
||||||
|
|||||||
Reference in New Issue
Block a user