From 8bc7d83c985f03970217d9f00185f83a61ae173d Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Thu, 30 May 2013 05:35:41 +0100 Subject: [PATCH] simplify discover options to only discoverall and discover --- Netdisco/lib/App/Netdisco/Core/Discover.pm | 2 +- Netdisco/lib/App/Netdisco/Daemon/Queue.pm | 2 +- .../lib/App/Netdisco/Daemon/Worker/Manager.pm | 2 +- .../Netdisco/Daemon/Worker/Poller/Device.pm | 57 +------------------ .../App/Netdisco/Daemon/Worker/Scheduler.pm | 3 +- .../lib/App/Netdisco/Manual/Configuration.pod | 2 +- 6 files changed, 8 insertions(+), 60 deletions(-) diff --git a/Netdisco/lib/App/Netdisco/Core/Discover.pm b/Netdisco/lib/App/Netdisco/Core/Discover.pm index f977b417..590fd8ad 100644 --- a/Netdisco/lib/App/Netdisco/Core/Discover.pm +++ b/Netdisco/lib/App/Netdisco/Core/Discover.pm @@ -815,8 +815,8 @@ sub discover_new_neighbors { next; } + # could fail if queued job already exists try { - # could fail if queued job already exists schema('netdisco')->resultset('Admin')->create({ device => $ip, action => 'discover', diff --git a/Netdisco/lib/App/Netdisco/Daemon/Queue.pm b/Netdisco/lib/App/Netdisco/Daemon/Queue.pm index deeb74ad..c35fc7bf 100644 --- a/Netdisco/lib/App/Netdisco/Daemon/Queue.pm +++ b/Netdisco/lib/App/Netdisco/Daemon/Queue.pm @@ -33,7 +33,7 @@ sub capacity_for { debug "checking local capacity for action $action"; my $action_map = { - Poller => [qw/refresh discover discovernew discover_neighbors arpnip macsuck/], + Poller => [qw/discoverall discover arpnip macsuck/], Interactive => [qw/location contact portcontrol portname vlan power/], }; diff --git a/Netdisco/lib/App/Netdisco/Daemon/Worker/Manager.pm b/Netdisco/lib/App/Netdisco/Daemon/Worker/Manager.pm index 6dd0a3cb..624a6069 100644 --- a/Netdisco/lib/App/Netdisco/Daemon/Worker/Manager.pm +++ b/Netdisco/lib/App/Netdisco/Daemon/Worker/Manager.pm @@ -14,7 +14,7 @@ my $fqdn = hostfqdn || 'localhost'; my $role_map = { (map {$_ => 'Poller'} - qw/refresh discover discovernew discover_neighbors arpnip macsuck/), + qw/discoverall discover arpnip macsuck/), (map {$_ => 'Interactive'} qw/location contact portcontrol portname vlan power/) }; diff --git a/Netdisco/lib/App/Netdisco/Daemon/Worker/Poller/Device.pm b/Netdisco/lib/App/Netdisco/Daemon/Worker/Poller/Device.pm index dab8a40b..93cf9105 100644 --- a/Netdisco/lib/App/Netdisco/Daemon/Worker/Poller/Device.pm +++ b/Netdisco/lib/App/Netdisco/Daemon/Worker/Poller/Device.pm @@ -14,7 +14,7 @@ use Role::Tiny; use namespace::clean; # queue a discover job for all devices known to Netdisco -sub refresh { +sub discoverall { my ($self, $job) = @_; my $devices = schema('netdisco')->resultset('Device')->get_column('ip'); @@ -43,6 +43,7 @@ sub refresh { return job_done("Queued discover job for all devices"); } +# queue a discover job for one device, and its *new* neighbors sub discover { my ($self, $job) = @_; @@ -65,61 +66,9 @@ sub discover { store_vlans($device, $snmp); store_power($device, $snmp); store_modules($device, $snmp); - store_neighbors($device, $snmp); + discover_new_neighbors($device, $snmp); return job_done("Ended discover for ". $host->addr); } -# run discover_neighbors on all known devices, and run discover on any -# newly found devices. -sub discovernew { - my ($self, $job) = @_; - - my $devices = schema('netdisco')->resultset('Device')->get_column('ip'); - my $jobqueue = schema('netdisco')->resultset('Admin'); - - schema('netdisco')->txn_do(sub { - # clean up user submitted jobs older than 1min, - # assuming skew between schedulers' clocks is not greater than 1min - $jobqueue->search({ - action => 'discover_neighbors', - status => 'queued', - entered => { '<' => \"(now() - interval '1 minute')" }, - })->delete; - - # is scuppered by any user job submitted in last 1min (bad), or - # any similar job from another scheduler (good) - $jobqueue->populate([ - map {{ - device => $_, - action => 'discover_neighbors', - status => 'queued', - }} ($devices->all) - ]); - }); - - return job_done("Queued discover_neighbors job for all devices"); -} - -sub discover_neighbors { - my ($self, $job) = @_; - - my $host = NetAddr::IP::Lite->new($job->device); - my $device = get_device($host->addr); - - if ($device->in_storage - and $device->vendor and $device->vendor eq 'netdisco') { - return job_done("Skipped discover for pseudo-device $host"); - } - - my $snmp = snmp_connect($device); - if (!defined $snmp) { - return job_error("discover_neighbors failed: could not SNMP connect to $host"); - } - - discover_new_neighbors($device, $snmp); - - return job_done("Ended discover_neighbors for". $host->addr); -} - 1; diff --git a/Netdisco/lib/App/Netdisco/Daemon/Worker/Scheduler.pm b/Netdisco/lib/App/Netdisco/Daemon/Worker/Scheduler.pm index f7ad185b..82b72289 100644 --- a/Netdisco/lib/App/Netdisco/Daemon/Worker/Scheduler.pm +++ b/Netdisco/lib/App/Netdisco/Daemon/Worker/Scheduler.pm @@ -11,8 +11,7 @@ use namespace::clean; my $jobactions = { map {$_ => undef} qw/ - refresh - discovernew + discoverall / # saveconfigs # macwalk diff --git a/Netdisco/lib/App/Netdisco/Manual/Configuration.pod b/Netdisco/lib/App/Netdisco/Manual/Configuration.pod index b98b5bb4..76f13309 100644 --- a/Netdisco/lib/App/Netdisco/Manual/Configuration.pod +++ b/Netdisco/lib/App/Netdisco/Manual/Configuration.pod @@ -5,7 +5,7 @@ App::Netdisco::Manual::Configuration - How to Configure Netdisco =head1 INTRODUCTION The configuration files for Netdisco come with all options set to sensible -default values, and just a few that you initially must set yourself. +default values, and just a few that you must initially set yourself. However as you use the system over time, there are many situations where you might want to tune the behaviour of Netdisco, and for that we have a lot of