Changeset 3869a700db6ffc7c89dcad5a762def14e7877d7c

Show
Ignore:
Timestamp:
10/24/07 15:54:15 (7 years ago)
Author:
Sergey Ivanov <seriv@omniti.com>
git-committer:
Sergey Ivanov <seriv@omniti.com> 1193241255 +0000
git-parent:

[2f64690b2c2b2d649e332f3c98ec514702e4e1f4]

git-author:
Sergey Ivanov <seriv@omniti.com> 1193241255 +0000
Message:

two modules for checking filesize, local and remotes over ssh added

git-svn-id: https://labs.omniti.com/resmon/trunk@48 8c0face9-b7db-6ec6-c4b3-d5f7145c7d55

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • lib/Resmon/Module.pm

    ra7d2d7b r3869a70  
    163163} 
    164164 
     165package Resmon::Module::FILESIZE; 
     166use vars qw/@ISA/; 
     167@ISA = qw/Resmon::Module/; 
     168 
     169sub handler { 
     170  my $arg = shift; 
     171  my $os = $arg->fresh_status(); 
     172  return $os if $os; 
     173  my $file = $arg->{'object'}; 
     174  my @statinfo = stat($file); 
     175  my $size = $statinfo[7]; 
     176  my $minsize = $arg->{minimum}; 
     177  my $maxsize = $arg->{maximum}; 
     178  return $arg->set_status("BAD(too big, $size > $maxsize)") 
     179        if($maxsize && ($size > $maxsize)); 
     180  return $arg->set_status("BAD(too small, $size < $minsize)") 
     181        if($minsize && ($size > $minsize)); 
     182  return $arg->set_status("OK($size)"); 
     183} 
     184 
     185package Resmon::Module::REMOTEFILESIZE; 
     186use vars qw/@ISA/; 
     187use Resmon::ExtComm qw/cache_command/; 
     188@ISA = qw/Resmon::Module/; 
     189 
     190sub handler { 
     191  my $arg = shift; 
     192  my $os = $arg->fresh_status(); 
     193  return $os if $os; 
     194  my $host = $arg->{'host'}; 
     195  my $file = $arg->{'object'}; 
     196  my $output = cache_command("ssh -i /root/.ssh/id_dsa $host du -b $file", 600); 
     197  $output =~ /^(\d+)\s/;  
     198  my $size = $1; 
     199  my $minsize = $arg->{minimum}; 
     200  my $maxsize = $arg->{maximum}; 
     201  return $arg->set_status("BAD(too big, $size > $maxsize)") 
     202        if($maxsize && ($size > $maxsize)); 
     203  return $arg->set_status("BAD(too small, $size < $minsize)") 
     204        if($minsize && ($size > $minsize)); 
     205  return $arg->set_status("OK($size)"); 
     206} 
     207 
    165208package Resmon::Module::FILEAGE; 
    166209use vars qw/@ISA/; 
     
    174217  my @statinfo = stat($file); 
    175218  my $age = time() - $statinfo[9]; 
    176   return $arg->set_status("BAD(to old $age seconds)") 
     219  return $arg->set_status("BAD(too old $age seconds)") 
    177220        if($arg->{maximum} && ($age > $arg->{maximum})); 
    178   return $arg->set_status("BAD(to new $age seconds)") 
     221  return $arg->set_status("BAD(too new $age seconds)") 
    179222        if($arg->{minimum} && ($age > $arg->{minimum})); 
    180223  return $arg->set_status("OK($age)");