Squashed commit of the following: commite2ca15c0f8Merge:0a90308ffcf6edAuthor: Oliver Gorwits <oliver@cpan.org> Date: Wed May 21 21:18:58 2014 +0100 Merge branch 'master' into og-pluggable-daemon commit0a90308ecfMerge:e80c575ee398fcAuthor: Oliver Gorwits <oliver@cpan.org> Date: Sat May 17 22:20:40 2014 +0100 Merge branch 'master' into og-pluggable-daemon Conflicts: Netdisco/lib/App/Netdisco.pm commite80c575c57Author: Oliver Gorwits <oliver@cpan.org> Date: Sat May 17 22:14:44 2014 +0100 move worker sleep into jobqueue commitc83b999597Author: Oliver Gorwits <oliver@cpan.org> Date: Sat May 17 22:01:43 2014 +0100 support disable manager from jobqueue dynamic code commit4792b0dc49Author: Oliver Gorwits <oliver@cpan.org> Date: Sat May 17 21:34:28 2014 +0100 fix pod name commit187fc84937Author: Oliver Gorwits <oliver@cpan.org> Date: Sat May 17 21:22:06 2014 +0100 better naming commit1c43aaa0f4Author: Oliver Gorwits <oliver@cpan.org> Date: Sat May 17 21:18:49 2014 +0100 make worker use only JobQueue not LocalQueue directly commit5316058ba8Author: Oliver Gorwits <oliver@cpan.org> Date: Sat May 17 20:42:19 2014 +0100 remove unecessary scrub subroutine commit8077e3de9dAuthor: Oliver Gorwits <oliver@cpan.org> Date: Sat May 17 20:31:18 2014 +0100 remove any duplicate jobs when locking commitd4b5e4e6cdAuthor: Oliver Gorwits <oliver@cpan.org> Date: Sat May 17 20:20:32 2014 +0100 rename DefaultSettings to Configuration commitaacb149d09Author: Oliver Gorwits <oliver@cpan.org> Date: Sat May 17 19:57:45 2014 +0100 no need to check - mgr is not started if 0 workers commit46ebe4cd6aAuthor: Oliver Gorwits <oliver@cpan.org> Date: Sat May 17 19:50:37 2014 +0100 remove unecessary job scrub commit60522fe555Author: Oliver Gorwits <oliver@cpan.org> Date: Sat May 17 19:27:53 2014 +0100 fixes for DefaultSettings commit2c6f0dd0f7Author: Oliver Gorwits <oliver@cpan.org> Date: Sat May 17 19:11:50 2014 +0100 rename housekeeping to schedule commitc12034d2b0Author: Oliver Gorwits <oliver@cpan.org> Date: Sat May 17 19:06:22 2014 +0100 new DefaultSettings package, and mv queue to be key of workers commit49e9079f9aMerge:ec8ad3b213f44eAuthor: Oliver Gorwits <oliver@cpan.org> Date: Sat May 17 08:00:02 2014 +0100 Merge branch 'master' into og-pluggable-daemon commitec8ad3b2d8Author: Oliver Gorwits <oliver@cpan.org> Date: Sun May 11 01:18:21 2014 +0100 fix entered_stamp commit471724dd89Author: Oliver Gorwits <oliver@cpan.org> Date: Sat May 10 23:44:14 2014 +0100 fix auto hack commit4620deff33Author: Oliver Gorwits <oliver@cpan.org> Date: Sat May 10 23:27:11 2014 +0100 final migration commit5413e34e83Author: Oliver Gorwits <oliver@cpan.org> Date: Sat May 10 23:18:12 2014 +0100 more JobQueue migration commit9569bda4d8Author: Oliver Gorwits <oliver@cpan.org> Date: Sat May 10 22:44:20 2014 +0100 migrate to JobQueue :) commit41ee8f91f2Author: Oliver Gorwits <oliver@cpan.org> Date: Sat May 10 22:38:20 2014 +0100 simplify again commit58cba4da24Author: Oliver Gorwits <oliver@cpan.org> Date: Sat May 10 22:06:41 2014 +0100 add POD for JobQueue commitc9afbab26bAuthor: Oliver Gorwits <oliver@cpan.org> Date: Sat May 10 21:36:01 2014 +0100 use Module::Load tricks to avoid some other mess commit50c72c1d64Author: Oliver Gorwits <oliver@cpan.org> Date: Sat May 10 21:12:52 2014 +0100 use Module::Load for dynamic loading commit54510a1560Author: Oliver Gorwits <oliver@cpan.org> Date: Thu May 8 22:05:10 2014 +0100 hack to make functional and OO interface commitb8c706a2e7Author: Oliver Gorwits <oliver@cpan.org> Date: Thu May 8 21:29:31 2014 +0100 simplify role apply for jobqueue commit8a816b9764Author: Oliver Gorwits <oliver@cpan.org> Date: Tue May 6 22:20:50 2014 +0100 remove debug print commitf3131adfc8Author: Oliver Gorwits <oliver@cpan.org> Date: Tue May 6 21:47:30 2014 +0100 big patch to remove knowledge of DB from most worker code commit39a0efb3c3Author: Oliver Gorwits <oliver@cpan.org> Date: Mon Apr 28 23:46:10 2014 +0100 port Worker Common to pluggable jobqueue commit8c0614357aAuthor: Oliver Gorwits <oliver@cpan.org> Date: Mon Apr 28 23:04:13 2014 +0100 port Scheduler to pluggable jobqueue commit3882c157ecMerge:44e6c492480646Author: Oliver Gorwits <oliver@cpan.org> Date: Mon Apr 28 22:36:57 2014 +0100 Merge branch 'master' into og-pluggable-daemon commit44e6c49419Merge:fdeeffc5fc6209Author: Oliver Gorwits <oliver@cpan.org> Date: Mon Apr 28 22:35:53 2014 +0100 Merge branch 'master' into og-pluggable-daemon commit5fc62090e2Author: Oliver Gorwits <oliver@cpan.org> Date: Mon Apr 28 22:15:07 2014 +0100 edge topology 17 * Use commitfdeeffcbe4Author: Oliver Gorwits <oliver@cpan.org> Date: Thu Apr 24 23:13:20 2014 +0100 book specifically same jobs which were seen commit0d97c2b819Author: Oliver Gorwits <oliver@cpan.org> Date: Thu Apr 24 22:57:37 2014 +0100 fix typos commit47265a5292Author: Oliver Gorwits <oliver@cpan.org> Date: Thu Apr 24 21:56:52 2014 +0100 rename file to follow name change commitfd169149c4Author: Oliver Gorwits <oliver@cpan.org> Date: Thu Apr 24 21:52:57 2014 +0100 remove job types from web code commit319489ae00Author: Oliver Gorwits <oliver@cpan.org> Date: Thu Apr 24 21:46:30 2014 +0100 remove job types from scheduler commitccdeca600cAuthor: Oliver Gorwits <oliver@cpan.org> Date: Thu Apr 24 21:33:01 2014 +0100 remove job types from netdisco-daemon-fg commit349bddf609Author: Oliver Gorwits <oliver@cpan.org> Date: Thu Apr 24 21:05:42 2014 +0100 move default env settings to Netdisco.pm commitb4b5cce00aAuthor: Oliver Gorwits <oliver@cpan.org> Date: Thu Apr 24 21:01:26 2014 +0100 remove job type knowledge from code into config
		
			
				
	
	
		
			186 lines
		
	
	
		
			4.6 KiB
		
	
	
	
		
			Perl
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			186 lines
		
	
	
		
			4.6 KiB
		
	
	
	
		
			Perl
		
	
	
		
			Executable File
		
	
	
	
	
