#!/usr/bin/perl

# get the arguments from command line
$snmpwalk="/usr/bin/snmpwalk";
$snmpget="/usr/bin/snmpget";
($host, $community) = @ARGV;

sub main() {
	# Define the array following the MIB specification:
	@statesName = ( "Unknown" , "Ready"     , "Failed", 
			"Online"  , "   "       , "Offline",
			"Degraded", "Recovering"         
		      );
	$statesName[11] = "Removed";
	$statesName[15] = "Resynching";
	$statesName[24] = "Rebuild";
	$statesName[25] = "No Media";
	$statesName[26] = "Formatting";
	$statesName[28] = "Diagnostics";
	$statesName[35] = "Initializing";


        `$snmpget -v1 -c $community $host .1.3.6.1.2.1.1.1.0 >/dev/null 2>&1`;
        if( $? != 0 ) {
                print "CRITICAL - SNMP nao habilitado\n";
                exit(2);
        }
  #	`$snmpget -v1 -c $community $host .1.3.6.1.4.1.674.10893.1.20.3.0 >/dev/null 2>&1`;
  #      if( $? != 0 ) {
  #              print "CRITICAL - Impossivel encontrar OIDs OpenManager\n";
  #              exit(2);
  #      }
		
	
	# puplate the temp array with disk status
	@temp = `$snmpwalk -v1 -c $community $host .1.3.6.1.4.1.674.10893.1.20.130.4.1.4`;
	push( @temp, `$snmpwalk -v1 -c $community $host .1.3.6.1.4.1.674.10893.1.1.130.4.1.4`);

	# lets parse the result
	foreach( @temp ) {
	        # SNMPv2-SMI::enterprises.674.10893.1.1.130.4.1.4.1 = INTEGER: 3 
		push( @arrayDiskState, $1 ) if( m/^.*INTEGER: (\d*)$/); 
	}

	$critical = 0;
	$i=0;	
	foreach $state (@arrayDiskState) {
		if($state != 3 && $state != 1) {
			$critical = 1;
		}
		$i++
	}

	$i=0;
	print "Status dos Discos -> ";
	foreach $state (@arrayDiskState) {
		print " Disk$i = $statesName[$state]   ";
		$i++;
	}
	print "\n";	

	if($critical == 1) {
		return 2;	
	}else{
		return 0;
	}


}

sub died() {
        print "Impossivel conectar ao servidor remoto\n";
        exit(2);
}

exit(&main());
