Search
j0ke.net Open Build Service
>
Projects
>
server:monitoring
:
icinga
:
production
>
nagios-plugins-snmp
> check_snmp_brocade200E
Sign Up
|
Log In
Username
Password
Cancel
Overview
Repositories
Revisions
Requests
Users
Advanced
Attributes
Meta
File check_snmp_brocade200E of Package nagios-plugins-snmp
#!/usr/bin/php5 <?php /* ** Author ** Original author Carsten Schoene (cs@linux-administrator.com) ** ** Copyright ** Copyright (c) 2008 linux-administrator.com ** All Rights Reserved. */ // Last change: 2009-07-14 (SW4424 support) // required arguments // $1 = Host / IP // $2 = read community string $switchType = "SNMPv2-SMI::mib-2.47.1.1.1.1.2.1"; $grad = iconv("UTF-8","ISO-8859-15","°"); define('MYNAME',"check_snmp_brocade200E"); define('OK',0); define('WARNING',1); define('CRITICAL',2); define('UNKNOWN',3); define('DEPENDENT',4); openlog(MYNAME,LOG_PID | LOG_ODELAY,LOG_MAIL); if ( ! extension_loaded("snmp") ) { if ( ! dl("snmp") ) { syslog(LOG_ERR,"snmp extension not loaded!"); exit; } } ini_set("display_errors","on"); // get working directory define('BASE',dirname(__FILE__)); $cmdlineopt = getopt("H:C:"); if (empty($cmdlineopt)) { echo "Usage: " . MYNAME . " -H [<hostname> | <ipaddress>] -C [<community>]\n"; echo "\t -H\t Hostname or IP address (default: localhost)\n"; echo "\t -C\t Community (default: public)\n"; exit(1); } if ( isset($cmdlineopt['H']) ) { $hostname = $cmdlineopt['H']; } else { $hostname = "localhost"; } if ( isset($cmdlineopt['C']) ) { $community = $cmdlineopt['C']; } else { $community = "public"; } $swTypeline = @snmpget($hostname,$community,$switchType); if ( $swTypeline == FALSE ) { echo "Can't get switchtype\n"; exit(UNKNOWN); } else { $swTypearr = explode(": ",$swTypeline); $swType = $swTypearr[1]; } switch ($swType) { case "\"SilkWorm200E\"": case "\"SW4424\"": case "\"Brocade300\"": $sensorIDX = ".1.3.6.1.3.94.1.8.1.2"; $sensorName = ".1.3.6.1.3.94.1.8.1.3"; $sensorStatus = ".1.3.6.1.3.94.1.8.1.4"; $sensorInfo = ".1.3.6.1.3.94.1.8.1.5"; $sensorMsg = ".1.3.6.1.3.94.1.8.1.6"; $oid_add = ".16.0.0.5.30.10.38.186.0.0.0.0.0.0.0.0."; define(1,'STATUS_UNKOWN'); define(2,'STATUS_OTHER'); define(3,'STATUS_OK'); define(4,'STATUS_WARN'); define(5,'STATUS_FAIL'); $sensorCount = count(@snmpwalk($hostname,$community,$sensorIDX)); if ($sensorCount > 0 ) { for ( $a = 1 ; $a <= $sensorCount ; $a++ ) { $sNameline = @snmpget($hostname,$community,$sensorName . $oid_add . $a); $sNamearr = explode("\"",$sNameline); $sName = $sNamearr[1]; $sStatusline = @snmpget($hostname,$community,$sensorStatus . $oid_add . $a); $sStatusarr = explode(": ",$sStatusline); $sStatus = $sStatusarr[1]; $sMsgline = @snmpget($hostname,$community,$sensorMsg . $oid_add . $a); $sMsglinearr0 = explode("\"",$sMsgline); $sMsglinearr1 = explode(" ",$sMsglinearr0[1]); $sMsgVal = $sMsglinearr1[9]; if ( $a == 1 ) { $output = "$sName => $sMsgVal (" . constant($sStatus) . ")"; } else { $output .= " , $sName => $sMsgVal (" . constant($sStatus) . ")"; } } print $output . "\n"; if ( preg_match('/STATUS_FAIL/',$output) ) { exit(CRITICAL); } if ( preg_match('/STATUS_WARN/',$output) ) { exit(WARNGING); } if ( preg_match('/STATUS_UNKOWN/',$output) ) { exit(UNKNOWN); } if ( preg_match('/STATUS_OTHER/',$output) ) { exit(UNKNOWN); } if ( preg_match('/STATUS_OK/',$output) ) { exit(OK); } } break; default: echo "Switchtype $swType is currently not supported"; } ?>