* Add macsuck worker to collect various PortAccessEntity (NAC) attributes * Incorporate PAE feedback on #937 * missing Result/Device.pm column added * pae_is... columns instead of pae_capabilities * moved most code to Util/PortAccessEntity.pm so the update can be done in discover and macsuck * Refactor PAE attributes during discover as separate Plugin * PortAccessEntity: don't use device->dns in log string * Fix "Experimental keys on scalar is now forbidden" test failure * Revamp pae_control and add missing attribute - device.pae_control (text) is now device.pae_is_enabled (bool) - also store pae_authconfig_port_control (port mode auto/force(un)Auth) * Fix "Experimental keys on scalar is now forbidden" test failure - ... again because of botched merge - at least perlgolfed away a set of curly braces * Update PortAccessEntity.pm * Incorporate @ollyg PR feedback * allow actions without transport to run when there are also no creds * initial refactor for separate gather, process, store phases for macsuck * factor out the vlan sanity check * additional help with log of action workers * cleanup logic in check macsuck * refactor to make main phases only * some fixes * implement file slurp. amazingly the whole thing works * remove outdated noop from test * treat error as critical, use cancel to suppress further drivers * big refactor to share mac sanity code to both paths * fix inverted logic on vlan sanity filter * some code tidy * fix error in default value * fix for vlan 0 nodes input from cli * ensure imported MACs are IEEE format * add api endpoint, no useful return status yet * exit status if error from nodes PUT * suppress other networked workers when direct workers are active * better log showing worker * fix status recording to get first error or last done message * implement arpnip API PUT * avoid package redeclaration error * make sure write API methods require admin status * add doc for passing JSON data to arpnip and macsuck * update manifest * remove option to do jobs in web handler; all by queue now * use job entry timestamp for offline queued jobs * fix store username and IP on api PUT * never de-duplicate user-submitted jobs; never reset DeviceSkip for offline jobs * myworker no longer needed * make logic cleaner Co-authored-by: Christian Ramseyer <ramseyer@netnea.com>
		
			
				
	
	
		
			106 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			Perl
		
	
	
	
	
	
			
		
		
	
	
			106 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			Perl
		
	
	
	
	
	
| package App::Netdisco::Worker::Status;
 | |
| 
 | |
| use strict;
 | |
| use warnings;
 | |
| 
 | |
| use Dancer qw/:moose :syntax !error !info/;
 | |
| 
 | |
| use Moo;
 | |
| use namespace::clean;
 | |
| 
 | |
| has 'status' => (
 | |
|   is => 'rw',
 | |
|   default => undef,
 | |
| );
 | |
| 
 | |
| has [qw/log phase/] => (
 | |
|   is => 'rw',
 | |
|   default => '',
 | |
| );
 | |
| 
 | |
| =head1 INTRODUCTION
 | |
| 
 | |
| The status can be:
 | |
| 
 | |
| =over 4
 | |
| 
 | |
| =item * C<done>
 | |
| 
 | |
| Indicates a state of success and a log message which may be used as the
 | |
| outcome for the action.
 | |
| 
 | |
| =item * C<info>
 | |
| 
 | |
| The worker has completed successfully and a debug log will be issued, but the
 | |
| outcome is not the main goal of the action.
 | |
| 
 | |
| =item * C<defer>
 | |
| 
 | |
| Issued when the worker has failed to connect to the remote device, or is not
 | |
| permitted to connect (through user config).
 | |
| 
 | |
| =item * C<error>
 | |
| 
 | |
| Something went wrong which should not normally be the case.
 | |
| 
 | |
| =item * C<()>
 | |
| 
 | |
| This is not really a status. The worker can return any value not an instance
 | |
| of this class to indicate a "pass", or non-error conclusion.
 | |
| 
 | |
| =back
 | |
| 
 | |
| =head1 METHODS
 | |
| 
 | |
| =head2 done, info, defer, error
 | |
| 
 | |
| Shorthand for new() with setting param, accepts log as arg.
 | |
| 
 | |
| =cut
 | |
| 
 | |
| sub _make_new {
 | |
|   my ($self, $status, $log) = @_;
 | |
|   die unless $status;
 | |
|   my $new = (ref $self ? $self : $self->new());
 | |
|   $new->log($log);
 | |
|   $new->status($status);
 | |
|   return $new;
 | |
| }
 | |
| 
 | |
| sub done  { shift->_make_new('done', @_)  }
 | |
| sub info  { shift->_make_new('info', @_)  }
 | |
| sub defer { shift->_make_new('defer', @_) }
 | |
| sub error { shift->_make_new('error', @_) }
 | |
| 
 | |
| =head2 is_ok
 | |
| 
 | |
| Returns true if status is C<done>.
 | |
| 
 | |
| =cut
 | |
| 
 | |
| sub is_ok { return $_[0]->status eq 'done' }
 | |
| 
 | |
| =head2 not_ok
 | |
| 
 | |
| Returns true if status is C<error>, C<defer>, or C<info>.
 | |
| 
 | |
| =cut
 | |
| 
 | |
| sub not_ok { return (not $_[0]->is_ok) }
 | |
| 
 | |
| =head2 level
 | |
| 
 | |
| A numeric constant for the status, to allow comparison.
 | |
| 
 | |
| =cut
 | |
| 
 | |
| sub level {
 | |
|   my $self = shift;
 | |
|   return (($self->status eq 'error') ? 4
 | |
|         : ($self->status eq 'done')  ? 3
 | |
|         : ($self->status eq 'defer') ? 2
 | |
|         : ($self->status eq 'info')  ? 1 : 0);
 | |
| }
 | |
| 
 | |
| 1;
 |