#!/usr/bin/perl

use strict;

my $community="public";
my @error;
my @warning;
my $count;

open(SNMP, "snmpwalk -m ALL -v1 -c $community localhost .1.3.6.1.4.1.3582.1.1.3.1.4|");
while(my $snmp = <SNMP>){
        $count++;
        chomp $snmp;
        $snmp =~ m/RAID-Adapter-MIB::state.(\d*)\.(\d*)\.(\d*) = INTEGER: (.*)\(\d*\)/;
        my $adapter = $1;
        my $channel = $2;
        my $lun = $3;
        my $state = $4;

        if ($state eq 'failed'){
                push @error, "drive $adapter,$channel,$lun is $state";
        }
        elsif ($state eq 'rebuild'){
                push @warning, "drive $adapter,$channel,$lun is $state";
        }
}
close(SNMP);

if (@error){
        print "CRITICAL: " . join(", ", @error, @warning) . "\n";
}
elsif (@warning){
        print "WARNING: " . join(", ", @warning) . "\n";
}
elsif ($count < 5){
        print "CRITICAL: no response from percsnmpd\n";
}
else{
        print "OK: all disks online\n";
}
