# needs $storage_descr: plaintext description, $storage_type: type of storage, $storage_id: resource id, $provider: resource type

{
    my $host = $args{"host"};
    my $id = $storage_id;

    print "  _storage: $host, $storage_descr, $storage_type, $id, $provider\n" if( $BigSister::common::dl>4 );
    $args{"_eval"} = "storage";
    do "_evaluator";

    my $limits = { "physmem" => [ "97%", "99%" ],
		    "pagemem" => [ "90%", "98%" ],
		    "disk" => [ "95%", "99%" ] }
		 -> {$storage_type};
    if( $args{"limits"} =~ /^(|.*,)$storage_descr\(([0-9\%\-]*)\)/ ) {
	my @limits = split( /[-,]/, $1 );
	$limits = \@limits;
    }
    print "    limits: ".$limits->[0]." ".$limits->[1]."\n" if( $BigSister::common::dl>6 && $limits );
    if( $limits && (defined $limits->[0] || defined $limits->[1]) ) {
	print "    adding check for $storage_descr ...\n" if( $BigSister::common::dl>3 );
	$args{"_check"} = 1;
	$args{"_evaluator"}->add_check( $storage_type=~/mem/?"cpu":"disk", sub {
	    my( $vars ) = @_;

	    my( $units, $used, $size, $descr ) = (
		$vars->{"$provider.hrStorageAllocationUnits.$id"},
		$vars->{"$provider.hrStorageUsed.$id"},
		$vars->{"$provider.hrStorageSize.$id"},
		$vars->{"$provider.hrStorageDescr.$id"}
		);
	    print "used: $used, size: $size, descr: $descr\n";

            # Enter the following block if and only if it is novell.
            if ($type =~ /:novell:/){
               my( @NovellID )  = $snmp->walk( "nwVolID" );

               # The following block is intended to be activated for disk.
               # the "return" exit will occur inside the block only for Novell disks.

               foreach $idNovell (@NovellID) {
                  $idNovell =~ s/.*://;
                  my( $NovellDescr) = (($snmp->get( "nwVolPhysicalName.$idNovell" ))[0]);

                  # Search the correct index matching for both snmp OID's. 
                  if ($descr =~ $NovellDescr){
                      my ($NovellFreeable) = (($snmp->get( "nwVolFreeable.$idNovell" ))[0]);
                      my ($NovellFree) = (($snmp->get( "nwVolFree.$idNovell" ))[0]);
                      my ($NovellBlock) = (($snmp->get( "nwVolBlockSize.$idNovell" ))[0]);
                      my ($NovellSize) = (($snmp->get( "nwVolSize.$idNovell" ))[0]);
                      $size = $NovellSize;
	              $used = $NovellSize-$NovellFree-$NovellFreeable;
	              $usage = int( 100*($used)/$size );
	              my $free = $size-$used;
	              my $text = $descr.": used ${used}k ($usage%) of ${size}k ";
	              my $status = 3;
	              my $limit1 = $limits->[1];
	              my $limit = $limits->[0];
	              if( (defined $limit1) 
         	       	  && ( (($limit1 =~ /^(.*)%/) && ($usage>=$limit1))) ) {
         		  $status = 0;
         		  $text .= " (full)";
	              }
	              elsif( (defined $limit) 
		         && ( (($limit =~ /^(.*)%/) && ($usage>=$limit))) ) {
	         	  $status = 1;
	         	  $text .= " (getting full)";
	              };
	              return( $status, $text );
                  }
               }

            } 


            # For every thing else (excluding the Novell disks, the code is the original
 
	    $used = int($used*$units/1024);
	    $size = int($size*$units/1024);
	    my $free = $size-$used;
	    if( $size ) {
	      $usage = int( 100*$used/$size );
	    }

	    my $text = $descr.": used ${used}k ($usage%) of ${size}k";
	    my $status = 3;
	    my $limit1 = $limits->[1];
	    my $limit = $limits->[0];
	    if( (defined $limit1) 
                  & ( (($limit1 =~ /^(.*)%/) && ($usage>=$limit1))
         	    || ($free<=$limit1) ) ) {
         	$status = 0;
         	$text .= " (full)";
	    }
	    elsif( (defined $limit) 
		&& ( (($limit =~ /^(.*)%/) && ($usage>=$limit))
	        	    || ($free<=$limit) ) ) {
	       	$status = 1;
	       	$text .= " (getting full)";
	    };

	     return( $status, $text );
	} );
    }
}

1;
