simplify discover options to only discoverall and discover
This commit is contained in:
		| @@ -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', | ||||
|   | ||||
| @@ -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/], | ||||
|   }; | ||||
|  | ||||
|   | ||||
| @@ -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/) | ||||
| }; | ||||
|   | ||||
| @@ -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; | ||||
|   | ||||
| @@ -11,8 +11,7 @@ use namespace::clean; | ||||
|  | ||||
| my $jobactions = { | ||||
|   map {$_ => undef} qw/ | ||||
|       refresh | ||||
|       discovernew | ||||
|       discoverall | ||||
|   / | ||||
| #    saveconfigs | ||||
| #    macwalk | ||||
|   | ||||
| @@ -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 | ||||
|   | ||||
		Reference in New Issue
	
	Block a user