Squashed commit of the following: commit 25bc026dc5e0177cd3aa81c11cdace091eb68f36 Author: Oliver Gorwits <oliver@cpan.org> Date: Mon Jun 17 08:16:56 2013 +0100 bump version for new release commit d4042f6e8db42c7a85df4dcf9690fec72ad2db69 Author: Oliver Gorwits <oliver@cpan.org> Date: Sun Jun 16 18:27:52 2013 +0100 Job Queue page play/pause/refresh controls commit b6c9152516d7800409b7a73c5d0cdce6dd405492 Author: Oliver Gorwits <oliver@cpan.org> Date: Sun Jun 16 17:50:06 2013 +0100 limit size of job queue table commit ac9e5feb8b774071fcf4423dd862dced74dee9e6 Author: Oliver Gorwits <oliver@cpan.org> Date: Sun Jun 16 17:47:55 2013 +0100 update bugs link commit 9c0fb0e9aedc6297f4462c3cf88343f6d0df40b6 Author: Oliver Gorwits <oliver@cpan.org> Date: Sun Jun 16 17:41:29 2013 +0100 update MANIFEST commit 7aaa2fff91ed2b1839bdbb79081d90ad3e144f47 Author: Oliver Gorwits <oliver@cpan.org> Date: Sun Jun 16 17:40:35 2013 +0100 Fix Plack middleware config for Expiry commit 313e2cf014cf0da7cf85074e390ad394b28bf42d Author: Oliver Gorwits <oliver@cpan.org> Date: Sun Jun 16 17:23:00 2013 +0100 Support for delegated authentication with REMOTE_USER and X-REMOTE_USER commit 85e21f2bf296c4a5ca6b5afb5091694e56e3031f Author: Oliver Gorwits <oliver@cpan.org> Date: Sun Jun 16 14:24:08 2013 +0100 Add tooltip showing the job queue item logged status message commit 9b14f53ebed51eb46ea278807cfe8a2fbd28743c Author: Oliver Gorwits <oliver@cpan.org> Date: Sun Jun 16 13:43:26 2013 +0100 Increase default frequency of job queue polling to 2 seconds commit 6ba46818d8ab2100c652c8eb8e98bc6f5a54e273 Author: Oliver Gorwits <oliver@cpan.org> Date: Sun Jun 16 12:57:43 2013 +0100 workaround for https://github.com/PerlDancer/Dancer/issues/935 commit c7a2d8a9d45716959bedbbb8db4cdd82a5950642 Author: Oliver Gorwits <oliver@cpan.org> Date: Sun Jun 16 11:54:18 2013 +0100 Fix hyperlinks when running behind reverse proxy on custom path commit 0620efa404bc25cb0a9ada5aa6f1b092d5c4d482 Author: Oliver Gorwits <oliver@cpan.org> Date: Sat Jun 15 18:31:19 2013 +0100 update deploy docs commit 857b1c7aa0fe832f8948349eda5211eb38ba3099 Author: Oliver Gorwits <oliver@cpan.org> Date: Sat Jun 15 18:16:50 2013 +0100 add note about compiler dependency commit 02a2ad6b2c52db9fbc1e24bc8888f658dc7084ad Author: Oliver Gorwits <oliver@cpan.org> Date: Sat Jun 15 17:44:29 2013 +0100 sort vlans, macs, ips in device port view commit 097bad77310728a98b261a2cfca4de7ab50be94b Author: Oliver Gorwits <oliver@cpan.org> Date: Sat Jun 15 16:32:20 2013 +0100 hint when calling web in fg without starman commit 6425d89ddb2b56129c610482134482d8f9455d40 Author: Oliver Gorwits <oliver@cpan.org> Date: Sat Jun 15 15:53:26 2013 +0100 macwalk and arpwalk refactored commit d527b9d05addc82fb38c84f6fea1aa5818fc68d5 Author: Oliver Gorwits <oliver@cpan.org> Date: Thu Jun 13 22:27:34 2013 +0100 implement is_macsuckable and is_arpnipable commit 7af10ed313e25f5d99a22b53ba438225c2259069 Author: Oliver Gorwits <oliver@cpan.org> Date: Thu Jun 13 22:17:39 2013 +0100 version bump commit 8ace3bf8fa48cf3e14bdf86fad5a4862aad50a4b Author: Oliver Gorwits <oliver@cpan.org> Date: Thu Jun 13 22:14:05 2013 +0100 tidy up user menu commit e6eef605c248471dbfe7ec62cd04d73d653523ca Author: Oliver Gorwits <oliver@cpan.org> Date: Thu Jun 13 22:02:52 2013 +0100 Add discoverall, macwalk, arpwalk items to the Admin Tasks menu commit 2631fabd1eccd8a3971e4762eebe57f406623bee Author: Oliver Gorwits <oliver@cpan.org> Date: Thu Jun 13 21:21:50 2013 +0100 remove length() which only became sane in 5.12 commit a7b7169070a58685cacde26a3b6d462e74be9928 Author: Oliver Gorwits <oliver@cpan.org> Date: Thu Jun 13 19:07:56 2013 +0100 Use DBIx::Class new collapsed query support when we can commit 77cddab8ba7033ccb1ecae257bafa4eef8f99f47 Author: Oliver Gorwits <oliver@cpan.org> Date: Wed Jun 12 17:26:47 2013 +0100 Database config simplified to only four essential settings commit 6ed0802bf2ab0fd898ce6945451b8ca6566ae551 Author: Oliver Gorwits <oliver@cpan.org> Date: Wed Jun 12 13:03:20 2013 +0100 Ask to set up guest user for Admin/Port Control rights in deploy script
		
			
				
	
	
		
			174 lines
		
	
	
		
			4.3 KiB
		
	
	
	
		
			Perl
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			174 lines
		
	
	
		
			4.3 KiB
		
	
	
	
		
			Perl
		
	
	
		
			Executable File
		
	
	
	
	
| #!/usr/bin/env perl
 | |
| 
 | |
| our $home;
 | |
| 
 | |
| BEGIN {
 | |
|   # try to find a localenv if one isn't already in place.
 | |
|   $home = ($ENV{NETDISCO_HOME} || $ENV{HOME});
 | |
| 
 | |
|   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";
 | |
|   }
 | |
| }
 | |
| 
 | |
| use FindBin;
 | |
| FindBin::again();
 | |
| use Path::Class 'dir';
 | |
| 
 | |
| BEGIN {
 | |
|   # stuff useful locations into @INC
 | |
|   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::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>) 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 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
 |