App-Netdisco
view release on metacpan or search on metacpan
bin/netdisco-do view on Meta::CPAN
#!/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 Try::Tiny;
use Pod::Usage;
use Scalar::Util 'blessed';
use File::Slurper qw/read_lines read_text/;
use NetAddr::IP qw/:rfc3021 :lower/;
use App::Netdisco::Backend::Job;
use App::Netdisco::JobQueue 'jq_insert';
use App::Netdisco::Util::Device 'get_device';
use Getopt::Long;
Getopt::Long::Configure ("bundling");
my ($port, $extra, $debug, $quiet, $queue_only, $force, $dryrun, $rollback);
my ($devices, $infotrace, $snmptrace, $sqltrace) = ([], 0, 0, 0);
my $result = GetOptions(
'device|d=s@' => \$devices,
'port|p=s' => \$port,
'extra|e=s' => \$extra,
'debug|D' => \$debug,
'enqueue' => \$queue_only,
'force' => \$force,
'dry-run' => \$dryrun,
'quiet' => \$quiet,
'rollback|R' => \$rollback,
'infotrace|I+' => \$infotrace,
'snmptrace|S+' => \$snmptrace,
'sqltrace|Q+' => \$sqltrace,
) or pod2usage(
-msg => 'error: bad options',
-verbose => 0,
-exitval => 1,
);
if ($dryrun) {
$ENV{ND2_WORKER_ROLL_CALL} = 1;
$debug = 1;
}
my $CONFIG = config();
bin/netdisco-do view on Meta::CPAN
=head2 renumber
Change the canonical IP address of a device (specified with C<-d>). Pass the
new IP address in the C<-e> parameter. All related records such as topology,
log and node information will also be updated to refer to the new device.
Note that I<no> check is made as to whether the new IP is reachable for future
polling.
~/bin/netdisco-do renumber -d 192.0.2.1 -e 192.0.2.254
=head2 nbtstat
Run an nbtstat on the node (specified with C<-d>).
~/bin/netdisco-do nbtstat -d 192.0.2.2
=head2 nbtwalk
Queue an nbtstat for all known nodes.
=head2 Custom Field update
Update a Device or Device Port custom field using `netdisco-do`. Specify
the field name as the "action" prefixed with `cf_`. The content can be
passed in the command, or taken from a file, or from standard input.
#Â pass directly
~/bin/netdisco-do cf_myfield --enqueue -d 192.0.2.1 -e 'field value'
#Â pipe from standard input
~/bin/netdisco-do cf_myfield --enqueue -d 192.0.2.1 -e '@-'
#Â read from a file
~/bin/netdisco-do cf_myfield --enqueue -d 192.0.2.1 -e '@/tmp/myfield'
Note that `--enqueue ` is *required* for the feature to work. The change
is, however, applied instanty in the database when `netdisco-do` runs.
=head2 expire
Run Device and Node expiry actions according to configuration.
=head2 expirenodes
Archive nodes on the specified device. If you want to delete nodes, set the
C<-e> parameter to "C<no>" (mnemonic: B<e>xpire). If you want to perform the
action on a specific port, set the C<-p> parameter.
~/bin/netdisco-do expirenodes -d 192.0.2.1
~/bin/netdisco-do expirenodes -d 192.0.2.1 -p FastEthernet0/1 -e no
=head2 graph
Generate GraphViz graphs for the largest cluster of devices.
You'll need to install the L<Graph::Undirected> and L<GraphViz> Perl modules,
and possibly also the C<graphviz> utility for your operating system. Also
create a directory for the output files.
mkdir ~/graph
~/bin/localenv cpanm Graph::Undirected
~/bin/localenv cpanm GraphViz
=head2 show
Dump the content of an SNMP MIB Object or an L<SNMP::Info> method, useful for
diagnostics and troubleshooting.
You should provide the "C<-e>" option which is the name of the method or
object, such as C<interfaces> or C<uptime> or C<ifDescr>.
If you wish to specify the SNMP MIB to load and find the Object in, then
you can qualify the "C<-e>" parameter, such as C<IF-MIB::ifDescr>.
If you wish to test with a specific L<SNMP::Info> device class other than the
one discovered, pass this in the "C<-p>" parameter, such as C<Layer3> or
C<SNMP::Info::Layer3> (the C<SNMP::Info> prefix is optional).
All "C<-e>" parameters are case sensitive.
~/bin/netdisco-do show -d 192.0.2.1 -e interfaces
~/bin/netdisco-do show -d 192.0.2.1 -e IF-MIB::ifDescr
~/bin/netdisco-do show -d 192.0.2.1 -e interfaces -p SNMP::Info::Layer2::HP
~/bin/netdisco-do show -d 192.0.2.1 -e ifName -p Layer3::Arista
The "C<-e>" parameter C<specify> will show the used configuration for the
specified device.
~/bin/netdisco-do show -d 192.0.2.1 -e specify
Passing the "C< --quiet >" command line flag will cause C<show> to return
data in a compact JSON format (suitable for piping to C<jq>, for example).
If the output is very long, you may see a "skipping..." message. Work
around this by passing "C< --quiet >" and then pipe the output to
"C<jq .>".
This command works well with the "C<-I>" debug flag on L<SNMP::Info> (or
"C<-II>").
=head2 psql
Start an interactive terminal with the Netdisco PostgreSQL database. If you
pass an SQL statement in the C<-e> option then it will be executed.
~/bin/netdisco-do psql
~/bin/netdisco-do psql -e 'SELECT ip, dns FROM device'
~/bin/netdisco-do psql -e 'COPY (SELECT ip, dns FROM device) TO STDOUT WITH CSV HEADER'
=head2 stats
Updates Netdisco's statistics on number of devices, nodes, etc, for today.
=head2 location
Set the SNMP location field on the device (specified with C<-d>). Pass the
location string in the C<-e> extra parameter. Use C<--force> to bypass
user access controls.
~/bin/netdisco-do location -d 192.0.2.1 -e 'wiring closet'
=head2 contact
( run in 1.166 second using v1.01-cache-2.11-cpan-5735350b133 )