5 =head1 NAME $RCSfile: discovery.pl,v $
15 Andrew DeFaria <Andrew@ClearSCM.com>
23 Mon Dec 13 09:13:27 EST 2010
27 $Date: 2011/01/07 20:48:22 $
33 Usage updatesystem.pl: [-u|sage] [-ve|rbose] [-deb|ug]
34 [-b|roadcastTime <seconds>]
37 -u|sage: Displays usage
40 -deb|ug: Output debug messages
42 -broadcastA|ddr <ip>: Broadcast IP (Default: Current subnet)
43 -broadcastT|ime <seconds>: Number of sends to wait for responses to broadcast
48 This script will discover systems on the local subnet and then add or update
49 them in the Clearadm database.
61 use lib "$FindBin::Bin/lib", "$FindBin::Bin/../lib";
68 my $VERSION = '$Revision: 1.1 $';
69 ($VERSION) = ($VERSION =~ /\$Revision: (.*) /);
71 my $clearadm = Clearadm->new;
73 my $broadcastTime = 10;
82 verbose "Performing discovery (for $broadcastTime seconds)...";
84 while (<$broadcast>) {
85 display "Received line: $_";
86 if (/from (\S+) \((.+)\)/) {
91 $hostname =~ s/(\w+)\..*/$1/;
93 unless ($hosts{$ip}) {
94 verbose "Received response from ($ip): $hostname";
95 $hosts{$ip} = $hostname;
99 last if (time() - $startTime) > $broadcastTime;
102 verbose "$broadcastTime seconds has elapsed - discovery complete";
108 my $broadcastAddress = inet_ntoa(INADDR_BROADCAST);
111 usage => sub { Usage },
112 verbose => sub { set_verbose },
113 debug => sub { set_debug },
114 'broadcastTime=s' => \$broadcastTime,
115 'broadcastAddr=s' => \$broadcastAddress,
116 ) or Usage "Invalid parameter";
118 Usage 'Extraneous options: ' . join ' ', @ARGV if @ARGV;
121 verbose "$FindBin::Script V$VERSION";
123 my $broadcastCmd = 'ping ';
125 if ($ARCHITECTURE eq 'solaris') {
126 $broadcastCmd .= '-s ';
128 $broadcastCmd .= '-b ';
131 $broadcastCmd .= "$broadcastAddress 2>&1";
133 my $pid = open my $broadcast, '-|', $broadcastCmd
134 or error "Unable to do $broadcastCmd", 1;
136 my %hosts = discover $broadcast;
142 my $nbrHosts = scalar keys %hosts;
144 verbose_nolf "Found $nbrHosts host";
145 verbose_nolf 's' if $nbrHosts != 1;
146 verbose " on subnet $broadcastAddress";
148 for (sort values %hosts) {
149 my $verbose = get_verbose() ? '-verbose' : '';
151 my ($status, @output) = Execute "updatesystem.pl -host $_ $verbose";
153 error "Unable to update host $_ (Status: $status)\n" . join ("\n", @output), 1 if $status;
155 verbose join "\n", @output;
160 =head1 CONFIGURATION AND ENVIRONMENT
162 DEBUG: If set then $debug is set to this level.
164 VERBOSE: If set then $verbose is set to this level.
166 TRACE: If set then $trace is set to this level.
174 L<Getop::Long|Getopt::Long>
178 =head2 ClearSCM Perl Modules
191 <a href="http://clearscm.com/php/scm_man.php?file=clearadm/lib/Clearadm.pm">Clearadm</a><br>
192 <a href="http://clearscm.com/php/scm_man.php?file=lib/Display.pm">Display</a><br>
193 <a href="http://clearscm.com/php/scm_man.php?file=lib/Utils.pm">Utils</a><br>
198 =head1 BUGS AND LIMITATIONS
200 There are no known bugs in this script
202 Please report problems to Andrew DeFaria <Andrew@ClearSCM.com>.
204 =head1 LICENSE AND COPYRIGHT
206 Copyright (c) 2010, ClearSCM, Inc. All rights reserved.