File check_snmp_brocade_health of Package nagios-plugins-snmp
1
#!/usr/bin/php
2
<?php
3
// Author: Carsten Schoene
4
// $LastChangedDate: 2015-02-02 07:59:29 +0100 (Mo, 02. Feb 2015) $
5
// Rev: $Rev: 9778 $
6
// required arguments
7
// $1 = Host / IP
8
// $2 = read community string
9
10
//$grad = iconv("UTF-8","ISO-8859-15","°");
11
$grad = "°";
12
define('MYNAME',"check_snmp_brocade_health");
13
define('OK',0);
14
define('WARNING',1);
15
define('CRITICAL',2);
16
define('UNKNOWN',3);
17
define('DEPENDENT',4);
18
19
openlog(MYNAME,LOG_PID | LOG_ODELAY,LOG_MAIL);
20
21
if ( ! extension_loaded("snmp") ) {
22
syslog(LOG_ERR,"snmp extension not loaded!");
23
exit;
24
}
25
26
ini_set("display_errors","on");
27
// get working directory
28
define('BASE',dirname(__FILE__));
29
30
$cmdlineopt = getopt("H:C:");
31
if (empty($cmdlineopt)) {
32
echo "Usage: " . MYNAME . " -H [<hostname> | <ipaddress>] -C [<community>]\n";
33
echo "\t -H\t Hostname or IP address (default: localhost)\n";
34
echo "\t -C\t Community (default: public)\n";
35
exit(1);
36
}
37
if ( isset($cmdlineopt['H']) ) {
38
$hostname = $cmdlineopt['H'];
39
} else {
40
$hostname = "localhost";
41
}
42
43
if ( isset($cmdlineopt['C']) ) {
44
$community = $cmdlineopt['C'];
45
} else {
46
$community = "public";
47
}
48
49
50
// get product type -> .1.3.6.1.4.1.1991.1.1.1.1.26.0
51
/*
52
0 - invalid
53
1 - mg8
54
2 - ni40G
55
3 - imr
56
4 - biRx800
57
5 - niXmr16000
58
6 - biRx400
59
7 - niXmr8000
60
8 - biRx200
61
9 - niXmr4000
62
10 - niMlx16
63
11 - niMlx8
64
12 - niMlx4
65
13 - niMlx32
66
14 - niXmr32000
67
15 - biRx32
68
16 - niCES2000Series
69
17 - niCER2000Series
70
18 - brMlxE4
71
19 - brMlxE8
72
20 - brMlxE16
73
21 - brMlxE32
74
50 - biNI2
75
66 - biBB
76
77 - biM4
77
78 - biNI
78
83 - biSLB
79
87 - biWG
80
*/
81
$prod = @snmpget($hostname,$community,".1.3.6.1.4.1.1991.1.1.1.1.26.0");
82
if (empty($prod) ) {
83
print "No brocade device found\n";
84
exit(UNKNOWN);
85
} else {
86
$prodarr = explode(": ",$prod);
87
$product_id = $prodarr[1];
88
}
89
switch ($product_id) {
90
case "18":
91
// temperature
92
$chassis = "";
93
$chassistemp = $chassis . "";
94
$chassiswarntemp = $chassis . "";
95
$chassisshutdowntemp = $chassis . "";
96
$chassistempfactor = "0.5";
97
98
// power supply
99
$psu = ".1.3.6.1.4.1.1991.1.1.1.2.1.1";
100
$psuidx = $psu . ".1";
101
$psudscr = $psu . ".2";
102
$psustat = $psu . ".3";
103
$psustates = array(1 => "other", 2 => "normal", 3 => "failure");
104
105
// fans
106
$fan = ".1.3.6.1.4.1.1991.1.1.1.3.1.1";
107
$fanidx = $fan . ".1";
108
$fandscr = $fan . ".2";
109
$fanstat = $fan . ".3";
110
$fanstates = array(1 => "other", 2 => "normal", 3 => "failure");
111
break;
112
case "66":
113
// temperature
114
$chassis = ".1.3.6.1.4.1.1991.1.1.1.1";
115
$chassistemp = $chassis . ".18";
116
$chassiswarntemp = $chassis . ".19";
117
$chassisshutdowntemp = $chassis . ".20";
118
$chassistempfactor = "0.5";
119
120
// power supply
121
$psu = ".1.3.6.1.4.1.1991.1.1.1.2.1.1";
122
$psuidx = $psu . ".1";
123
$psudscr = $psu . ".2";
124
$psustat = $psu . ".3";
125
$psustates = array(1 => "other", 2 => "normal", 3 => "failure");
126
127
// fans
128
$fan = ".1.3.6.1.4.1.1991.1.1.1.3.1.1";
129
$fanidx = $fan . ".1";
130
$fandscr = $fan . ".2";
131
$fanstat = $fan . ".3";
132
$fanstates = array(1 => "other", 2 => "normal", 3 => "failure");
133
break;
134
default:
135
exit();
136
}
137
138
139
// check temperature
140
if ( !empty($chassistemp) ) {
141
$curtemp = @snmpget($hostname,$community,$chassistemp.".0");
142
}
143
$output = $tempoutput = $fanoutput = $psuoutput = $tempstate = $psustate = $fanstate = "";
144
145
if (!empty($curtemp)) {
146
$curtemparr = explode(": ",$curtemp);
147
$curtemp = $curtemparr[1];
148
$warntemp = @snmpget($hostname,$community,$chassiswarntemp.".0");
149
$warntemparr = explode(": ",$warntemp);
150
$warntemp = $warntemparr[1];
151
$shuttemp = @snmpget($hostname,$community,$chassisshutdowntemp.".0");
152
$shuttemparr = explode(": ",$shuttemp);
153
$shuttemp = $shuttemparr[1];
154
if ( is_numeric($chassistempfactor) ) {
155
$curtemp = $curtemp * $chassistempfactor;
156
$warntemp = $warntemp * $chassistempfactor;
157
$shuttemp = $shuttemp * $chassistempfactor;
158
}
159
$crittemp = $shuttemp - 2;
160
$lowcrittemp = $shuttemp - 10;
161
if ( $curtemp < $crittemp && $curtemp > $lowcrittemp && $curtemp > $warntemp ) {
162
$tempstate = CRITICAL;
163
$tempoutput = "Chassis Temperature " . $curtemp . $grad."C is near shutdown level (".$shuttemp.$grad."C / ".$crittemp.$grad."C)";
164
}elseif ( $curtemp <= $lowcrittemp && $curtemp > $warntemp ) {
165
$tempstate = WARNING;
166
$tempoutput = "Chassis Temperature " . $curtemp . $grad. "C has reached warnging level (".$warntemp.$grad."C)";
167
}elseif ( $curtemp <= $warntemp ) {
168
$tempstate = OK;
169
$tempoutput = "Chassis Temperature " . $curtemp . $grad. "C is normal";
170
} else {
171
$tempstate = UNKNOWN;
172
$tempoutput = "Chassis Temperature is unknown";
173
}
174
} else {
175
$tempstate = OK;
176
$tempoutput = "No temprature sensor found";
177
}
178
179
180
// check power supply
181
if ( !empty($psuidx) ) {
182
$psusensorCount = count(@snmpwalk($hostname,$community,$psuidx));
183
} else {
184
$psusensorCount = 0;
185
$psustate = OK;
186
$psuoutput = "";
187
}
188
if ( $psusensorCount > 0 ) {
189
foreach ( snmpwalk($hostname,$community,$psuidx) as $psusensor ) {
190
$psusensorarr = explode(": ",$psusensor);
191
$a = $psusensorarr[1];
192
$psuNameline = @snmpget($hostname,$community,$psudscr . ".". $a);
193
$psuNameArr = explode("\"", $psuNameline);
194
$psuStateline = @snmpget($hostname,$community,$psustat . ".". $a);
195
$psuStatArr = explode(": ",$psuStateline);
196
$psustatus = $psustates[$psuStatArr[1]];
197
if ( $a == 1 ) {
198
$psuoutput = "PSU${a} => $psustatus";
199
} else {
200
$psuoutput .= ", PSU${a} => $psustatus";
201
}
202
}
203
if ( preg_match('/failure/i',$psuoutput) ) {
204
$psustate = CRITICAL;
205
} elseif( preg_match('/other/i', $psuoutput) ) {
206
$psustate = WARNING;
207
} elseif( preg_match('/normal/i', $psuoutput) ) {
208
$psustate = OK;
209
} else {
210
$psustate = UNKNOWN;
211
}
212
}
213
214
// check fans
215
if ( !empty($fanidx) ) {
216
$fansensorCount = count(@snmpwalk($hostname,$community,$fanidx));
217
} else {
218
$fansensorCount = 0;
219
$fanstate = OK;
220
$fanoutput = "";
221
}
222
if ( $fansensorCount > 0 ) {
223
foreach ( @snmpwalk($hostname,$community,$fanidx) as $fansensor ) {
224
$fansensorarr = explode(": ",$fansensor);
225
$a = $fansensorarr[1];
226
$fanNameline = @snmpget($hostname,$community,$fandscr . ".".$a);
227
$fanNameArr = explode("\"", $fanNameline);
228
$fanStateline = @snmpget($hostname,$community,$fanstat . ".".$a);
229
$fanStatArr = explode(": ",$fanStateline);
230
$fanstatus = $fanstates[$fanStatArr[1]];
231
if ( $a == 1 ) {
232
$fanoutput = "FAN${a} => $fanstatus";
233
} else {
234
$fanoutput .= ", FAN${a} => $fanstatus";
235
}
236
}
237
if ( preg_match('/failure/i',$fanoutput) ) {
238
$fanstate = CRITICAL;
239
} elseif( preg_match('/other/i', $fanoutput) ) {
240
$fanstate = WARNING;
241
} elseif( preg_match('/normal/i', $fanoutput) ) {
242
$fanstate = OK;
243
} else {
244
$fanstate = UNKNOWN;
245
}
246
}
247
248
$output = $tempoutput . ", " . $psuoutput . ", " . $fanoutput;
249
print $output . "\n";
250
if ( $tempstate == CRITICAL || $psustate == CRITICAL || $fanstate == CRITICAL ) {
251
exit(CRITICAL);
252
} elseif ( $tempstate == WARNING || $psustate == WARNING || $fanstate == WARNING ) {
253
exit(WARNING);
254
} elseif ( $tempstate == UNKNOWN || $psustate == UNKNOWN || $fanstate == UNKNOWN ) {
255
exit(UNKNOWN);
256
} else {
257
exit(OK);
258
}
259