eval 'exec perl -x $0 ${1+"$@"}' # -*-perl-*-
  if 0;
#!perl -w
#
# ======================================================================
# This file is Copyright 1998,1999 by the Purdue Research Foundation and
# may only be used under license.  For terms of the license, see the
# file named COPYRIGHT included with this software release.
# AAFID is a trademark of the Purdue Research Foundation.
# All rights reserved.
# ======================================================================
#
# AAFID2 system
# Agent name:        DiskSpace
# Agent description: Monitor file system usage
# Author:            Diego Zamboni
#
# History of modifications:
# 
# Known bugs:
# 
# Things to do:
# 
# Future work:
# 
# Suggestions made by people:
# 
# Generated automatically by ../bin/makeagent.pl on Tue Sep  7 23:55:48 1999.
# 
###### AUTOMATICALLY GENERATED FILE --- DO NOT EDIT ##########
#

# 10 "DiskSpace.aas"
package DiskSpace;

# Version number
# 13 "DiskSpace.aas"
$VERSION=eval {0.1}; $VERSION=$VERSION;

# Agent parameters
%PARAMETERS=(
             Description        => "Monitor file system usage",
             CheckPeriod        => eval {undef},
# 22 "DiskSpace.aas"
             Status => 0,
             Message => 'FS: ',
# 19 "DiskSpace.aas"
             FiltersNeeded => { 	FileSystems => [ {}, 'Check' ] }
            );

# Package loading
use AAFID::Agent;
use AAFID::Log;
use AAFID::Common;


use vars qw (
             @ISA
             $VERSION
             %PARAMETERS
            );

# Define the superclass.
 @ISA=qw(AAFID::Agent);

=head1 DiskSpace

	Here goes the long description of how
	the agent works.

=cut

# Preamble code
# 49 "DiskSpace.aas"

sub sendFStoFilter {
  my $self=shift;
  my $thr=$self->getParameter('MyFS', {});
  $self->setFilterPattern(
    'FileSystems',
    { MountPoint => 
	       join('|', map { "^$_\$" }
			     keys %$thr ) }
    );
}

# The Check function.
sub Check {
  my $self=checkref(shift);
# 26 "DiskSpace.aas"
  my ($filter, $fh, $line)=@_;
  my ($pct, $fs)=(split(" ", $line))[4,5];
  my $thr=$Params{MyFS};
  my $status=$Params{Status}||0;
  my $badFS=$self->getParameter('MyBadFS', {});
  if (exists($thr->{$fs})) {
    if ($pct > $thr->{$fs}) {
      $badFS->{$fs}="$fs($pct)";
      $status++ unless $status==10;
    }
    else {
      delete $badFS->{$fs};
      $status-- unless $status==0;
    }
  }
  return ($status, "FS: ".join(", ", values %$badFS));
}
# Agent commands

sub command_ADD_FS {
  my $self=checkref(shift);
  my ($message, %p)=@_;
  if (exists($p{FS}) && exists($p{Limit}) && 1) {
    my $FS = $p{FS};
my $Limit = $p{Limit};
# 44 "DiskSpace.aas"
  my $thr=$self->getParameter('MyFS', {});
  $thr->{$FS}=$Limit;
  $self->sendFStoFilter();
    # By default, return undef
    return undef;
  }
}

sub command_LIST_FS {
  my $self=checkref(shift);
  my ($message, %p)=@_;
  if (1) {
    
# 69 "DiskSpace.aas"
  my $thr=$self->getParameter('MyFS', {});
  return { FileSystems =>
           join(",",
	     map {"$_ (".$thr->{$_}.")"}
		 keys(%$thr))};
    # By default, return undef
    return undef;
  }
}

sub command_DEL_FS {
  my $self=checkref(shift);
  my ($message, %p)=@_;
  if (exists($p{FS}) && 1) {
    my $FS = $p{FS};
# 62 "DiskSpace.aas"
  my $thr=$self->getParameter('MyFS', {});
  my $bFS=$self->getParameter('MyBadFS', {});
  delete $thr->{$FS} if exists $thr->{$FS};
  delete $bFS->{$FS} if exists $bFS->{$FS};
  $self->sendFStoFilter();
    # By default, return undef
    return undef;
  }
}

# End of entity marker
_EndOfEntity;
