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;
100 if (time () - $startTime) > $broadcastTime;
103 verbose "$broadcastTime seconds has elapsed - discovery complete";
109 my $broadcastAddress = inet_ntoa (INADDR_BROADCAST);
112 usage => sub { Usage },
113 verbose => sub { set_verbose },
114 debug => sub { set_debug },
115 'broadcastTime=s' => \$broadcastTime,
116 'broadcastAddr=s' => \$broadcastAddress,
117 ) or Usage "Invalid parameter";
119 Usage 'Extraneous options: ' . join ' ', @ARGV
123 verbose "$FindBin::Script V$VERSION";
125 my $broadcastCmd = 'ping ';
127 if ($ARCHITECTURE eq 'solaris') {
128 $broadcastCmd .= '-s ';
130 $broadcastCmd .= '-b ';
133 $broadcastCmd .= "$broadcastAddress 2>&1";
135 my $pid = open my $broadcast, '-|', $broadcastCmd
136 or error "Unable to do $broadcastCmd", 1;
138 my %hosts = discover $broadcast;
144 my $nbrHosts = scalar keys %hosts;
146 verbose_nolf "Found $nbrHosts host";
147 verbose_nolf 's' if $nbrHosts != 1;
148 verbose " on subnet $broadcastAddress";
150 foreach (sort values %hosts) {
151 my $verbose = get_verbose () ? '-verbose' : '';
153 my ($status, @output) = Execute "updatesystem.pl -host $_ $verbose";
155 error "Unable to update host $_ (Status: $status)\n"
156 . join ("\n", @output), 1
159 verbose join "\n", @output;
164 =head1 CONFIGURATION AND ENVIRONMENT
166 DEBUG: If set then $debug is set to this level.
168 VERBOSE: If set then $verbose is set to this level.
170 TRACE: If set then $trace is set to this level.
178 L<Getop::Long|Getopt::Long>
182 =head2 ClearSCM Perl Modules
195 <a href="http://clearscm.com/php/scm_man.php?file=clearadm/lib/Clearadm.pm">Clearadm</a><br>
196 <a href="http://clearscm.com/php/scm_man.php?file=lib/Display.pm">Display</a><br>
197 <a href="http://clearscm.com/php/scm_man.php?file=lib/Utils.pm">Utils</a><br>
202 =head1 BUGS AND LIMITATIONS
204 There are no known bugs in this script
206 Please report problems to Andrew DeFaria <Andrew@ClearSCM.com>.
208 =head1 LICENSE AND COPYRIGHT
210 Copyright (c) 2010, ClearSCM, Inc. All rights reserved.