5 =head1 NAME $RCSfile: updatefs.pl,v $
15 Andrew DeFaria <Andrew@ClearSCM.com>
23 Mon Dec 13 09:13:27 EST 2010
27 $Date: 2011/06/16 15:12:50 $
33 Usage updatefs.pl: [-u|sage] [-ve|rbose] [-deb|ug]
34 [-host [<host>|all]] [-fs [<fs>|all]]
37 -u|sage: Displays usage
40 -deb|ug: Output debug messages
42 -host [<host>|all]: Update host or all hosts (Default: all)
43 -fs [<fs>|all]: Update filesystem or all (Default: all)
47 This script will record the state of a filesystem.
54 use Net::Domain qw(hostname);
58 use lib "$FindBin::Bin/lib", "$FindBin::Bin/../lib";
66 my $VERSION = '$Revision: 1.29 $';
67 ($VERSION) = ($VERSION =~ /\$Revision: (.*) /);
69 my $clearadm = Clearadm->new;
70 my $clearexec = Clearexec->new;
74 # Given a host and a filesystem, formulate a fs record
76 my ($systemRef, $filesystem) = @_;
78 my %system = %{$systemRef};
80 my %filesystem = $clearadm->GetFilesystem ($system{name}, $filesystem);
82 unless (%filesystem) {
83 error "Filesystem $host:$filesystem not in clearadm database - try adding it";
89 system => $system{name},
90 filesystem => $filesystem,
91 timestamp => Today2SQLDatetime,
94 # Sun is so braindead!
95 # TODO: Verify this works under Solaris
96 if ($system{type} eq 'Unix') {
97 my $cmd = "df -v $filesystem{mount}";
99 my ($status, @unixfs) = $clearexec->execute ($cmd);
102 error ('Unable to determine fsinfo for '
103 . "$system{name}:$filesystem{mount} ($cmd)\n" .
112 for (my $i = 0; $i < scalar @unixfs; $i++) {
113 my @fields = split ' ', $unixfs[$i];
115 $fs{mount} = $fields[0];
116 $fs{size} = $fields[2] * 1024;
117 $fs{used} = $fields[3] * 1024;
118 $fs{free} = $fields[4] * 1024;
119 $fs{reserve} = $fs{size} - $fs{used} - $fs{free};
121 } elsif ($system{type} eq 'Linux' or $system{type} eq 'Windows') {
122 my $cmd = "/bin/df --block-size=1 -P $filesystem{mount}";
124 my ($status, @linuxfs) = $clearexec->execute ($cmd);
127 error ("Unable to determine fsinfo for $system{name}:$filesystem{mount}\n"
128 . join "\n", @linuxfs
140 $fs{size} = $fields[1];
141 $fs{used} = $fields[2];
142 $fs{free} = $fields[3];
143 $fs{mount} = $fields[5];
144 $fs{reserve} = $fs{size} - $fs{used} - $fs{free};
152 'usage' => sub { Usage },
153 'verbose' => sub { set_verbose },
154 'debug' => sub { set_debug },
157 ) or Usage "Invalid parameter";
159 Usage 'Extraneous options: ' . join ' ', @ARGV
163 verbose "$FindBin::Script V$VERSION";
167 for my $system ($clearadm->FindSystem ($host)) {
168 next if $$system{active} eq 'false';
170 my $status = $clearexec->connectToServer (
176 verbose "Unable to connect to system $$system{name}:$$system{port}";
180 for my $filesystem ($clearadm->FindFilesystem ($$system{name}, $fs)) {
181 verbose "Snapshotting $$system{name}:$$filesystem{filesystem}";
183 my %fs = snapshotFS ($system, $$filesystem{filesystem});
186 my ($err, $msg) = $clearadm->AddFS (%fs);
188 error $msg, $err if $err;
191 # Check if over threshold
192 my %notification = $clearadm->GetNotification ('Filesystem');
195 unless %notification;
199 $usedPct = sprintf ('%.2f', (($fs{used} + $fs{reserve}) / $fs{size}) * 100) if $fs{size} != 0;
201 if ($usedPct >= $$filesystem{threshold}) {
204 . " System: $$filesystem{system} "
205 . "Filesystem: $$filesystem{filesystem} Used: $usedPct% "
206 . "Threshold: $$filesystem{threshold}";
208 $clearadm->ClearNotifications ($$system{name}, $$filesystem{filesystem});
212 $clearexec->disconnectFromServer;
219 =head1 CONFIGURATION AND ENVIRONMENT
221 DEBUG: If set then $debug is set to this level.
223 VERBOSE: If set then $verbose is set to this level.
225 TRACE: If set then $trace is set to this level.
233 L<Getopt::Long|Getopt::Long>
235 L<Net::Domain|Net::Domain>
237 =head2 ClearSCM Perl Modules
252 <a href="http://clearscm.com/php/scm_man.php?file=clearadm/lib/Clearadm.pm">Clearadm</a><br>
253 <a href="http://clearscm.com/php/scm_man.php?file=clearadm/lib/Clearexec.pm">Clearexec</a><br>
254 <a href="http://clearscm.com/php/scm_man.php?file=lib/DateUtils.pm">DateUtils</a><br>
255 <a href="http://clearscm.com/php/scm_man.php?file=lib/Display.pm">Display</a><br>
256 <a href="http://clearscm.com/php/scm_man.php?file=lib/Utils.pm">Utils</a><br>
261 =head1 BUGS AND LIMITATIONS
263 There are no known bugs in this script
265 Please report problems to Andrew DeFaria <Andrew@ClearSCM.com>.
267 =head1 LICENSE AND COPYRIGHT
269 Copyright (c) 2010, ClearSCM, Inc. All rights reserved.