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";
67 my $VERSION = '$Revision: 1.1 $';
68 ($VERSION) = ($VERSION =~ /\$Revision: (.*) /);
70 my $clearadm = Clearadm->new;
72 my $broadcastTime = 10;
81 verbose "Performing discovery (for $broadcastTime seconds)...";
83 while (<$broadcast>) {
86 my $hostname = gethostbyaddr (inet_aton ($ip), AF_INET);
88 unless ($hosts{$ip}) {
89 verbose "Received response from ($ip): $hostname";
90 $hosts{$ip} = $hostname;
95 if (time () - $startTime) > $broadcastTime;
98 verbose "$broadcastTime seconds has elapsed - discovery complete";
104 my $broadcastAddress = inet_ntoa (INADDR_BROADCAST);
107 usage => sub { Usage },
108 verbose => sub { set_verbose },
109 debug => sub { set_debug },
110 'broadcastTime=s' => \$broadcastTime,
111 'broadcastAddr=s' => \$broadcastAddress,
112 ) or Usage "Invalid parameter";
114 Usage 'Extraneous options: ' . join ' ', @ARGV
118 verbose "$FindBin::Script V$VERSION";
120 my $broadcastCmd = "ping -b $broadcastAddress 2>&1";
122 my $pid = open my $broadcast, '-|', $broadcastCmd
123 or error "Unable to do $broadcastCmd", 1;
125 my %hosts = discover $broadcast;
131 my $nbrHosts = scalar keys %hosts;
133 verbose_nolf "Found $nbrHosts host";
134 verbose_nolf 's' if $nbrHosts != 1;
135 verbose " on subnet $broadcastAddress";
137 foreach (sort values %hosts) {
138 my $verbose = get_verbose () ? '-verbose' : '';
140 my ($status, @output) = Execute "updatesystem.pl -host $_ $verbose";
142 error "Unable to update host $_ (Status: $status)\n"
143 . join ("\n", @output), 1
146 verbose join "\n", @output;
151 =head1 CONFIGURATION AND ENVIRONMENT
153 DEBUG: If set then $debug is set to this level.
155 VERBOSE: If set then $verbose is set to this level.
157 TRACE: If set then $trace is set to this level.
165 L<Getop::Long|Getopt::Long>
169 =head2 ClearSCM Perl Modules
182 <a href="http://clearscm.com/php/scm_man.php?file=clearadm/lib/Clearadm.pm">Clearadm</a><br>
183 <a href="http://clearscm.com/php/scm_man.php?file=lib/Display.pm">Display</a><br>
184 <a href="http://clearscm.com/php/scm_man.php?file=lib/Utils.pm">Utils</a><br>
189 =head1 BUGS AND LIMITATIONS
191 There are no known bugs in this script
193 Please report problems to Andrew DeFaria <Andrew@ClearSCM.com>.
195 =head1 LICENSE AND COPYRIGHT
197 Copyright (c) 2010, ClearSCM, Inc. All rights reserved.