#!/usr/bin/perl
# Modified : 15/11/2007
# Matthieu Jouzel / Emmanuel Berre
# -----------------------------------------
# Author : jakubowski Benjamin
# Date : 19/12/2005
# check_win_snmp_disk.pl SERVEUR COMMUNITY

$STATE_CRITICAL = 2;

$STATE_OK = 0;

$STATE_WARNING = 1; 

$SERVER=@ARGV[0];			# Example: 10.0.0.3
$SNMPCOMUNITY=@ARGV[1];		# Example: $SNMPCOMUNITY
$LDISK=@ARGV[2];		# A,C,D,E,F,....Logical disk => like 1,2,3 .....
$WARN=@ARGV[3];			# Example: "80"
$CRITIK=@ARGV[4];		# Example: "90"


# Used Space
$USED=`/usr/local/bin/snmpget -v 1 -c $SNMPCOMUNITY $SERVER .iso.org.dod.internet.mgmt.mib-2.host.hrStorage.hrStorageTable.hrStorageEntry.hrStorageUsed.$LDISK | awk '{ print \$4 }'`;
$USED =~ s/\n//g;

# Size of disk
$SIZE=`/usr/local/bin/snmpget -v 1 -c $SNMPCOMUNITY $SERVER .iso.org.dod.internet.mgmt.mib-2.host.hrStorage.hrStorageTable.hrStorageEntry.hrStorageSize.$LDISK | awk '{ print  \$4  }'`;
$SIZE =~ s/\n//g;

# GET BYTE VALUE FOR DISK SYSTEM (512;1024;2048;4096)
$VALUE=`/usr/local/bin/snmpget -v 1 -c $SNMPCOMUNITY $SERVER .iso.org.dod.internet.mgmt.mib-2.host.hrStorage.hrStorageTable.hrStorageEntry.hrStorageAllocationUnits.$LDISK | awk '{ print \$4 }'`;

$VALUE =~ s/\n//g;

# Espace Libre
$C=$SIZE-$USED;

$LIBRE = int($C * $VALUE / 1024 / 1024) ;
$USEDMo = int($USED * $VALUE / 1024 / 1024) ;
$POUR=int($USED/$SIZE * 100);

if ( $POUR < $WARN )
{
	print "OK : Percent : $POUR% Used : $USEDMo Mo Free : $LIBRE Mo\n";
	exit $STATE_OK;
}
elsif ( $POUR < $CRITIK )
{
	print "WARNING : Percent : $POUR% Used : $USEDMo Mo Free : $LIBRE Mo\n";
	exit $STATE_WARNING;
}
else
{
	print "CRITICAL : Percent : $POUR% Used : $USEDMo Mo Free : $LIBRE Mo\n";
	exit $STATE_CRITICAL;
}


