#949 replace other occurances of now() with LOCALTIMESTAMP
This commit is contained in:
@@ -168,7 +168,7 @@ sub jq_getsome {
|
|||||||
-exists => $jobs->search({
|
-exists => $jobs->search({
|
||||||
job => { '>' => $job->id },
|
job => { '>' => $job->id },
|
||||||
status => { -like => 'queued-%' },
|
status => { -like => 'queued-%' },
|
||||||
started => \[q/> (now() - ?::interval)/, setting('jobs_stale_after')],
|
started => \[q/> (LOCALTIMESTAMP - ?::interval)/, setting('jobs_stale_after')],
|
||||||
%job_properties,
|
%job_properties,
|
||||||
})->as_query,
|
})->as_query,
|
||||||
}],
|
}],
|
||||||
@@ -187,7 +187,7 @@ sub jq_locked {
|
|||||||
my @returned = ();
|
my @returned = ();
|
||||||
my $rs = schema(vars->{'tenant'})->resultset('Admin')->search({
|
my $rs = schema(vars->{'tenant'})->resultset('Admin')->search({
|
||||||
status => ('queued-'. setting('workers')->{'BACKEND'}),
|
status => ('queued-'. setting('workers')->{'BACKEND'}),
|
||||||
started => \[q/> (now() - ?::interval)/, setting('jobs_stale_after')],
|
started => \[q/> (LOCALTIMESTAMP - ?::interval)/, setting('jobs_stale_after')],
|
||||||
});
|
});
|
||||||
|
|
||||||
while (my $job = $rs->next) {
|
while (my $job = $rs->next) {
|
||||||
@@ -216,7 +216,7 @@ sub jq_lock {
|
|||||||
->search({ job => $job->id, status => 'queued' }, { for => 'update' })
|
->search({ job => $job->id, status => 'queued' }, { for => 'update' })
|
||||||
->update({
|
->update({
|
||||||
status => ('queued-'. setting('workers')->{'BACKEND'}),
|
status => ('queued-'. setting('workers')->{'BACKEND'}),
|
||||||
started => \"now()",
|
started => \"LOCALTIMESTAMP",
|
||||||
});
|
});
|
||||||
|
|
||||||
$happy = true if $updated > 0;
|
$happy = true if $updated > 0;
|
||||||
@@ -319,7 +319,7 @@ sub jq_userlog {
|
|||||||
return schema(vars->{'tenant'})->resultset('Admin')->search({
|
return schema(vars->{'tenant'})->resultset('Admin')->search({
|
||||||
username => $user,
|
username => $user,
|
||||||
log => { '-not_like' => 'duplicate of %' },
|
log => { '-not_like' => 'duplicate of %' },
|
||||||
finished => { '>' => \"(now() - interval '5 seconds')" },
|
finished => { '>' => \"(LOCALTIMESTAMP - interval '5 seconds')" },
|
||||||
})->with_times->all;
|
})->with_times->all;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -150,13 +150,13 @@ and the current NetBIOS user C<nbuser>.
|
|||||||
Adds new entry or time stamps matching one.
|
Adds new entry or time stamps matching one.
|
||||||
|
|
||||||
Optionally a literal string can be passed in the second argument for the
|
Optionally a literal string can be passed in the second argument for the
|
||||||
C<time_last> timestamp, otherwise the current timestamp (C<now()>) is used.
|
C<time_last> timestamp, otherwise the current timestamp (C<LOCALTIMESTAMP>) is used.
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
sub store_nbt {
|
sub store_nbt {
|
||||||
my ( $hash_ref, $now ) = @_;
|
my ( $hash_ref, $now ) = @_;
|
||||||
$now ||= 'now()';
|
$now ||= 'LOCALTIMESTAMP';
|
||||||
|
|
||||||
schema(vars->{'tenant'})->resultset('NodeNbt')->update_or_create(
|
schema(vars->{'tenant'})->resultset('NodeNbt')->update_or_create(
|
||||||
{ mac => $hash_ref->{'mac'},
|
{ mac => $hash_ref->{'mac'},
|
||||||
|
|||||||
@@ -160,13 +160,13 @@ The C<dns> entry is optional. The update will mark old entries for this IP as
|
|||||||
no longer C<active>.
|
no longer C<active>.
|
||||||
|
|
||||||
Optionally a literal string can be passed in the second argument for the
|
Optionally a literal string can be passed in the second argument for the
|
||||||
C<time_last> timestamp, otherwise the current timestamp (C<now()>) is used.
|
C<time_last> timestamp, otherwise the current timestamp (C<LOCALTIMESTAMP>) is used.
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
sub store_arp {
|
sub store_arp {
|
||||||
my ($hash_ref, $now) = @_;
|
my ($hash_ref, $now) = @_;
|
||||||
$now ||= 'now()';
|
$now ||= 'LOCALTIMESTAMP';
|
||||||
my $ip = $hash_ref->{'ip'};
|
my $ip = $hash_ref->{'ip'};
|
||||||
my $mac = NetAddr::MAC->new(mac => ($hash_ref->{'node'} || $hash_ref->{'mac'} || ''));
|
my $mac = NetAddr::MAC->new(mac => ($hash_ref->{'node'} || $hash_ref->{'mac'} || ''));
|
||||||
my $name = $hash_ref->{'dns'};
|
my $name = $hash_ref->{'dns'};
|
||||||
|
|||||||
@@ -120,7 +120,7 @@ post '/login' => sub {
|
|||||||
event => (sprintf 'Login (%s)', ($api ? 'API' : 'WebUI')),
|
event => (sprintf 'Login (%s)', ($api ? 'API' : 'WebUI')),
|
||||||
details => param('return_url'),
|
details => param('return_url'),
|
||||||
});
|
});
|
||||||
$user->update({ last_on => \'now()' });
|
$user->update({ last_on => \'LOCALTIMESTAMP' });
|
||||||
|
|
||||||
if ($api) {
|
if ($api) {
|
||||||
# from the internals of Dancer::Plugin::Auth::Extensible
|
# from the internals of Dancer::Plugin::Auth::Extensible
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ ajax '/ajax/control/admin/nodemonitor/update' => require_role admin => sub {
|
|||||||
active => (param('active') ? \'true' : \'false'),
|
active => (param('active') ? \'true' : \'false'),
|
||||||
why => param('why'),
|
why => param('why'),
|
||||||
cc => param('cc'),
|
cc => param('cc'),
|
||||||
date => \'now()',
|
date => \'LOCALTIMESTAMP',
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ ajax '/ajax/control/admin/pseudodevice/add' => require_role admin => sub {
|
|||||||
os => 'netdisco',
|
os => 'netdisco',
|
||||||
os_ver => pretty_version($App::Netdisco::VERSION, 3),
|
os_ver => pretty_version($App::Netdisco::VERSION, 3),
|
||||||
layers => param('layers'),
|
layers => param('layers'),
|
||||||
last_discover => \'now()',
|
last_discover => \'LOCALTIMESTAMP',
|
||||||
is_pseudo => \'true',
|
is_pseudo => \'true',
|
||||||
});
|
});
|
||||||
return unless $device;
|
return unless $device;
|
||||||
@@ -101,7 +101,7 @@ ajax '/ajax/control/admin/pseudodevice/update' => require_role admin => sub {
|
|||||||
$device->update({layers => param('layers')});
|
$device->update({layers => param('layers')});
|
||||||
|
|
||||||
# and update last_discover, since device properties changed
|
# and update last_discover, since device properties changed
|
||||||
$device->update({last_discover => \'now()'});
|
$device->update({last_discover => \'LOCALTIMESTAMP'});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ get '/ajax/content/report/ipinventory' => require_login sub {
|
|||||||
'dns',
|
'dns',
|
||||||
\'true AS active',
|
\'true AS active',
|
||||||
\'false AS node',
|
\'false AS node',
|
||||||
\qq/replace( date_trunc( 'minute', age( now(), device.last_discover ) ) ::text, 'mon', 'month') AS age/,
|
\qq/replace( date_trunc( 'minute', age( LOCALTIMESTAMP, device.last_discover ) ) ::text, 'mon', 'month') AS age/,
|
||||||
'device.vendor',
|
'device.vendor',
|
||||||
\'null AS nbname',
|
\'null AS nbname',
|
||||||
|
|
||||||
@@ -91,7 +91,7 @@ get '/ajax/content/report/ipinventory' => require_login sub {
|
|||||||
{ join => ['oui', 'netbios'],
|
{ join => ['oui', 'netbios'],
|
||||||
columns => [qw( ip mac time_first time_last dns active)],
|
columns => [qw( ip mac time_first time_last dns active)],
|
||||||
'+select' => [ \'true AS node',
|
'+select' => [ \'true AS node',
|
||||||
\qq/replace( date_trunc( 'minute', age( now(), me.time_last ) ) ::text, 'mon', 'month') AS age/,
|
\qq/replace( date_trunc( 'minute', age( LOCALTIMESTAMP, me.time_last ) ) ::text, 'mon', 'month') AS age/,
|
||||||
'oui.company',
|
'oui.company',
|
||||||
'netbios.nbname',
|
'netbios.nbname',
|
||||||
],
|
],
|
||||||
@@ -107,7 +107,7 @@ get '/ajax/content/report/ipinventory' => require_login sub {
|
|||||||
\'null AS dns',
|
\'null AS dns',
|
||||||
'active',
|
'active',
|
||||||
\'true AS node',
|
\'true AS node',
|
||||||
\qq/replace( date_trunc( 'minute', age( now(), time_last ) ) ::text, 'mon', 'month') AS age/,
|
\qq/replace( date_trunc( 'minute', age( LOCALTIMESTAMP, time_last ) ) ::text, 'mon', 'month') AS age/,
|
||||||
'oui.company',
|
'oui.company',
|
||||||
'nbname'
|
'nbname'
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ register_worker({ phase => 'main' }, sub {
|
|||||||
os => 'netdisco',
|
os => 'netdisco',
|
||||||
os_ver => pretty_version($App::Netdisco::VERSION, 3),
|
os_ver => pretty_version($App::Netdisco::VERSION, 3),
|
||||||
layers => '00000100',
|
layers => '00000100',
|
||||||
last_discover => \'now()',
|
last_discover => \'LOCALTIMESTAMP',
|
||||||
is_pseudo => \'true',
|
is_pseudo => \'true',
|
||||||
});
|
});
|
||||||
return unless $device;
|
return unless $device;
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ register_worker({ phase => 'early',
|
|||||||
my ($job, $workerconf) = @_;
|
my ($job, $workerconf) = @_;
|
||||||
my $device = $job->device;
|
my $device = $job->device;
|
||||||
|
|
||||||
# would be possible just to use now() on updated records, but by using this
|
# would be possible just to use LOCALTIMESTAMP on updated records, but by using this
|
||||||
# same value for them all, we can if we want add a job at the end to
|
# 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)
|
# 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)
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ my $clean = sub {
|
|||||||
serial => $device->serial,
|
serial => $device->serial,
|
||||||
model => $device->model,
|
model => $device->model,
|
||||||
fru => \'false',
|
fru => \'false',
|
||||||
last_discover => \'now()',
|
last_discover => \'LOCALTIMESTAMP',
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -95,7 +95,7 @@ register_worker({ phase => 'main', driver => 'snmp' }, sub {
|
|||||||
serial => Encode::decode('UTF-8', $e_serial->{$entry}),
|
serial => Encode::decode('UTF-8', $e_serial->{$entry}),
|
||||||
fru => $e_fru->{$entry},
|
fru => $e_fru->{$entry},
|
||||||
description => Encode::decode('UTF-8', $e_descr->{$entry}),
|
description => Encode::decode('UTF-8', $e_descr->{$entry}),
|
||||||
last_discover => \'now()',
|
last_discover => \'LOCALTIMESTAMP',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ register_worker({ phase => 'early', driver => 'snmp' }, sub {
|
|||||||
$device->set_column( snmp_class => $snmp->class );
|
$device->set_column( snmp_class => $snmp->class );
|
||||||
$device->set_column( snmp_engineid => unpack('H*', ($snmp->snmpEngineID || '')) );
|
$device->set_column( snmp_engineid => unpack('H*', ($snmp->snmpEngineID || '')) );
|
||||||
|
|
||||||
$device->set_column( last_discover => \'now()' );
|
$device->set_column( last_discover => \'LOCALTIMESTAMP' );
|
||||||
|
|
||||||
# protection for failed SNMP gather
|
# protection for failed SNMP gather
|
||||||
if ($device->in_storage and not $device->is_pseudo) {
|
if ($device->in_storage and not $device->is_pseudo) {
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ register_worker({ phase => 'main', driver => 'snmp' }, sub {
|
|||||||
native => $native,
|
native => $native,
|
||||||
egress_tag => 'f',
|
egress_tag => 'f',
|
||||||
vlantype => $type,
|
vlantype => $type,
|
||||||
last_discover => \'now()',
|
last_discover => \'LOCALTIMESTAMP',
|
||||||
};
|
};
|
||||||
|
|
||||||
++$this_port_vlans{$vlan};
|
++$this_port_vlans{$vlan};
|
||||||
@@ -78,7 +78,7 @@ register_worker({ phase => 'main', driver => 'snmp' }, sub {
|
|||||||
native => $native,
|
native => $native,
|
||||||
egress_tag => ($native eq 't' ? 'f' : 't'),
|
egress_tag => ($native eq 't' ? 'f' : 't'),
|
||||||
vlantype => $type,
|
vlantype => $type,
|
||||||
last_discover => \'now()',
|
last_discover => \'LOCALTIMESTAMP',
|
||||||
};
|
};
|
||||||
|
|
||||||
++$this_port_vlans{$vlan};
|
++$this_port_vlans{$vlan};
|
||||||
@@ -109,7 +109,7 @@ register_worker({ phase => 'main', driver => 'snmp' }, sub {
|
|||||||
push @devicevlans, {
|
push @devicevlans, {
|
||||||
vlan => $vlan,
|
vlan => $vlan,
|
||||||
description => $v_name->{$entry},
|
description => $v_name->{$entry},
|
||||||
last_discover => \'now()',
|
last_discover => \'LOCALTIMESTAMP',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,7 +120,7 @@ register_worker({ phase => 'main', driver => 'snmp' }, sub {
|
|||||||
push @devicevlans, {
|
push @devicevlans, {
|
||||||
vlan => $vlan,
|
vlan => $vlan,
|
||||||
description => (sprintf "VLAN %d", $vlan),
|
description => (sprintf "VLAN %d", $vlan),
|
||||||
last_discover => \'now()',
|
last_discover => \'LOCALTIMESTAMP',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ register_worker({ phase => 'main' }, sub {
|
|||||||
schema('netdisco')->txn_do(sub {
|
schema('netdisco')->txn_do(sub {
|
||||||
schema('netdisco')->resultset('Device')->search({
|
schema('netdisco')->resultset('Device')->search({
|
||||||
-or => [ 'vendor' => undef, 'vendor' => { '!=' => 'netdisco' }],
|
-or => [ 'vendor' => undef, 'vendor' => { '!=' => 'netdisco' }],
|
||||||
last_discover => \[q/< (now() - ?::interval)/,
|
last_discover => \[q/< (LOCALTIMESTAMP - ?::interval)/,
|
||||||
(setting('expire_devices') * 86400)],
|
(setting('expire_devices') * 86400)],
|
||||||
})->delete();
|
})->delete();
|
||||||
});
|
});
|
||||||
@@ -27,12 +27,12 @@ register_worker({ phase => 'main' }, sub {
|
|||||||
? setting('expire_nodeip_freshness') : setting('expire_nodes'));
|
? setting('expire_nodeip_freshness') : setting('expire_nodes'));
|
||||||
if ($freshness) {
|
if ($freshness) {
|
||||||
schema('netdisco')->resultset('NodeIp')->search({
|
schema('netdisco')->resultset('NodeIp')->search({
|
||||||
time_last => \[q/< (now() - ?::interval)/, ($freshness * 86400)],
|
time_last => \[q/< (LOCALTIMESTAMP - ?::interval)/, ($freshness * 86400)],
|
||||||
})->delete();
|
})->delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
schema('netdisco')->resultset('Node')->search({
|
schema('netdisco')->resultset('Node')->search({
|
||||||
time_last => \[q/< (now() - ?::interval)/,
|
time_last => \[q/< (LOCALTIMESTAMP - ?::interval)/,
|
||||||
(setting('expire_nodes') * 86400)],
|
(setting('expire_nodes') * 86400)],
|
||||||
})->delete();
|
})->delete();
|
||||||
});
|
});
|
||||||
@@ -44,13 +44,13 @@ register_worker({ phase => 'main' }, sub {
|
|||||||
? setting('expire_nodeip_freshness') : setting('expire_nodes_archive'));
|
? setting('expire_nodeip_freshness') : setting('expire_nodes_archive'));
|
||||||
if ($freshness) {
|
if ($freshness) {
|
||||||
schema('netdisco')->resultset('NodeIp')->search({
|
schema('netdisco')->resultset('NodeIp')->search({
|
||||||
time_last => \[q/< (now() - ?::interval)/, ($freshness * 86400)],
|
time_last => \[q/< (LOCALTIMESTAMP - ?::interval)/, ($freshness * 86400)],
|
||||||
})->delete();
|
})->delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
schema('netdisco')->resultset('Node')->search({
|
schema('netdisco')->resultset('Node')->search({
|
||||||
-not_bool => 'active',
|
-not_bool => 'active',
|
||||||
time_last => \[q/< (now() - ?::interval)/,
|
time_last => \[q/< (LOCALTIMESTAMP - ?::interval)/,
|
||||||
(setting('expire_nodes_archive') * 86400)],
|
(setting('expire_nodes_archive') * 86400)],
|
||||||
})->delete();
|
})->delete();
|
||||||
});
|
});
|
||||||
@@ -67,7 +67,7 @@ register_worker({ phase => 'main' }, sub {
|
|||||||
if (setting('expire_jobs') and setting('expire_jobs') > 0) {
|
if (setting('expire_jobs') and setting('expire_jobs') > 0) {
|
||||||
schema('netdisco')->txn_do_locked('admin', 'EXCLUSIVE', sub {
|
schema('netdisco')->txn_do_locked('admin', 'EXCLUSIVE', sub {
|
||||||
schema('netdisco')->resultset('Admin')->search({
|
schema('netdisco')->resultset('Admin')->search({
|
||||||
entered => \[q/< (now() - ?::interval)/,
|
entered => \[q/< (LOCALTIMESTAMP - ?::interval)/,
|
||||||
(setting('expire_jobs') * 86400)],
|
(setting('expire_jobs') * 86400)],
|
||||||
})->delete();
|
})->delete();
|
||||||
});
|
});
|
||||||
@@ -76,7 +76,7 @@ register_worker({ phase => 'main' }, sub {
|
|||||||
if (setting('expire_userlog') and setting('expire_userlog') > 0) {
|
if (setting('expire_userlog') and setting('expire_userlog') > 0) {
|
||||||
schema('netdisco')->txn_do_locked('admin', 'EXCLUSIVE', sub {
|
schema('netdisco')->txn_do_locked('admin', 'EXCLUSIVE', sub {
|
||||||
schema('netdisco')->resultset('UserLog')->search({
|
schema('netdisco')->resultset('UserLog')->search({
|
||||||
creation => \[q/< (now() - ?::interval)/,
|
creation => \[q/< (LOCALTIMESTAMP - ?::interval)/,
|
||||||
(setting('expire_userlog') * 86400)],
|
(setting('expire_userlog') * 86400)],
|
||||||
})->delete();
|
})->delete();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ register_worker({ phase => 'early',
|
|||||||
my ($job, $workerconf) = @_;
|
my ($job, $workerconf) = @_;
|
||||||
my $device = $job->device;
|
my $device = $job->device;
|
||||||
|
|
||||||
# would be possible just to use now() on updated records, but by using this
|
# would be possible just to use LOCALTIMESTAMP on updated records, but by using this
|
||||||
# same value for them all, we can if we want add a job at the end to
|
# 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)
|
# 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)
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ register_worker({ phase => 'main' }, sub {
|
|||||||
|
|
||||||
my $devices = schema('netdisco')->resultset('Device')->search(undef, {
|
my $devices = schema('netdisco')->resultset('Device')->search(undef, {
|
||||||
'+columns' => { old =>
|
'+columns' => { old =>
|
||||||
\['age(now(), last_discover) > ?::interval', $down_age] },
|
\['age(LOCALTIMESTAMP, last_discover) > ?::interval', $down_age] },
|
||||||
});
|
});
|
||||||
|
|
||||||
$config->{groups} ||= { default => 'any' };
|
$config->{groups} ||= { default => 'any' };
|
||||||
|
|||||||
Reference in New Issue
Block a user