diff --git a/Netdisco/Changes b/Netdisco/Changes index 7cacf678..0b115c39 100644 --- a/Netdisco/Changes +++ b/Netdisco/Changes @@ -1,3 +1,15 @@ +2.012005 - 2013-08-16 + + [ENHANCEMENTS] + + * Improved handling of automatic macsuck/arpnip after initial discover + + [BUG FIXES] + + * Fix no_auth to work with new Auth::Extensible plugin + * Remove done job from local queue regardless of exit status + * Set last arpnip timestamp + 2.012002 - 2013-08-07 [BUG FIXES] diff --git a/Netdisco/META.yml b/Netdisco/META.yml index 4cbaeb99..14e31e63 100644 --- a/Netdisco/META.yml +++ b/Netdisco/META.yml @@ -45,7 +45,7 @@ requires: Plack: 1.0023 Plack::Middleware::Expires: 0.03 Role::Tiny: 1.002005 - SNMP::Info: 3.01 + SNMP::Info: 3.05 SQL::Translator: 0.11016 Socket6: 0.23 Starman: 0.3008 @@ -61,4 +61,4 @@ resources: homepage: http://netdisco.org/ license: http://opensource.org/licenses/bsd-license.php repository: git://git.code.sf.net/p/netdisco/netdisco-ng -version: 2.012002 +version: 2.012005 diff --git a/Netdisco/Makefile.PL b/Netdisco/Makefile.PL index 74b34871..e38097da 100644 --- a/Netdisco/Makefile.PL +++ b/Netdisco/Makefile.PL @@ -32,7 +32,7 @@ requires 'Plack::Middleware::Expires' => 0.03; requires 'Role::Tiny' => 1.002005; requires 'Socket6' => 0.23; requires 'Starman' => 0.3008; -requires 'SNMP::Info' => 3.01; +requires 'SNMP::Info' => 3.05; requires 'SQL::Translator' => 0.11016; requires 'Template' => 2.24; requires 'YAML' => 0.84; diff --git a/Netdisco/lib/App/Netdisco.pm b/Netdisco/lib/App/Netdisco.pm index 765ed760..36e4f882 100644 --- a/Netdisco/lib/App/Netdisco.pm +++ b/Netdisco/lib/App/Netdisco.pm @@ -7,7 +7,7 @@ use 5.010_000; use File::ShareDir 'dist_dir'; use Path::Class; -our $VERSION = '2.012002'; +our $VERSION = '2.012005'; BEGIN { if (not ($ENV{DANCER_APPDIR} || '') diff --git a/Netdisco/lib/App/Netdisco/Core/Arpnip.pm b/Netdisco/lib/App/Netdisco/Core/Arpnip.pm index d4015d1b..f441f05e 100644 --- a/Netdisco/lib/App/Netdisco/Core/Arpnip.pm +++ b/Netdisco/lib/App/Netdisco/Core/Arpnip.pm @@ -72,6 +72,8 @@ sub do_arpnip { _store_subnet($_, $now) for @subnets; debug sprintf ' [%s] arpnip - processed %s Subnet entries', $device->ip, scalar @subnets; + + $device->update({last_arpnip => \$now}); } # get an arp table (v4 or v6) diff --git a/Netdisco/lib/App/Netdisco/Daemon/Queue.pm b/Netdisco/lib/App/Netdisco/Daemon/Queue.pm index ec072a6e..f89e14fb 100644 --- a/Netdisco/lib/App/Netdisco/Daemon/Queue.pm +++ b/Netdisco/lib/App/Netdisco/Daemon/Queue.pm @@ -5,7 +5,7 @@ use Dancer::Plugin::DBIC 'schema'; use base 'Exporter'; our @EXPORT = (); -our @EXPORT_OK = qw/ add_jobs capacity_for take_jobs reset_jobs /; +our @EXPORT_OK = qw/ add_jobs capacity_for take_jobs reset_jobs scrub_jobs /; our %EXPORT_TAGS = ( all => \@EXPORT_OK ); schema('daemon')->deploy; @@ -69,10 +69,17 @@ sub take_jobs { sub reset_jobs { my ($wid) = @_; - debug "resetting jobs owned by worked $wid to be available"; + debug "resetting jobs owned by worker $wid to be available"; return unless $wid > 1; $queue->search({wid => $wid}) ->update({wid => 0}); } +sub scrub_jobs { + my ($wid) = @_; + debug "deleting jobs owned by worker $wid"; + return unless $wid > 1; + $queue->search({wid => $wid})->delete; +} + 1; diff --git a/Netdisco/lib/App/Netdisco/Daemon/Worker/Common.pm b/Netdisco/lib/App/Netdisco/Daemon/Worker/Common.pm index 674a7232..64292713 100644 --- a/Netdisco/lib/App/Netdisco/Daemon/Worker/Common.pm +++ b/Netdisco/lib/App/Netdisco/Daemon/Worker/Common.pm @@ -79,6 +79,9 @@ sub close_job { finished => $now, }); } + + # remove job from local queue + $self->do('scrub_jobs', $self->wid); } catch { $self->sendto('stderr', "error closing job: $_\n") }; } diff --git a/Netdisco/lib/App/Netdisco/Daemon/Worker/Poller/Device.pm b/Netdisco/lib/App/Netdisco/Daemon/Worker/Poller/Device.pm index d0e031b2..45f04d7e 100644 --- a/Netdisco/lib/App/Netdisco/Daemon/Worker/Poller/Device.pm +++ b/Netdisco/lib/App/Netdisco/Daemon/Worker/Poller/Device.pm @@ -36,6 +36,8 @@ sub discoverall { device => $_, action => 'discover', status => 'queued', + username => $job->username, + userip => $job->userip, }} ($devices->all) ]); }); @@ -43,12 +45,13 @@ sub discoverall { return job_done("Queued discover job for all devices"); } -# queue a discover job for one device, and its *new* neighbors +# run a discover job for one device, and its *new* neighbors sub discover { my ($self, $job) = @_; my $host = NetAddr::IP::Lite->new($job->device); my $device = get_device($host->addr); + my $jobqueue = schema('netdisco')->resultset('Admin'); if ($device->ip eq '0.0.0.0') { return job_error("discover failed: no device param (need -d ?)"); @@ -72,6 +75,33 @@ sub discover { store_modules($device, $snmp); discover_new_neighbors($device, $snmp); + # if requested, and the device has not yet been arpniped/macsucked, queue now + if ($device->in_storage and $job->subaction and $job->subaction eq 'with-nodes') { + if (!defined $device->last_macsuck) { + schema('netdisco')->txn_do(sub { + $jobqueue->create({ + device => $device->ip, + action => 'macsuck', + status => 'queued', + username => $job->username, + userip => $job->userip, + }); + }); + } + + if (!defined $device->last_arpnip) { + schema('netdisco')->txn_do(sub { + $jobqueue->create({ + device => $device->ip, + action => 'arpnip', + status => 'queued', + username => $job->username, + userip => $job->userip, + }); + }); + } + } + return job_done("Ended discover for ". $host->addr); } diff --git a/Netdisco/lib/App/Netdisco/Manual/Deployment.pod b/Netdisco/lib/App/Netdisco/Manual/Deployment.pod index 0b14c7cc..8bd49845 100644 --- a/Netdisco/lib/App/Netdisco/Manual/Deployment.pod +++ b/Netdisco/lib/App/Netdisco/Manual/Deployment.pod @@ -55,7 +55,7 @@ After enabling the C, C and C modules in Apache, a suitable configuration would be: ProxyPreserveHost On - ProxyPass / http://localhost:5000/ + ProxyPass / http://localhost:5000/ retry=0 timeout=5 ProxyPassReverse / http://localhost:5000/ ProxyRequests Off @@ -68,7 +68,7 @@ To combine this with Non-root Hosting as above, simply change the paths referenced in the configuration, and set C in your C as discussed above. Note there is no trailing slash in the Apache config: - ProxyPass /netdisco2 http://localhost:5000/netdisco2 + ProxyPass /netdisco2 http://localhost:5000/netdisco2 retry=0 timeout=5 ProxyPassReverse /netdisco2 http://localhost:5000/netdisco2 To delegate user authentication to Apache, use the C or diff --git a/Netdisco/lib/App/Netdisco/Web/AdminTask.pm b/Netdisco/lib/App/Netdisco/Web/AdminTask.pm index 1e0dfa39..332e3e9f 100644 --- a/Netdisco/lib/App/Netdisco/Web/AdminTask.pm +++ b/Netdisco/lib/App/Netdisco/Web/AdminTask.pm @@ -8,7 +8,7 @@ use Dancer::Plugin::Auth::Extensible; use Try::Tiny; sub add_job { - my ($jobtype, $device) = @_; + my ($jobtype, $device, $subaction) = @_; if ($device) { $device = NetAddr::IP::Lite->new($device); @@ -16,32 +16,16 @@ sub add_job { if ! $device or $device->addr eq '0.0.0.0'; } + # job might already be in the queue, so this could die try { - # jobs might already be in the queue, so this could die schema('netdisco')->resultset('Admin')->create({ ($device ? (device => $device->addr) : ()), action => $jobtype, + ($subaction ? (subaction => $subaction) : ()), status => 'queued', username => session('logged_in_user'), userip => request->remote_address, }); - - if (param('extra') and param('extra') eq 'with-walk') { - schema('netdisco')->resultset('Admin')->create({ - action => 'macwalk', - subaction => 'after-discoverall', - status => 'queued', - username => session('logged_in_user'), - userip => request->remote_address, - }); - schema('netdisco')->resultset('Admin')->create({ - action => 'arpwalk', - subaction => 'after-discoverall', - status => 'queued', - username => session('logged_in_user'), - userip => request->remote_address, - }); - } }; } @@ -63,14 +47,14 @@ foreach my $jobtype (keys %jobs_all, keys %jobs) { send_error('Missing device', 400) if exists $jobs{$jobtype} and not param('device'); - add_job($jobtype, param('device')); + add_job($jobtype, param('device'), param('extra')); }; post "/admin/$jobtype" => require_role admin => sub { send_error('Missing device', 400) if exists $jobs{$jobtype} and not param('device'); - add_job($jobtype, param('device')); + add_job($jobtype, param('device'), param('extra')); redirect uri_for('/admin/jobqueue')->as_string; }; } diff --git a/Netdisco/lib/App/Netdisco/Web/AuthN.pm b/Netdisco/lib/App/Netdisco/Web/AuthN.pm index 6805904e..4751017f 100644 --- a/Netdisco/lib/App/Netdisco/Web/AuthN.pm +++ b/Netdisco/lib/App/Netdisco/Web/AuthN.pm @@ -10,12 +10,15 @@ hook 'before' => sub { if (! session('logged_in_user') && request->path ne uri_for('/login')->path) { if (setting('trust_x_remote_user') and scalar request->header('X-REMOTE_USER')) { session(logged_in_user => scalar request->header('X-REMOTE_USER')); + session(logged_in_user_realm => 'users'); } elsif (setting('trust_remote_user') and $ENV{REMOTE_USER}) { session(logged_in_user => $ENV{REMOTE_USER}); + session(logged_in_user_realm => 'users'); } elsif (setting('no_auth')) { session(logged_in_user => 'guest'); + session(logged_in_user_realm => 'users'); } else { # user has no AuthN - force to handler for '/' diff --git a/Netdisco/share/views/index.tt b/Netdisco/share/views/index.tt index 0f663c3c..5e3c7a0a 100644 --- a/Netdisco/share/views/index.tt +++ b/Netdisco/share/views/index.tt @@ -45,7 +45,7 @@