Support for expire_devices, expire_nodes, and expire_nodes_archive

This commit is contained in:
Oliver Gorwits
2013-12-29 19:29:59 +00:00
parent cfb04e98d1
commit 183bf81cc6
11 changed files with 114 additions and 23 deletions

View File

@@ -22,7 +22,7 @@ sub capacity_for {
debug "checking local capacity for action $action";
my $action_map = {
Poller => [qw/discoverall discover arpwalk arpnip macwalk macsuck/],
Poller => [qw/discoverall discover arpwalk arpnip macwalk macsuck expiry/],
Interactive => [qw/location contact portcontrol portname vlan power/],
};

View File

@@ -13,7 +13,7 @@ my $fqdn = hostfqdn || 'localhost';
my $role_map = {
(map {$_ => 'Poller'}
qw/discoverall discover arpwalk arpnip macwalk macsuck/),
qw/discoverall discover arpwalk arpnip macwalk macsuck expiry/),
(map {$_ => 'Interactive'}
qw/location contact portcontrol portname vlan power/)
};

View File

@@ -9,7 +9,8 @@ with 'App::Netdisco::Daemon::Worker::Common';
# add dispatch methods for poller tasks
with 'App::Netdisco::Daemon::Worker::Poller::Device',
'App::Netdisco::Daemon::Worker::Poller::Arpnip',
'App::Netdisco::Daemon::Worker::Poller::Macsuck';
'App::Netdisco::Daemon::Worker::Poller::Macsuck',
'App::Netdisco::Daemon::Worker::Poller::Expiry';
sub worker_type { 'pol' }
sub worker_name { 'Poller' }

View File

@@ -0,0 +1,46 @@
package App::Netdisco::Daemon::Worker::Poller::Expiry;
use Dancer qw/:moose :syntax :script/;
use Dancer::Plugin::DBIC 'schema';
use App::Netdisco::Daemon::Util ':all';
use Role::Tiny;
use namespace::clean;
# expire devices and nodes according to config
sub expiry {
my ($self, $job) = @_;
if (setting('expire_devices') and setting('expire_devices') > 0) {
schema('netdisco')->txn_do(sub {
schema('netdisco')->resultset('Device')->search({
last_discover => \[q/< (now() - ?::interval)/,
(setting('expire_devices') * 86400)],
})->delete();
});
}
if (setting('expire_nodes') and setting('expire_nodes') > 0) {
schema('netdisco')->txn_do(sub {
schema('netdisco')->resultset('Node')->search({
time_last => \[q/< (now() - ?::interval)/,
(setting('expire_nodes') * 86400)],
})->delete();
});
}
if (setting('expire_nodes_archive') and setting('expire_nodes_archive') > 0) {
schema('netdisco')->txn_do(sub {
schema('netdisco')->resultset('Node')->search({
-not_bool => 'active',
time_last => \[q/< (now() - ?::interval)/,
(setting('expire_nodes_archive') * 86400)],
})->delete();
});
}
return job_done("Checked expiry for all Devices and Nodes");
}
1;

View File

@@ -14,6 +14,7 @@ my $jobactions = {
discoverall
arpwalk
macwalk
expiry
/
# saveconfigs
# nbtwalk