fix localenv discovery for scripts
This commit is contained in:
@@ -108,6 +108,7 @@ lib/App/Netdisco/Manual/ReleaseNotes.pod
|
|||||||
lib/App/Netdisco/Manual/WritingPlugins.pod
|
lib/App/Netdisco/Manual/WritingPlugins.pod
|
||||||
lib/App/Netdisco/Util/Device.pm
|
lib/App/Netdisco/Util/Device.pm
|
||||||
lib/App/Netdisco/Util/DNS.pm
|
lib/App/Netdisco/Util/DNS.pm
|
||||||
|
lib/App/Netdisco/Util/Noop.pm
|
||||||
lib/App/Netdisco/Util/Port.pm
|
lib/App/Netdisco/Util/Port.pm
|
||||||
lib/App/Netdisco/Util/PortMAC.pm
|
lib/App/Netdisco/Util/PortMAC.pm
|
||||||
lib/App/Netdisco/Util/SanityCheck.pm
|
lib/App/Netdisco/Util/SanityCheck.pm
|
||||||
|
|||||||
@@ -60,4 +60,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.007000_006
|
version: 2.007000_007
|
||||||
|
|||||||
@@ -3,14 +3,12 @@
|
|||||||
use strict;
|
use strict;
|
||||||
use warnings FATAL => 'all';
|
use warnings FATAL => 'all';
|
||||||
|
|
||||||
use FindBin;
|
|
||||||
FindBin::again();
|
|
||||||
our $home;
|
our $home;
|
||||||
|
|
||||||
BEGIN {
|
BEGIN {
|
||||||
# try really hard to find a localenv if one isn't already in place.
|
# try really hard to find a localenv if one isn't already in place.
|
||||||
$home = ($ENV{NETDISCO_HOME} || $ENV{HOME});
|
$home = ($ENV{NETDISCO_HOME} || $ENV{HOME});
|
||||||
eval "use Daemon::Control";
|
eval "require App::Netdisco::Util::Noop";
|
||||||
|
|
||||||
if ($@) {
|
if ($@) {
|
||||||
use File::Spec;
|
use File::Spec;
|
||||||
@@ -22,7 +20,10 @@ BEGIN {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
use FindBin;
|
||||||
|
FindBin::again();
|
||||||
use Path::Class;
|
use Path::Class;
|
||||||
|
use Daemon::Control;
|
||||||
|
|
||||||
my $netdisco = file($FindBin::RealBin, 'netdisco-daemon-fg');
|
my $netdisco = file($FindBin::RealBin, 'netdisco-daemon-fg');
|
||||||
my @args = (scalar @ARGV > 1 ? @ARGV[1 .. $#ARGV] : ());
|
my @args = (scalar @ARGV > 1 ? @ARGV[1 .. $#ARGV] : ());
|
||||||
|
|||||||
@@ -1,13 +1,11 @@
|
|||||||
#!/usr/bin/env perl
|
#!/usr/bin/env perl
|
||||||
|
|
||||||
use FindBin;
|
|
||||||
FindBin::again();
|
|
||||||
our $home;
|
our $home;
|
||||||
|
|
||||||
BEGIN {
|
BEGIN {
|
||||||
# try really hard to find a localenv if one isn't already in place.
|
# try really hard to find a localenv if one isn't already in place.
|
||||||
$home = ($ENV{NETDISCO_HOME} || $ENV{HOME});
|
$home = ($ENV{NETDISCO_HOME} || $ENV{HOME});
|
||||||
eval "use Daemon::Control";
|
eval "require App::Netdisco::Util::Noop";
|
||||||
|
|
||||||
if ($@) {
|
if ($@) {
|
||||||
use File::Spec;
|
use File::Spec;
|
||||||
@@ -19,11 +17,14 @@ BEGIN {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
use FindBin;
|
||||||
|
FindBin::again();
|
||||||
|
use Path::Class;
|
||||||
|
|
||||||
BEGIN {
|
BEGIN {
|
||||||
# stuff useful locations into @INC and $PATH
|
# stuff useful locations into @INC and $PATH
|
||||||
my $location = $FindBin::RealBin;
|
my $location = $FindBin::RealBin;
|
||||||
|
|
||||||
use Path::Class;
|
|
||||||
unshift @INC,
|
unshift @INC,
|
||||||
dir($location)->parent->subdir('lib')->stringify,
|
dir($location)->parent->subdir('lib')->stringify,
|
||||||
dir($location, 'lib')->stringify;
|
dir($location, 'lib')->stringify;
|
||||||
@@ -35,6 +36,7 @@ BEGIN {
|
|||||||
use App::Netdisco;
|
use App::Netdisco;
|
||||||
use Dancer ':script';
|
use Dancer ':script';
|
||||||
use Dancer::Plugin::DBIC 'schema';
|
use Dancer::Plugin::DBIC 'schema';
|
||||||
|
|
||||||
info "App::Netdisco version $App::Netdisco::VERSION loaded.";
|
info "App::Netdisco version $App::Netdisco::VERSION loaded.";
|
||||||
|
|
||||||
use 5.010_000;
|
use 5.010_000;
|
||||||
|
|||||||
@@ -1,5 +1,22 @@
|
|||||||
#!/usr/bin/env perl
|
#!/usr/bin/env perl
|
||||||
|
|
||||||
|
our $home;
|
||||||
|
|
||||||
|
BEGIN {
|
||||||
|
# try really hard to find a localenv if one isn't already in place.
|
||||||
|
$home = ($ENV{NETDISCO_HOME} || $ENV{HOME});
|
||||||
|
eval "require App::Netdisco::Util::Noop";
|
||||||
|
|
||||||
|
if ($@) {
|
||||||
|
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;
|
use FindBin;
|
||||||
FindBin::again();
|
FindBin::again();
|
||||||
use Path::Class 'dir';
|
use Path::Class 'dir';
|
||||||
@@ -16,71 +33,6 @@ use App::Netdisco;
|
|||||||
use Dancer qw/:moose :script/;
|
use Dancer qw/:moose :script/;
|
||||||
use Dancer::Plugin::DBIC 'schema';
|
use Dancer::Plugin::DBIC 'schema';
|
||||||
|
|
||||||
=head1 NAME
|
|
||||||
|
|
||||||
netdisco-do - Run any Netdisco poller 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
|
|
||||||
|
|
||||||
info "App::Netdisco version $App::Netdisco::VERSION loaded.";
|
info "App::Netdisco version $App::Netdisco::VERSION loaded.";
|
||||||
|
|
||||||
use Try::Tiny;
|
use Try::Tiny;
|
||||||
@@ -164,3 +116,68 @@ info sprintf '%s: finished at %s', $action, scalar localtime;
|
|||||||
info sprintf '%s: status %s: %s', $action, $status, $log;
|
info sprintf '%s: status %s: %s', $action, $status, $log;
|
||||||
|
|
||||||
exit ($status eq 'done' ? 0 : 1);
|
exit ($status eq 'done' ? 0 : 1);
|
||||||
|
|
||||||
|
=head1 NAME
|
||||||
|
|
||||||
|
netdisco-do - Run any Netdisco poller 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
|
||||||
|
|||||||
@@ -3,14 +3,12 @@
|
|||||||
use strict;
|
use strict;
|
||||||
use warnings FATAL => 'all';
|
use warnings FATAL => 'all';
|
||||||
|
|
||||||
use FindBin;
|
|
||||||
FindBin::again();
|
|
||||||
our $home;
|
our $home;
|
||||||
|
|
||||||
BEGIN {
|
BEGIN {
|
||||||
# try really hard to find a localenv if one isn't already in place.
|
# try really hard to find a localenv if one isn't already in place.
|
||||||
$home = ($ENV{NETDISCO_HOME} || $ENV{HOME});
|
$home = ($ENV{NETDISCO_HOME} || $ENV{HOME});
|
||||||
eval "use Daemon::Control";
|
eval "require App::Netdisco::Util::Noop";
|
||||||
|
|
||||||
if ($@) {
|
if ($@) {
|
||||||
use File::Spec;
|
use File::Spec;
|
||||||
@@ -22,7 +20,10 @@ BEGIN {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
use FindBin;
|
||||||
|
FindBin::again();
|
||||||
use Path::Class;
|
use Path::Class;
|
||||||
|
use Daemon::Control;
|
||||||
|
|
||||||
my $netdisco = file($FindBin::RealBin, 'netdisco-web-fg');
|
my $netdisco = file($FindBin::RealBin, 'netdisco-web-fg');
|
||||||
my @args = (scalar @ARGV > 1 ? @ARGV[1 .. $#ARGV] : ());
|
my @args = (scalar @ARGV > 1 ? @ARGV[1 .. $#ARGV] : ());
|
||||||
|
|||||||
@@ -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.007000_006';
|
our $VERSION = '2.007000_007';
|
||||||
|
|
||||||
BEGIN {
|
BEGIN {
|
||||||
if (not length ($ENV{DANCER_APPDIR} || '')
|
if (not length ($ENV{DANCER_APPDIR} || '')
|
||||||
|
|||||||
5
Netdisco/lib/App/Netdisco/Util/Noop.pm
Normal file
5
Netdisco/lib/App/Netdisco/Util/Noop.pm
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
package App::Netdisco::Util::Noop;
|
||||||
|
|
||||||
|
# used for testing library access.
|
||||||
|
|
||||||
|
1;
|
||||||
Reference in New Issue
Block a user