X-Git-Url: https://defaria.com/gitweb/?a=blobdiff_plain;f=clearadm%2Fupdatefs.pl;h=6308e35bcd2f6e2cdb4fb1ec0e858d517050d8bd;hb=HEAD;hp=75f830c5c58295223c70f52448fa5c7c333b08d5;hpb=020a4a5ea2be725b155cae3a2cadc9aba3911b9b;p=clearscm.git diff --git a/clearadm/updatefs.pl b/clearadm/updatefs.pl index 75f830c..6308e35 100755 --- a/clearadm/updatefs.pl +++ b/clearadm/updatefs.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/local/bin/perl =pod @@ -54,6 +54,7 @@ use warnings; use Net::Domain qw(hostname); use FindBin; use Getopt::Long; +use Convert::Base64; use lib "$FindBin::Bin/lib", "$FindBin::Bin/../lib"; @@ -72,17 +73,17 @@ my $clearexec = Clearexec->new; my ($host, $fs); # Given a host and a filesystem, formulate a fs record -sub snapshotFS ($$) { +sub snapshotFS($$) { my ($systemRef, $filesystem) = @_; my %system = %{$systemRef}; - my %filesystem = $clearadm->GetFilesystem ($system{name}, $filesystem); + my %filesystem = $clearadm->GetFilesystem($system{name}, $filesystem); unless (%filesystem) { - error "Filesystem $host:$filesystem not in clearadm database - try adding it"; - - return; + error "Filesystem $host:$filesystem not in clearadm database - try adding it"; + + return; } # unless my %fs = ( @@ -94,47 +95,30 @@ sub snapshotFS ($$) { # Sun is so braindead! # TODO: Verify this works under Solaris if ($system{type} eq 'Unix') { - foreach ('ufs', 'vxfs') { - my $cmd = "/usr/bin/df -k -F $filesystem{mount}"; + my $cmd = "df -v $filesystem{mount}"; - my ($status, @unixfs) = $clearexec->execute ($cmd); + my ($status, @unixfs) = $clearexec->execute ($cmd); - if ($status != 0) { - error ('Unable to determine fsinfo for ' - . "$system{name}:$filesystem{mount} ($cmd)\n" . - join "\n", @unixfs - ); - - return; - } # if + if ($status != 0) { + error ('Unable to determine fsinfo for ' + . "$system{name}:$filesystem{mount} ($cmd)\n" + . join "\n", @unixfs); + + return; + } # if - # Skip heading - shift @unixfs; + # Skip heading + shift @unixfs; - for (my $i = 0; $i < scalar @unixfs; $i++) { - my $firstField; - - # Trim leading and trailing spaces - $unixfs[$i] =~ s/^\s+//; - $unixfs[$i] =~ s/\s+$//; - - my @fields = split /\s+/, $unixfs[$i]; - - if (@fields == 1) { - $firstField = 0; - $i++; - - @fields = split /\s+/, $unixfs[$i];; - } else { - $firstField = 1; - } #if - - $fs{size} = $fields[$firstField] * 1024; - $fs{used} = $fields[$firstField + 1] * 1024; - $fs{free} = $fields[$firstField + 2] * 1024; - $fs{reserve} = $fs{size} - $fs{used} - $fs{free}; - } # for - } # foreach + for (my $i = 0; $i < scalar @unixfs; $i++) { + my @fields = split ' ', $unixfs[$i]; + + $fs{mount} = $fields[0]; + $fs{size} = $fields[2] * 1024; + $fs{used} = $fields[3] * 1024; + $fs{free} = $fields[4] * 1024; + $fs{reserve} = $fs{size} - $fs{used} - $fs{free}; + } # for } elsif ($system{type} eq 'Linux' or $system{type} eq 'Windows') { my $cmd = "/bin/df --block-size=1 -P $filesystem{mount}"; @@ -165,7 +149,7 @@ sub snapshotFS ($$) { } # snapshotFS # Main -GetOptions ( +GetOptions( 'usage' => sub { Usage }, 'verbose' => sub { set_verbose }, 'debug' => sub { set_debug }, @@ -173,61 +157,80 @@ GetOptions ( 'fs=s' => \$fs, ) or Usage "Invalid parameter"; -Usage 'Extraneous options: ' . join ' ', @ARGV - if @ARGV; +Usage 'Extraneous options: ' . join ' ', @ARGV if @ARGV; # Announce ourselves verbose "$FindBin::Script V$VERSION"; my $exit = 0; -foreach my $system ($clearadm->FindSystem ($host)) { - next if $$system{active} eq 'false'; +for my $system ($clearadm->FindSystem ($host)) { + next if $system->{active} eq 'false'; - my $status = $clearexec->connectToServer ( - $$system{name}, - $$system{port} + my $status = $clearexec->connectToServer( + $system->{name}, + $system->{port} ); unless ($status) { - verbose "Unable to connect to system $$system{name}:$$system{port}"; + verbose "Unable to connect to system $system->{name}:$system->{port}"; next; } # unless - foreach my $filesystem ($clearadm->FindFilesystem ($$system{name}, $fs)) { - verbose "Snapshotting $$system{name}:$$filesystem{filesystem}"; + for my $filesystem ($clearadm->FindFilesystem ($system->{name}, $fs)) { + verbose "Snapshotting $system->{name}:$filesystem->{filesystem}"; - my %fs = snapshotFS ($system, $$filesystem{filesystem}); + my %fs = snapshotFS($system, $filesystem->{filesystem}); if (%fs) { - my ($err, $msg) = $clearadm->AddFS (%fs); + my ($err, $msg) = $clearadm->AddFS(%fs); error $msg, $err if $err; } # if + # Generate graphs + my $cmd = "plotfs.cgi generate=1 system=$system->{name} filesystem=$filesystem->{filesystem} scaling=Day points=7"; + + verbose "Generating fssmall for $system->{name}:$filesystem->{filesystem}"; + my ($error, @output) = Execute("$cmd tiny=1 2>&1"); + + error 'Unable to generate fssmall' . join("\n", @output), $error if $error; + + $filesystem->{fssmall} = join '', @output; + + verbose "Generating fslarge for $system->{name}:$filesystem->{filesystem}"; + ($error, @output) = Execute("$cmd 2>&1"); + + error 'Unable to generate fslarge' . join("\n", @output), $error if $error; + + $filesystem->{fslarge} = join '', @output; + + my ($err, $msg) = $clearadm->UpdateFilesystem($system->{name}, $filesystem->{filesystem}, %$filesystem); + + error "Unable to update filesystem record $msg", $err if $err; + # Check if over threshold - my %notification = $clearadm->GetNotification ('Filesystem'); + my %notification = $clearadm->GetNotification('Filesystem'); - next - unless %notification; + next unless %notification; - my $usedPct = sprintf ( - '%.2f', - (($fs{used} + $fs{reserve}) / $fs{size}) * 100 - ); + my $usedPct = '0%'; + + $usedPct = sprintf ('%.2f', (($fs{used} + $fs{reserve}) / $fs{size}) * 100) if $fs{size} != 0; - if ($usedPct >= $$filesystem{threshold}) { + if ($usedPct >= $filesystem->{threshold}) { $exit = 2; - display YMDHMS . " System: $$filesystem{system} " - . "Filesystem: $$filesystem{filesystem} Used: $usedPct% " - . "Threshold: $$filesystem{threshold}"; + display YMDHMS + . " System: $filesystem->{system} " + . "Filesystem: $filesystem->{filesystem} Used: $usedPct% " + . "Threshold: $filesystem->{threshold}"; } else { - $clearadm->ClearNotifications ($$system{name}, $$filesystem{filesystem}); + $clearadm->ClearNotifications ($system->{name}, $filesystem->{filesystem}); } # if - } # foreach + } # for $clearexec->disconnectFromServer; -} # foreach +} # for exit $exit; @@ -266,11 +269,11 @@ L =begin html
-Clearadm
-Clearexec
-DateUtils
-Display
-Utils
+Clearadm
+Clearexec
+DateUtils
+Display
+Utils
=end html