| #!/usr/bin/env perl
 | |
| 
 | |
| use strict;
 | |
| use warnings;
 | |
| 
 | |
| our $home;
 | |
| 
 | |
| BEGIN {
 | |
|   use FindBin;
 | |
|   FindBin::again();
 | |
| 
 | |
|   $home = ($ENV{NETDISCO_HOME} || $ENV{HOME});
 | |
| 
 | |
|   # try to find a localenv if one isn't already in place.
 | |
|   if (!exists $ENV{PERL_LOCAL_LIB_ROOT}) {
 | |
|       use File::Spec;
 | |
|       my $localenv = File::Spec->catfile($FindBin::RealBin, 'localenv');
 | |
|       exec($localenv, $0, @ARGV) if -f $localenv;
 | |
|       $localenv = File::Spec->catfile($home, 'perl5', 'bin', 'localenv');
 | |
|       exec($localenv, $0, @ARGV) if -f $localenv;
 | |
| 
 | |
|       die "Sorry, can't find libs required for App::Netdisco.\n"
 | |
|         if !exists $ENV{PERLBREW_PERL};
 | |
|   }
 | |
| }
 | |
| 
 | |
| BEGIN {
 | |
|   use Path::Class;
 | |
| 
 | |
|   # stuff useful locations into @INC and $PATH
 | |
|   unshift @INC,
 | |
|     dir($FindBin::RealBin)->parent->subdir('lib')->stringify,
 | |
|     dir($FindBin::RealBin, 'lib')->stringify;
 | |
| }
 | |
