#!/usr/bin/perl

# ARGV[0] = Host Address
# ARGV[1] = Command to check on Remote

# Execute checl_nrpe with check command
$response = `/usr/local/nagios/libexec/check_nrpe -H $ARGV[0] -c $ARGV[1] -to 60`;

if ($ARGV[1] eq "check_load") {  

	} elsif ($ARGV[1] eq "check_dasdb1") {  # We're checking space on dasdb1 or root
	$value = substr($response, -16, 2);
	chomp $value;
	} else {  # Else we must be checking processes
        $value = substr($response, 5, 3);
	# The following line removes the letter p in case it is left over after the substr
	$value =~ tr/p//d;
        chomp $value;
	}

# Enter the data in the rrd

$rrdentry = "/usr/bin/rrdtool update /usr/local/nagios/rrd/linux/$ARGV[0].rrd -t $ARGV[1] N:$value";
system $rrdentry;
#print $rrdentry;

# Set the exit code based on whether it is critical or not.
if ($response) {  
	print $response;
        exit 0;
} else {
	print $response;
        exit 2;
}


