change noop to info, and some fixes

This commit is contained in:
Oliver Gorwits
2017-11-25 12:29:08 +00:00
parent de594c647f
commit 26b4bdb907
16 changed files with 54 additions and 58 deletions

View File

@@ -49,13 +49,13 @@ sub BUILD {
=head1 METHODS
=head2 summary
=head2 display_name
An attempt to make a meaningful written statement about the job.
=cut
sub summary {
sub display_name {
my $job = shift;
return join ' ',
$job->action,
@@ -87,8 +87,8 @@ sub finalise_status {
next if $status->phase
and $status->phase !~ m/^(?:check|early|main)$/;
next if $status->phase eq 'check'
and $status->level eq Status->done()->level;
# done() from check phase should not be the action's done()
next if $status->phase eq 'check' and $status->is_ok;
if ($status->level >= $max_level) {
$job->status( $status->status );
@@ -110,8 +110,8 @@ sub check_passed {
return true if 0 == scalar @{ $job->_statuslist };
foreach my $status (@{ $job->_statuslist }) {
next unless $status->phase and $status->phase eq 'check';
return true if $status->is_ok;
return true if
(($status->phase eq 'check') and $status->is_ok);
}
return false;
}
@@ -128,7 +128,7 @@ sub namespace_passed {
if ($job->_last_namespace) {
foreach my $status (@{ $job->_statuslist }) {
next unless ($status->phase and $status->phase eq $workerconf->{phase})
next unless ($status->phase eq $workerconf->{phase})
and ($workerconf->{namespace} eq $job->_last_namespace)
and ($workerconf->{priority} < $job->_last_priority);
return true if $status->is_ok;
@@ -169,8 +169,7 @@ sub add_status {
$status->phase( $job->_current_phase || '' );
push @{ $job->_statuslist }, $status;
debug $status->log if $status->log
and (($status->phase eq 'check')
or ($status->level ne Status->done()->level));
and (($status->phase eq 'check') or $status->not_ok);
}
=head1 ADDITIONAL COLUMNS

View File

@@ -29,7 +29,7 @@ sub worker_body {
try {
$job->started(scalar localtime);
prctl sprintf 'nd2: #%s poll: #%s: %s',
$wid, $job->id, $job->summary;
$wid, $job->id, $job->display_name;
info sprintf "pol (%s): starting %s job(%s) at %s",
$wid, $job->action, $job->id, $job->started;
$self->run($job);

View File

@@ -105,13 +105,13 @@ __PACKAGE__->belongs_to( target => 'App::Netdisco::DB::Result::Device',
=head1 METHODS
=head2 summary
=head2 display_name
An attempt to make a meaningful statement about the job.
=cut
sub summary {
sub display_name {
my $job = shift;
return join ' ',
$job->action,

View File

@@ -51,7 +51,7 @@ register 'register_worker' => sub {
my $no = (exists $workerconf->{no} ? $workerconf->{no} : undef);
my $only = (exists $workerconf->{only} ? $workerconf->{only} : undef);
return $job->add_status( Status->noop('worker not applicable to this device') )
return $job->add_status( Status->info('worker not applicable to this device') )
if ($no and check_acl_no($job->device, $no))
or ($only and not check_acl_only($job->device, $only));
@@ -68,7 +68,7 @@ register 'register_worker' => sub {
}
# per-device action but no device creds available
return $job->add_status( Status->noop('worker driver or action not applicable') )
return $job->add_status( Status->info('worker driver or action not applicable') )
if 0 == scalar @newuserconf;
}

View File

@@ -24,7 +24,7 @@ register_worker({ phase => 'main', driver => 'snmp' }, sub {
my $now = 'to_timestamp('. (join '.', gettimeofday) .')';
store_subnet($_, $now) for @subnets;
return Status->noop(sprintf ' [%s] arpnip - processed %s Subnet entries',
return Status->info(sprintf ' [%s] arpnip - processed %s Subnet entries',
$device->ip, scalar @subnets);
});

View File

@@ -76,7 +76,7 @@ register_worker({ phase => 'main', driver => 'snmp' }, sub {
schema('netdisco')->resultset('Admin')
->find({job => $job->id})->update({device => $new_ip});
return Status->noop(sprintf ' [%s] device - changed IP to %s (%s)',
return Status->info(sprintf ' [%s] device - changed IP to %s (%s)',
$old_ip, $device->ip, ($device->dns || ''));
});
});

View File

@@ -41,7 +41,7 @@ register_worker({ phase => 'main', driver => 'snmp' }, sub {
});
});
return Status->noop(
return Status->info(
sprintf ' [%s] modules - 0 chassis components (added one pseudo for chassis)',
$device->ip);
}
@@ -87,7 +87,7 @@ register_worker({ phase => 'main', driver => 'snmp' }, sub {
$device->ip, $gone;
$device->modules->populate(\@modules);
return Status->noop(sprintf ' [%s] modules - added %d new chassis modules',
return Status->info(sprintf ' [%s] modules - added %d new chassis modules',
$device->ip, scalar @modules);
});
});

View File

@@ -67,6 +67,9 @@ register_worker({ phase => 'main', driver => 'snmp' }, sub {
($remote_id ? (device_key => $remote_id) : ()),
});
}
return Status->info(sprintf ' [%s] neigh - processed %s neighbors',
$device->ip, scalar @to_discover);
});
=head2 store_neighbors( $device )

View File

@@ -19,7 +19,7 @@ register_worker({ phase => 'main', driver => 'snmp' }, sub {
my $p_status = $snmp->peth_power_status;
if (!defined $p_watts) {
return Status->noop(sprintf ' [%s] power - 0 power modules', $device->ip);
return Status->info(sprintf ' [%s] power - 0 power modules', $device->ip);
}
# build device module power info suitable for DBIC
@@ -73,7 +73,7 @@ register_worker({ phase => 'main', driver => 'snmp' }, sub {
$device->ip, $gone;
$device->powered_ports->populate(\@portpower);
return Status->noop(sprintf ' [%s] power - added %d new PoE capable ports',
return Status->info(sprintf ' [%s] power - added %d new PoE capable ports',
$device->ip, scalar @portpower);
});
});

View File

@@ -237,7 +237,7 @@ register_worker({ phase => 'early', driver => 'snmp' }, sub {
$device->update_or_insert(undef, {for => 'update'});
$device->ports->populate([values %interfaces]);
return Status->noop(sprintf ' [%s] interfaces - added %d new interfaces',
return Status->info(sprintf ' [%s] interfaces - added %d new interfaces',
$device->ip, scalar values %interfaces);
});
});

View File

@@ -87,7 +87,7 @@ register_worker({ phase => 'main', driver => 'snmp' }, sub {
$device->ip, $gone;
$device->port_vlans->populate(\@portvlans);
return Status->noop(sprintf ' [%s] vlans - added %d new port VLANs',
return Status->info(sprintf ' [%s] vlans - added %d new port VLANs',
$device->ip, scalar @portvlans);
});
});

View File

@@ -77,7 +77,7 @@ register_worker({ phase => 'main', driver => 'snmp' }, sub {
$device->ip, $gone;
$device->wireless_ports->populate(\@channels);
return Status->noop(sprintf ' [%s] wireless - added %d new wireless channels',
return Status->info(sprintf ' [%s] wireless - added %d new wireless channels',
$device->ip, scalar @channels);
});
});

View File

@@ -33,6 +33,8 @@ register_worker({ phase => 'main' }, sub {
userip => $job->userip,
});
}
return Status->info("Queued macsuck and arpnip for $device.");
});
true;

View File

@@ -20,14 +20,8 @@ register_worker({ phase => 'main', driver => 'snmp' }, sub {
my $cd11_txrate = $snmp->cd11_txrate;
return unless $cd11_txrate and scalar keys %$cd11_txrate;
if (setting('store_wireless_clients')) {
debug sprintf ' [%s] macsuck - gathering wireless client info',
$device->ip;
}
else {
return Status->noop(sprintf ' [%s] macsuck - dot11 info available but skipped due to config',
$device->ip);
}
return Status->info(sprintf ' [%s] macsuck - dot11 info available but skipped due to config',
$device->ip) unless setting('store_wireless_clients');
my $cd11_rateset = $snmp->cd11_rateset();
my $cd11_uptime = $snmp->cd11_uptime();
@@ -77,6 +71,9 @@ register_worker({ phase => 'main', driver => 'snmp' }, sub {
});
});
}
return Status->info(sprintf ' [%s] macsuck - processed %s wireless nodes',
$device->ip, scalar keys %{ $cd11_txrate });
});
true;

