#!/usr/bin/php
<?php
// some brocade chassis checks by righter
// v1.0 26.11.2012 initial release
// blog.righter.ch

// set your community and temperature warning threshold and snmpwalk binary location
$comu="your-community";
$tempcrit=75;
$snmpbin="/usr/bin/snmpwalk";

$crit=NULL;
$warn=NULL;
$ok=NULL;

// get power supply infos
$out=array();
exec("$snmpbin -m ALL -Oqv -c $comu -v2c $argv[1] snChasPwrSupplyOperStatus", $out);
for ($i=0; $i<sizeof($out); $i++)
{
	$t=$i+1;
	if ($out[$i] == "normal")
	{
		$ok.="Power Suppply $t normal operation\n";
	}
	else
	{
		$crit.="Power Supply $t error\n";
	}
}


// get fan information
$out=array();
exec("$snmpbin -m ALL -Oqv -c $comu -v2c $argv[1] snChasFanOperStatus", $out);
for ($i=0; $i<sizeof($out); $i++)
{
        $t=$i+1;
        if ($out[$i] == "normal")
        {
                $ok.="Fan $t normal operation\n";
        }
        else
        {
                $crit.="Fan Supply $t error\n";
        }
}

// get temperature information
$outdesc=array();
$out=array();
exec("$snmpbin -m ALL -Oqv -c $comu -v2c $argv[1] snAgentTempValue", $out);
exec("$snmpbin -m ALL -Oqv -c $comu -v2c $argv[1] snAgentTempSensorDescr", $outdesc);
for ($i=0; $i<sizeof($out); $i++)
{
	$out[$i]=$out[$i]/2;
        if ($out[$i] < $tempcrit)
        {
                $ok.="$out[$i]C on $outdesc[$i]\n";
        }
        else
        {
                $crit.="$out[$i]C on $outdesc[$i]\n";
        }
}

if ($crit)
{
	echo $crit;
	exit(2);
}
if ($ok)
{
	echo "$ok";
	exit(0);
}
?>

