package Resmon::Module::REMOTEFILESIZE;
use vars qw/@ISA/;
use Resmon::ExtComm qw/cache_command/;
@ISA = qw/Resmon::Module/;

sub handler {
  my $arg = shift;
  my $host;
  my $object;
  if ($arg->{'object'} =~ ';') {
    # Specify the host in hostname:/path/to/file format, this method allows
    # you to monitor the same file on multiple hosts
    ($host, $file) = split /;/,$arg->{'object'},2;
  } else {
    # Specify host as a paramater. This method doesn't allow you to monitor
    # the same file on multiple hosts
    $host = $arg->{'host'};
    $file = $arg->{'object'};
  }
  my $output = cache_command("ssh -i /root/.ssh/id_dsa $host du -k $file", 600);
  $output =~ /^(\d+)\s/; 
  my $size = $1 * 1024;
  my $minsize = $arg->{minimum};
  my $maxsize = $arg->{maximum};
  return "BAD($size, too big)"
        if($maxsize && ($size > $maxsize));
  return "BAD($size, too small)"
        if($minsize && ($size > $minsize));
  return "OK($size)";
}
1;

package Resmon::Module::REMOTEFILESIZE;
use vars qw/@ISA/;
use Resmon::ExtComm qw/cache_command/;
@ISA = qw/Resmon::Module/;

sub handler {
  my $arg = shift;
  my $host;
  my $file;
  # Specify the host in hostname/path/to/file format, this method allows
  # you to monitor the same file on multiple hosts
  ($host, $file) = $arg->{'object'} =~ /^([^\/]+)?(\/.*)$/;
  # Specify host as a paramater. This method doesn't allow you to monitor
  # the same file on multiple hosts
  $host ||= $arg->{'host'};
  my $output = cache_command("ssh -i /root/.ssh/id_dsa $host du -k $file", 600);
  $output =~ /^(\d+)\s/; 
  my $size = $1 * 1024;
  my $minsize = $arg->{minimum};
  my $maxsize = $arg->{maximum};
  return "BAD($size, too big)"
        if($maxsize && ($size > $maxsize));
  return "BAD($size, too small)"
        if($minsize && ($size > $minsize));
  return "OK($size)";
}
1;

Change the method of specifying a host to hostname/path/to/file
Change the method of specifying a host to hostname/path/to/file

git-svn-id: f288825eac1cbbbc51b99d82d097385cba0e17f8@218 8c0face9-b7db-6ec6-c4b3-d5f7145c7d55