| 
 | |
| # for netdisco app config
 | |
| use App::Netdisco;
 | |
| use Dancer qw/:moose :script/;
 | |
| use Dancer::Plugin::DBIC 'schema';
 | |
| 
 | |
| info "App::Netdisco version $App::Netdisco::VERSION loaded.";
 | |
| 
 | |
| use Try::Tiny;
 | |
| use Getopt::Long;
 | |
| Getopt::Long::Configure ("bundling");
 | |
| 
 | |
| my ($device, $port, $extra, $debug);
 | |
| my $result = GetOptions(
 | |
|   'device|d=s' => \$device,
 | |
|   'port|p=s'   => \$port,
 | |
|   'extra|e=s'  => \$extra,
 | |
|   'debug|D'    => \$debug,
 | |
| ) or exit(1);
 | |
| 
 | |
| my $CONFIG = config();
 | |
| $CONFIG->{logger} = 'console';
 | |
| $CONFIG->{log} = ($debug ? 'debug' : 'info');
 | |
| 
 | |
| # reconfigure logging to force console output
 | |
| Dancer::Logger->init('console', $CONFIG);
 | |
| 
 | |
| # for the in-memory local job queue
 | |
| schema('daemon')->deploy;
 | |
| 
 | |
| # get requested action
 | |
| my $action = shift @ARGV;
 | |
| 
 | |
| if (!length $action) {
 | |
|   error 'error: missing action!';
 | |
|   exit (1);
 | |
| }
 | |
| 
 | |
| # create worker (placeholder object for the role methods)
 | |
| {
 | |
|   package MyWorker;
 | |
|   use Moo;
 | |
|   with 'App::Netdisco::Daemon::Worker::Poller::Device';
 | |
|   with 'App::Netdisco::Daemon::Worker::Poller::Arpnip';
 | |
|   with 'App::Netdisco::Daemon::Worker::Poller::Macsuck';
 | |
|   with 'App::Netdisco::Daemon::Worker::Poller::Nbtstat';
 | |
|   with 'App::Netdisco::Daemon::Worker::Poller::Expiry';
 | |
|   with 'App::Netdisco::Daemon::Worker::Interactive::DeviceActions';
 | |
|   with 'App::Netdisco::Daemon::Worker::Interactive::PortActions';
 | |
| }
 | |
| my $worker = MyWorker->new();
 | |
| 
 | |
| # belt and braces check before we go ahead
 | |
