release 2.012005

Squashed commit of the following:

commit a031e3f388af144cb6d729e4b16b174a7caf6de9
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Fri Aug 16 17:50:55 2013 +0100

    new version - 2.012005

commit a0215a83fb2cd9f3040cfd04e239a1a40367e056
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Fri Aug 16 17:47:28 2013 +0100

    set last arpnip timestamp

commit 824d311a2503cc91a117d4cc5949b0aca0cabdc9
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Fri Aug 16 17:28:14 2013 +0100

    test release - 2.012003_001

commit d06316eb1ae6a035a2fefd1edd06bfa6ffe38fa8
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Fri Aug 16 17:26:44 2013 +0100

    Improved handling of automatic macsuck/arpnip after initial discover

commit d7c1e7948f22487c0564a884ce94d109a2cdc13c
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Fri Aug 16 13:21:51 2013 +0100

    add rev. proxy timeout to suggested config

commit 040065a50fec4669740ae48ff18352ef7ff3fde1
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Fri Aug 16 13:14:15 2013 +0100

    remove done job from local queue regardless of exit status

commit d0f1d105459c047cc7156d1b4ef897ad27f965bb
Author: Oliver Gorwits <oliver@cpan.org>
Date:   Fri Aug 16 13:12:45 2013 +0100

    fix no_auth to work with new Auth::Extensible plugin
This commit is contained in:
Oliver Gorwits
2013-08-16 17:51:21 +01:00
parent 5b06162d7d
commit 73d2fffc35
12 changed files with 72 additions and 31 deletions

View File

@@ -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 2.012002 - 2013-08-07
[BUG FIXES] [BUG FIXES]

View File

@@ -45,7 +45,7 @@ requires:
Plack: 1.0023 Plack: 1.0023
Plack::Middleware::Expires: 0.03 Plack::Middleware::Expires: 0.03
Role::Tiny: 1.002005 Role::Tiny: 1.002005
SNMP::Info: 3.01 SNMP::Info: 3.05
SQL::Translator: 0.11016 SQL::Translator: 0.11016
Socket6: 0.23 Socket6: 0.23
Starman: 0.3008 Starman: 0.3008
@@ -61,4 +61,4 @@ resources:
homepage: http://netdisco.org/ homepage: http://netdisco.org/
license: http://opensource.org/licenses/bsd-license.php license: http://opensource.org/licenses/bsd-license.php
repository: git://git.code.sf.net/p/netdisco/netdisco-ng repository: git://git.code.sf.net/p/netdisco/netdisco-ng
version: 2.012002 version: 2.012005

View File

@@ -32,7 +32,7 @@ requires 'Plack::Middleware::Expires' => 0.03;
requires 'Role::Tiny' => 1.002005; requires 'Role::Tiny' => 1.002005;
requires 'Socket6' => 0.23; requires 'Socket6' => 0.23;
requires 'Starman' => 0.3008; requires 'Starman' => 0.3008;
requires 'SNMP::Info' => 3.01; requires 'SNMP::Info' => 3.05;
requires 'SQL::Translator' => 0.11016; requires 'SQL::Translator' => 0.11016;
requires 'Template' => 2.24; requires 'Template' => 2.24;
requires 'YAML' => 0.84; requires 'YAML' => 0.84;

View File

@@ -7,7 +7,7 @@ use 5.010_000;
use File::ShareDir 'dist_dir'; use File::ShareDir 'dist_dir';
use Path::Class; use Path::Class;
our $VERSION = '2.012002'; our $VERSION = '2.012005';
BEGIN { BEGIN {
if (not ($ENV{DANCER_APPDIR} || '') if (not ($ENV{DANCER_APPDIR} || '')

View File

@@ -72,6 +72,8 @@ sub do_arpnip {
_store_subnet($_, $now) for @subnets; _store_subnet($_, $now) for @subnets;
debug sprintf ' [%s] arpnip - processed %s Subnet entries', debug sprintf ' [%s] arpnip - processed %s Subnet entries',
$device->ip, scalar @subnets; $device->ip, scalar @subnets;
$device->update({last_arpnip => \$now});
} }
# get an arp table (v4 or v6) # get an arp table (v4 or v6)

View File

@@ -5,7 +5,7 @@ use Dancer::Plugin::DBIC 'schema';
use base 'Exporter'; use base 'Exporter';
our @EXPORT = (); 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 ); our %EXPORT_TAGS = ( all => \@EXPORT_OK );
schema('daemon')->deploy; schema('daemon')->deploy;
@@ -69,10 +69,17 @@ sub take_jobs {
sub reset_jobs { sub reset_jobs {
my ($wid) = @_; 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; return unless $wid > 1;
$queue->search({wid => $wid}) $queue->search({wid => $wid})
->update({wid => 0}); ->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; 1;

View File

@@ -79,6 +79,9 @@ sub close_job {
finished => $now, finished => $now,
}); });
} }
# remove job from local queue
$self->do('scrub_jobs', $self->wid);
} }
catch { $self->sendto('stderr', "error closing job: $_\n") }; catch { $self->sendto('stderr', "error closing job: $_\n") };
} }

