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 foreach ('ufs', 'vxfs') {
98 my $cmd = "/usr/bin/df -k -F $filesystem{mount}";
100 my ($status, @unixfs) = $clearexec->execute ($cmd);
103 error ('Unable to determine fsinfo for '
104 . "$system{name}:$filesystem{mount} ($cmd)\n" .
114 for (my $i = 0; $i < scalar @unixfs; $i++) {
117 # Trim leading and trailing spaces
118 $unixfs[$i] =~ s/^\s+//;
119 $unixfs[$i] =~ s/\s+$//;
121 my @fields = split /\s+/, $unixfs[$i];
127 @fields = split /\s+/, $unixfs[$i];;
132 $fs{size} = $fields[$firstField] * 1024;
133 $fs{used} = $fields[$firstField + 1] * 1024;
134 $fs{free} = $fields[$firstField + 2] * 1024;
135 $fs{reserve} = $fs{size} - $fs{used} - $fs{free};
138 } elsif ($system{type} eq 'Linux' or $system{type} eq 'Windows') {
139 my $cmd = "/bin/df --block-size=1 -P $filesystem{mount}";
141 my ($status, @linuxfs) = $clearexec->execute ($cmd);
144 error ("Unable to determine fsinfo for $system{name}:$filesystem{mount}\n"
145 . join "\n", @linuxfs
157 $fs{size} = $fields[1];
158 $fs{used} = $fields[2];
159 $fs{free} = $fields[3];
160 $fs{mount} = $fields[5];
161 $fs{reserve} = $fs{size} - $fs{used} - $fs{free};
169 'usage' => sub { Usage },
170 'verbose' => sub { set_verbose },
171 'debug' => sub { set_debug },
174 ) or Usage "Invalid parameter";
176 Usage 'Extraneous options: ' . join ' ', @ARGV
180 verbose "$FindBin::Script V$VERSION";
184 foreach my $system ($clearadm->FindSystem ($host)) {
185 next if $$system{active} eq 'false';
187 my $status = $clearexec->connectToServer (
193 verbose "Unable to connect to system $$system{name}:$$system{port}";
197 foreach my $filesystem ($clearadm->FindFilesystem ($$system{name}, $fs)) {
198 verbose "Snapshotting $$system{name}:$$filesystem{filesystem}";
200 my %fs = snapshotFS ($system, $$filesystem{filesystem});
203 my ($err, $msg) = $clearadm->AddFS (%fs);
205 error $msg, $err if $err;
208 # Check if over threshold
209 my %notification = $clearadm->GetNotification ('Filesystem');
212 unless %notification;
214 my $usedPct = sprintf (
216 (($fs{used} + $fs{reserve}) / $fs{size}) * 100
219 if ($usedPct >= $$filesystem{threshold}) {
221 display YMDHMS . " System: $$filesystem{system} "
222 . "Filesystem: $$filesystem{filesystem} Used: $usedPct% "
223 . "Threshold: $$filesystem{threshold}";
225 $clearadm->ClearNotifications ($$system{name}, $$filesystem{filesystem});
229 $clearexec->disconnectFromServer;
236 =head1 CONFIGURATION AND ENVIRONMENT
238 DEBUG: If set then $debug is set to this level.
240 VERBOSE: If set then $verbose is set to this level.
242 TRACE: If set then $trace is set to this level.
250 L<Getopt::Long|Getopt::Long>
252 L<Net::Domain|Net::Domain>
254 =head2 ClearSCM Perl Modules
269 <a href="http://clearscm.com/php/scm_man.php?file=clearadm/lib/Clearadm.pm">Clearadm</a><br>
270 <a href="http://clearscm.com/php/scm_man.php?file=clearadm/lib/Clearexec.pm">Clearexec</a><br>
271 <a href="http://clearscm.com/php/scm_man.php?file=lib/DateUtils.pm">DateUtils</a><br>
272 <a href="http://clearscm.com/php/scm_man.php?file=lib/Display.pm">Display</a><br>
273 <a href="http://clearscm.com/php/scm_man.php?file=lib/Utils.pm">Utils</a><br>
278 =head1 BUGS AND LIMITATIONS
280 There are no known bugs in this script
282 Please report problems to Andrew DeFaria <Andrew@ClearSCM.com>.
284 =head1 LICENSE AND COPYRIGHT
286 Copyright (c) 2010, ClearSCM, Inc. All rights reserved.