| if (not $worker->can( $action )) {
 | |
|   error sprintf 'error: %s is not a valid action', $action;
 | |
|   exit (1);
 | |
| }
 | |
| 
 | |
| # what job are we asked to do?
 | |
| my $job = schema('daemon')->resultset('Admin')->new_result({
 | |
|   job => 0,
 | |
|   action => $action,
 | |
|   device => $device,
 | |
|   port   => $port,
 | |
|   subaction => $extra,
 | |
| });
 | |
| 
 | |
| # do job
 | |
| my ($status, $log);
 | |
| try {
 | |
|     info sprintf '%s: started at %s', $action, scalar localtime;
 | |
|     ($status, $log) = $worker->$action($job);
 | |
| }
 | |
| catch {
 | |
|     $status = 'error';
 | |
|     $log = "error running job: $_";
 | |
| };
 | |
| 
 | |
| info sprintf '%s: finished at %s', $action, scalar localtime;
 | |
| info sprintf '%s: status %s: %s', $action, $status, $log;
 | |
| 
 | |
| exit ($status eq 'done' ? 0 : 1);
 | |
| 
 | |
| =head1 NAME
 | |
| 
 | |
| netdisco-do - Run any Netdisco job from the command-line.
 | |
| 
 | |
| =head1 USAGE
 | |
| 
 | |
|  ~/bin/netdisco-do <action> [-D] [-d <device> [-p <port>] [-e <extra>]]
 | |
| 
 | |
| Regardless of Netdisco configuration, debug level logging is enabled if the
 | |
| C<-D> flag is given.
 | |
| 
 | |
| =head1 DESCRIPTION
 | |
| 
 | |
| This program allows you to run any Netdisco poller job from the command-line.
 | |
| 
 | |
| Note that some jobs (C<discoverall>, C<macwalk>, C<arpwalk>), C<nbtwalk>)
 | |
| simply add entries to the Netdisco job queue for other jobs, so won't seem
 | |
| to do much when you trigger them.
 | |
| 
 | |
| =head1 ACTIONS
 | |
| 
 | |
| =head2 discover
 | |
| 
 | |
| Run a discover on the device (specified with C<-d>).
 | |
| 
 | |
| =head2 macsuck
 | |
| 
 | |
| Run a macsuck on the device (specified with C<-d>).
 | |
| 
 | |
| =head2 arpnip
 | |
| 
 | |
| Run an arpnip on the device (specified with C<-d>).
 | |
| 
 | |
| =head2 nbtstat
 | |
| 
 | |
| Run an nbtstat on the node (specified with C<-d>).
 | |
| 
 | |
| =head2 set_location
 | |
| 
 | |
| Set the SNMP location field on the device (specified with C<-d>). Pass the
 | |
| location string in the C<-e> extra parameter.
 | |
| 
 | |
| =head2 set_contact
 | |
| 
 | |
| Set the SNMP contact field on the device (specified with C<-d>). Pass the
 | |
| contact name in the C<-e> extra parameter.
 | |
| 
 | |
| =head2 set_portname
 | |
| 
 | |
| Set the description on a device port. Requires the C<-d> parameter (device),
 | |
| C<-p> parameter (port), and C<-e> parameter (description).
 | |
| 
 | |
| =head2 set_portcontrol
 | |
| 
 | |
| Set the up/down status on a device port. Requires the C<-d> parameter
 | |
| (device), C<-p> parameter (port), and C<-e> parameter ("up" or "down").
 | |
| 
 | |
| =head2 set_vlan
 | |
| 
 | |
| Set the native VLAN on a device port. Requires the C<-d> parameter (device),
 | |
| C<-p> parameter (port), and C<-e> parameter (VLAN number).
 | |
| 
 | |
| =head2 set_power
 | |
| 
 | |
| Set the PoE on/off status on a device port. Requires the C<-d> parameter
 | |
| (device), C<-p> parameter (port), and C<-e> parameter ("true" or "false").
 | |
| 
 | |
| =cut
 |