From febb2b095e849f4f8b3ad4d50bc3d7f8e81cbd8b Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Thu, 22 Feb 2018 21:54:17 +0000 Subject: [PATCH] support for enqueue only netdisco-do --- bin/netdisco-do | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/bin/netdisco-do b/bin/netdisco-do index 7c363d33..9bf64884 100755 --- a/bin/netdisco-do +++ b/bin/netdisco-do @@ -45,12 +45,13 @@ use Scalar::Util 'blessed'; 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 ($device, $port, $extra, $debug, $rollback); +my ($device, $port, $extra, $debug, $queue_only, $rollback); my ($infotrace, $snmptrace, $sqltrace) = (0, 0, 0); my $result = GetOptions( @@ -58,6 +59,7 @@ my $result = GetOptions( 'port|p=s' => \$port, 'extra|e=s' => \$extra, 'debug|D' => \$debug, + 'queue|q' => \$queue_only, 'rollback|R' => \$rollback, 'infotrace|I+' => \$infotrace, 'snmptrace|S+' => \$snmptrace, @@ -117,13 +119,20 @@ foreach my $host (@hostlist) { } # what job are we asked to do? - my $job = App::Netdisco::Backend::Job->new({ - job => 0, + my %job_spec = ( action => $action, device => $dev, port => $port, subaction => $extra, - }); + ); + + if ($queue_only) { + jq_insert({ username => ($ENV{USER} || 'netdisco-do'), %job_spec }); + info sprintf '%s: queued at %s', $action, scalar localtime; + next; + } + + my $job = App::Netdisco::Backend::Job->new({ job => 0, %job_spec }); my $actiontext = ( ($job->device ? ('['.$job->device->ip.']') : '') . @@ -162,7 +171,7 @@ netdisco-do - Run any Netdisco job from the command-line. =head1 SYNOPSIS - ~/bin/netdisco-do [-DISQR] [-d [-p ] [-e ]] + ~/bin/netdisco-do [-DISQRq] [-d [-p ] [-e ]] =head1 DESCRIPTION @@ -172,7 +181,11 @@ This program allows you to run any Netdisco poller job from the command-line. Note that some jobs (C, C, C, C) simply add entries to the Netdisco job queue for other jobs, so won't seem -to do much when you trigger them. +to do much when you trigger them. Everything else happens in real-time. + +However the flag "C<-q>" will force the queueing of the job, regardless of +type. This may be useful for cron-driven actions, or for actions working +across large IP spaces. For any action, if you wish to run one of its individual worker stages, then pass C as the first argument to C, for example