X-Git-Url: https://defaria.com/gitweb/?a=blobdiff_plain;f=clearadm%2Fupdatefs.pl;h=6308e35bcd2f6e2cdb4fb1ec0e858d517050d8bd;hb=7ddf095f187ca60d9a70fb83b2bc3c2b6d91f088;hp=86df94ccf02344cc6bccc85c2a27cf0566a95732;hpb=0c802537ec02d6cfea4c41b3138535c09a319489;p=clearscm.git diff --git a/clearadm/updatefs.pl b/clearadm/updatefs.pl index 86df94c..6308e35 100755 --- a/clearadm/updatefs.pl +++ b/clearadm/updatefs.pl @@ -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 = ( @@ -100,8 +101,8 @@ sub snapshotFS ($$) { if ($status != 0) { error ('Unable to determine fsinfo for ' - . "$system{name}:$filesystem{mount} ($cmd)\n" . - join "\n", @unixfs); + . "$system{name}:$filesystem{mount} ($cmd)\n" + . join "\n", @unixfs); return; } # if @@ -148,7 +149,7 @@ sub snapshotFS ($$) { } # snapshotFS # Main -GetOptions ( +GetOptions( 'usage' => sub { Usage }, 'verbose' => sub { set_verbose }, 'debug' => sub { set_debug }, @@ -156,8 +157,7 @@ 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"; @@ -165,47 +165,67 @@ verbose "$FindBin::Script V$VERSION"; my $exit = 0; for my $system ($clearadm->FindSystem ($host)) { - next if $$system{active} eq 'false'; + 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 - for 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 = '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}"; + . " 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 } # for