View File

@@ -36,6 +36,8 @@ sub discoverall {
device => $_, device => $_,
action => 'discover', action => 'discover',
status => 'queued', status => 'queued',
username => $job->username,
userip => $job->userip,
}} ($devices->all) }} ($devices->all)
]); ]);
}); });
@@ -43,12 +45,13 @@ sub discoverall {
return job_done("Queued discover job for all devices"); 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 { sub discover {
my ($self, $job) = @_; my ($self, $job) = @_;
my $host = NetAddr::IP::Lite->new($job->device); my $host = NetAddr::IP::Lite->new($job->device);
my $device = get_device($host->addr); my $device = get_device($host->addr);
my $jobqueue = schema('netdisco')->resultset('Admin');
if ($device->ip eq '0.0.0.0') { if ($device->ip eq '0.0.0.0') {
return job_error("discover failed: no device param (need -d ?)"); return job_error("discover failed: no device param (need -d ?)");
@@ -72,6 +75,33 @@ sub discover {
store_modules($device, $snmp); store_modules($device, $snmp);
discover_new_neighbors($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); return job_done("Ended discover for ". $host->addr);
} }

View File

@@ -55,7 +55,7 @@ After enabling the C<headers>, C<proxy> and C<proxy_http> modules in Apache, a
suitable configuration would be: suitable configuration would be:
ProxyPreserveHost On ProxyPreserveHost On
ProxyPass / http://localhost:5000/ ProxyPass / http://localhost:5000/ retry=0 timeout=5
ProxyPassReverse / http://localhost:5000/ ProxyPassReverse / http://localhost:5000/
ProxyRequests Off 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<path> in your C<deployment.yml> as referenced in the configuration, and set C<path> in your C<deployment.yml> as
discussed above. Note there is no trailing slash in the Apache config: 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 ProxyPassReverse /netdisco2 http://localhost:5000/netdisco2
To delegate user authentication to Apache, use the C<trust_remote_user> or To delegate user authentication to Apache, use the C<trust_remote_user> or

View File

@@ -8,7 +8,7 @@ use Dancer::Plugin::Auth::Extensible;
use Try::Tiny; use Try::Tiny;
sub add_job { sub add_job {
my ($jobtype, $device) = @_; my ($jobtype, $device, $subaction) = @_;
if ($device) { if ($device) {
$device = NetAddr::IP::Lite->new($device); $device = NetAddr::IP::Lite->new($device);
@@ -16,32 +16,16 @@ sub add_job {
if ! $device or $device->addr eq '0.0.0.0'; if ! $device or $device->addr eq '0.0.0.0';
} }
# job might already be in the queue, so this could die
try { try {
# jobs might already be in the queue, so this could die
schema('netdisco')->resultset('Admin')->create({ schema('netdisco')->resultset('Admin')->create({
($device ? (device => $device->addr) : ()), ($device ? (device => $device->addr) : ()),
action => $jobtype, action => $jobtype,
($subaction ? (subaction => $subaction) : ()),
status => 'queued', status => 'queued',
username => session('logged_in_user'), username => session('logged_in_user'),
userip => request->remote_address, 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) send_error('Missing device', 400)
if exists $jobs{$jobtype} and not param('device'); 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 { post "/admin/$jobtype" => require_role admin => sub {
send_error('Missing device', 400) send_error('Missing device', 400)
if exists $jobs{$jobtype} and not param('device'); 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; redirect uri_for('/admin/jobqueue')->as_string;
}; };
} }

View File

@@ -10,12 +10,15 @@ hook 'before' => sub {
if (! session('logged_in_user') && request->path ne uri_for('/login')->path) { 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')) { 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 => scalar request->header('X-REMOTE_USER'));
session(logged_in_user_realm => 'users');
} }
elsif (setting('trust_remote_user') and $ENV{REMOTE_USER}) { elsif (setting('trust_remote_user') and $ENV{REMOTE_USER}) {
session(logged_in_user => $ENV{REMOTE_USER}); session(logged_in_user => $ENV{REMOTE_USER});
session(logged_in_user_realm => 'users');
} }
elsif (setting('no_auth')) { elsif (setting('no_auth')) {
session(logged_in_user => 'guest'); session(logged_in_user => 'guest');
session(logged_in_user_realm => 'users');
} }
else { else {
# user has no AuthN - force to handler for '/' # user has no AuthN - force to handler for '/'

View File

@@ -45,7 +45,7 @@
<form class="nd_login-form" method="post" action="[% uri_for('/admin/discover') %]"> <form class="nd_login-form" method="post" action="[% uri_for('/admin/discover') %]">
<div class="form-horizontal"> <div class="form-horizontal">
<input placeholder="Device hostname or IP" class="span4" name="device" type="text"/> <input placeholder="Device hostname or IP" class="span4" name="device" type="text"/>
<input type="hidden" name="extra" value="with-walk"/> <input type="hidden" name="extra" value="with-nodes"/>
<button type="submit" class="btn btn-info">Discover</button> <button type="submit" class="btn btn-info">Discover</button>
</div> </div>
</form> </form>