View File

@@ -1,4 +1,4 @@
package App::Netdisco::Worker::Plugin::Vlan::Native;
package App::Netdisco::Worker::Plugin::Vlan::Core;
use Dancer ':syntax';
use App::Netdisco::Worker::Plugin;
@@ -18,7 +18,7 @@ register_worker({ phase => 'early', driver => 'snmp' }, sub {
vars->{'iid'} = get_iid($snmp, vars->{'port'})
or return Status->error("Failed to get port ID for [$pn] from $device");
return Status->noop("Vlan set can continue.");
return Status->info("Vlan set can continue.");
});
register_worker({ phase => 'main', driver => 'snmp' }, sub {

View File

@@ -3,7 +3,7 @@ package App::Netdisco::Worker::Status;
use strict;
use warnings;
use Dancer qw/:moose :syntax !error/;
use Dancer qw/:moose :syntax !error !info/;
use Moo;
use namespace::clean;
@@ -26,24 +26,29 @@ The status can be:
=item * C<done>
At C<check> phase, indicates the action may continue. At other phases,
indicates the worker has completed without error or has no work to do.
success and this could be the outcome of the action
=item * C<error>
=item * C<info>
Indicates that there is an error condition. Also used to quit a worker without
side effects that C<done> and C<defer> have.
success and notable but not the main goal of the action
=item * C<defer>
Quits a worker. If the final recorded outcome for a device is C<defer> several
times in a row, then it may be skipped from further jobs.
failed to connect, should increment defer counters
=item * C<error>
had a problem and was unsuccessful
=item * C<()>
skipped the worker for some reason but not fatal
=back
=head1 METHODS
=head2 done, error, defer
=head2 done, info, defer, error
Shorthand for new() with setting param, accepts log as arg.
@@ -58,21 +63,10 @@ sub _make_new {
return $new;
}
sub error { shift->_make_new('error', @_) }
sub done { shift->_make_new('done', @_) }
sub info { shift->_make_new('info', @_) }
sub defer { shift->_make_new('defer', @_) }
=head2 noop
Simply logs a message at debug level if passed, and returns true. Used for
consistency with other Status class methods but really does nothing.
=cut
sub noop {
debug $_[1] if $_[1];
return true;
}
sub error { shift->_make_new('error', @_) }
=head2 is_ok
@@ -84,7 +78,7 @@ sub is_ok { return $_[0]->status eq 'done' }
=head2 not_ok
Returns true if status is C<error> or C<defer>.
Returns true if status is C<error>, C<defer>, or C<info>.
=cut
@@ -98,7 +92,8 @@ A numeric constant for the status, to allow comparison.
sub level {
my $self = shift;
return (($self->status eq 'done') ? 3
return (($self->status eq 'done') ? 4
: ($self->status eq 'info') ? 3
: ($self->status eq 'defer') ? 2 : 1);
}