-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcheck_p2000_api.php
More file actions
757 lines (645 loc) · 25.2 KB
/
check_p2000_api.php
File metadata and controls
757 lines (645 loc) · 25.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
#!/usr/bin/php
<?php
/*Nagios Exit codes
0 = OK
1 = WARNING
2 = CRITICAL
3 = UNKNOWN
perfdata output rta=35.657001ms;1000.000000;3000.000000;0.000000 pl=0%;80;100;0
*/
//Set provided variables
$arguements = getopt("H:U:P:s:c:S:u:w:C:t:n:");
$secure = isset($arguements['s']) ? $arguements['s'] : 0;
$command = isset($arguements['c']) ? $arguements['c'] : "status";
$stat = isset($arguements['S']) ? $arguements['S'] : "iops";
$uom = isset($arguements['u']) ? $arguements['u'] : "";
$warnType = isset($arguements['t']) ? $arguements['t'] : "greaterthan";
$volumeName = isset($arguements['n']) ? $arguements['n'] : "";
if(isset($arguements['w']) || isset($arguements['C'])) {
if(!isset($arguements['w']) || !isset($arguements['C'])) {
echo "Specify warning/critical threshold \n\r";
Usage();
exit(3);
}
else {
$warning = $arguements['w'];
$critical = $arguements['C'];
}
}
//Validate Provided arguements
if(!isset($arguements['H']) || !isset($arguements['U']) || !isset($arguements['P'])) {
Usage();
exit(3);
}
elseif(($command == 'named-volume') && (empty($volumeName))) {
Usage();
exit(3);
}
elseif(($command == 'named-vdisk') && (empty($volumeName))) {
Usage();
exit(3);
}
else {
//Concatenate Username and password into auth string
$concatAuth = $arguements['U'] . "_" . $arguements['P'];
$concatMD5 = md5($concatAuth);
$hostAddr = $arguements['H'];
$auth = $concatMD5;
$authstr = "/api/login/".$auth;
}
$successful =0;
//Set up HTTP request depending on whether secure or not.
if(class_exists('HttpRequest')) {
if($secure) {
$url = "https://".$hostAddr."/api/";
$ssl_array = array('version' => 3);
$r = new HttpRequest("$url", HttpRequest::METH_POST, array('ssl' => $ssl_array));
}
else {
$url = "http://".$hostAddr."/api/";
$r = new HttpRequest("$url", HttpRequest::METH_POST);
}
$r->setOptions(array('connecttimeout'=>120,'timeout'=>120));
//Send the Authorisation String
$r->setBody("$authstr");
//Send HTTP Request
try {
$responce = $r->send()->getBody();
//echo($responce);
} catch (HttpException $ex) {
if (isset($ex->innerException)){
returnNagios("UNKNOWN",$ex->innerException->getMessage());
}
else {
returnNagios("UNKNOWN", $ex->getMessage());
}
}
}
else {
if($secure) {
$url = "https://".$hostAddr."/api/";
}
else {
$url = "http://".$hostAddr."/api/";
}
if(!function_exists("curl_init")) {
returnNagios("UNKNOWN", "HTTPRequest or CURL Libraries aren't installed");
}
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $authstr);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
try{
$responce = curl_exec($ch);
if(curl_error($ch) != "") {
returnNagios("UNKNOWN", $e->getMessage());
}
} catch(Exception $e) {
returnNagios("UNKNOWN", $e->getMessage());
}
curl_close($ch);
}
//Check to see if the Authorisation was successful
try {
$xmlResponse = @new SimpleXMLElement($responce);
}
catch(Exception $e) {
returnNagios("UNKNOWN", $e->getMessage().". Is this a HP MSA P2000?");
}
foreach($xmlResponse->OBJECT->PROPERTY as $Property) {
foreach($Property->attributes() as $name => $val) {
if($name =="name" && $val =="response-type" && $Property == "success") {
$successful =1;
}
}
}
//If Auth was successfull continue
if($successful) {
$sessionVariable = (string) $xmlResponse->OBJECT->PROPERTY[2];
switch($command) {
case "status":
try {
//Get Disk Info
$regXML = getRequest($sessionVariable, "{$url}show/disks", $secure);
$regXML = new SimpleXMLElement($regXML);
foreach($regXML->OBJECT as $obj) {
$attr = $obj->attributes();
//Get HDD Statuses
if($attr['name']== "drive") {
$type = "Disks";
$statuses[$type][]= getEnclosureStatus($obj->PROPERTY, array('name'=>'name', 'value'=>'health'));
}
}
//Get VDisk Info
$regXML = getRequest($sessionVariable, "{$url}show/vdisks", $secure);
$regXML = new SimpleXMLElement($regXML);
foreach($regXML->OBJECT as $obj) {
$attr = $obj->attributes();
//Get Vdisk Statuses
if($attr['name']== "virtual-disk") {
$type = "Vdisk";
$statuses[$type][]= getEnclosureStatus($obj->PROPERTY, array('name'=>'name', 'value'=>'health'));
}
}
//Get Sensor Information
$regXML = getRequest($sessionVariable, "{$url}show/sensor-status", $secure);
$regXML = new SimpleXMLElement($regXML);
foreach($regXML->OBJECT as $obj) {
$attr = $obj->attributes();
if($attr['name']== "sensor") {
switch((string) getEnclosureStatus($obj->PROPERTY, array('name'=>'name', 'value'=>'sensor-type'))) {
case "3":
$type = "Temperature";
break;
case "9":
$type = "Voltage";
break;
case "2":
$type = "Overall";
break;
}
$statuses[$type][]= getEnclosureStatus($obj->PROPERTY, array('name'=>'name', 'value'=>'status'));
}
}
//Get FRU Information
$regXML = getRequest($sessionVariable, "{$url}show/frus", $secure);
$regXML = new SimpleXMLElement($regXML);
foreach($regXML->OBJECT as $obj) {
$attr = $obj->attributes();
if($attr['name']== "fru") {
$type = (string) getEnclosureStatus($obj->PROPERTY, array('name'=>'name', 'value'=>'fru-shortname'));
$statuses[$type][]= getEnclosureStatus($obj->PROPERTY, array('name'=>'name', 'value'=>'fru-status'));
}
}
//Get Enclosure Information
$regXML = getRequest($sessionVariable, "{$url}show/enclosures", $secure);
$regXML = new SimpleXMLElement($regXML);
foreach($regXML->OBJECT as $obj) {
$attr = $obj->attributes();
if($attr['name']== "enclosures") {
$type = "Enclosures";
$statuses[$type][]= getEnclosureStatus($obj->PROPERTY, array('name'=>'name', 'value'=>'health'));
}
}
if(count($statuses) < 1) {
//Use API to run command and get XML
$regXML = getRequest($sessionVariable, "{$url}show/enclosure-status", $secure);
$regXML = new SimpleXMLElement($regXML);
foreach($regXML->OBJECT as $obj) {
//get statuses of components and enclosures and enter status into array
$attr = $obj->attributes();
//Get all the enlosure components HDD, FAN, PSU etc
if($attr['name']== "enclosure-component") {
$type = (string) getEnclosureStatus($obj->PROPERTY, array('name'=>'display-name', 'value'=>'Type'));
$statuses[$type][]= getEnclosureStatus($obj->PROPERTY, array('name'=>'name', 'value'=>'status'));
}
//Get all overall enclosure status
if($attr['name'] == "enclosure-environmental") {
$type = "Enclosure";
$statuses[$type][]= getEnclosureStatus($obj->PROPERTY, array('name'=>'name', 'value'=>'status'));
}
}
}
//print_r($statuses);
}
catch(Exception $e) {
returnNagios("UNKNOWN", $e->getMessage());
}
//loop through statuses array and create the Output. Also get the overall state.
//Use highest status as overall status.
//Count each type and produce output.
if(isset($statuses)) {
$overallStatus = "OK";
$output = "";
foreach($statuses as $typ=>$arrType) {
$output .= $typ;
$typeWarn =0;
$typeOK =0;
$typeCrit = 0;
foreach($arrType as $arrTypeStatus) {
switch($arrTypeStatus) {
case "Fault" :
$typeCrit++;
break;
case "Warning" :
$typeWarn++;
break;
case "OK" :
$typeOK++;
break;
default:
$typeCrit++;
break;
}
}
if($typeWarn >0 && $typeCrit ==0) {
$output .= " $typeWarn Warning, ";
$overallStatus = "WARNING";
}
if($typeCrit > 0) {
$output .= " $typeCrit Critical, ";
$overallStatus = "CRITICAL";
}
if($typeCrit ==0 && $typeWarn ==0) {
$output .= " $typeOK OK, ";
}
}
}
else {
returnNagios("UNKNOWN", "Could Not Read API");
}
break;
case "named-volume":
try {
//pass $volumename to the end of URL and use API to run command and get XML
$regXML = getRequest($sessionVariable, "{$url}show/volumes/".$volumeName, $secure);
$regXML = new SimpleXMLElement($regXML);
foreach($regXML->OBJECT as $obj) {
$attr = $obj->attributes();
if($attr['name']=="volume") {
$vdiskName = (string) getEnclosureStatus($obj->PROPERTY, array('name'=>'name', 'value'=>'virtual-disk-name'));
$diskName = (string) getEnclosureStatus($obj->PROPERTY, array('name'=>'name', 'value'=>'volume-name'));
$diskSize = (string) getEnclosureStatus($obj->PROPERTY, array('name'=>'name', 'value'=>'size'));
$statuses = (string) getEnclosureStatus($obj->PROPERTY, array('name'=>'name', 'value'=>'health'));
$reason = (string) getEnclosureStatus($obj->PROPERTY, array('name'=>'name', 'value'=>'health-reason'));
$action = (string) getEnclosureStatus($obj->PROPERTY, array('name'=>'name', 'value'=>'health-recommendation'));
}
}
}
catch(Exception $e) {
returnNagios("UNKNOWN", $e->getMessage().". Check firmware supports command.");
}
//Check the return of status and build the output
if(isset($statuses)){
$overallStatus = "OK";
$output = "";
if($statuses == "OK") {
//Health is OK
$overallstatus = 'OK';
$output = "Volume " . $diskName . " is " . $statuses . ". Size is: " . $diskSize . " vDisk Name is " . $vdiskName . ".";
}
elseif($statuses == "Degraded") {
//Health is Degraded = Warning
$overallstatus = 'WARNING';
$output = "Volume " . $diskName . " is " . $statuses . ". Reason is: " . $reason . ". Recommended action is " . $action . ".";
}
elseif($statuses == "Fault") {
//Health is Fault = Critical
$overallstatus = 'CRITICAL';
$output = "Volume " . $diskName . " is " . $statuses . ". Reason is: " . $reason . ". Recommended action is " . $action . ".";
}
elseif($statuses == "Unknown") {
//Health is Unknown
$overallstatus = 'UNKNOWN';
$output = "Volume " . $diskName . " is " . $statuses . ". Reason is: " . $reason . ". Recommended action is " . $action . ".";
}
} else {
returnNagios("UNKNOWN", "Could Not Read API");
}
break;
case "named-vdisk":
try {
//pass $volumename to the end of URL and use API to run command and get XML
$regXML = getRequest($sessionVariable, "{$url}show/vdisks/".$volumeName, $secure);
$regXML = new SimpleXMLElement($regXML);
foreach($regXML->OBJECT as $obj) {
$attr = $obj->attributes();
if($attr['name']=="virtual-disk") {
$diskName = (string) getEnclosureStatus($obj->PROPERTY, array('name'=>'name', 'value'=>'name'));
$diskSize = (string) getEnclosureStatus($obj->PROPERTY, array('name'=>'name', 'value'=>'size'));
$statuses = (string) getEnclosureStatus($obj->PROPERTY, array('name'=>'name', 'value'=>'health'));
$reason = (string) getEnclosureStatus($obj->PROPERTY, array('name'=>'name', 'value'=>'health-reason'));
$action = (string) getEnclosureStatus($obj->PROPERTY, array('name'=>'name', 'value'=>'health-recommendation'));
}
}
}
catch(Exception $e) {
returnNagios("UNKNOWN", $e->getMessage().". Check firmware supports command.");
}
//Check the return of status and build the output
if(isset($statuses)){
$overallStatus = "OK";
$output = "";
if($statuses == "OK") {
//Health is OK
$overallstatus = 'OK';
$output = "vDisk " . $diskName . " is " . $statuses . ". Size is: " . $diskSize . ".";
}
elseif($statuses == "Degraded") {
//Health is Degraded = Warning
$overallstatus = 'WARNING';
$output = "vDisk " . $diskName . " is " . $statuses . ". Reason is: " . $reason . ". Recommended action is " . $action . ".";
}
elseif($statuses == "Fault") {
//Health is Fault = Critical
$overallstatus = 'CRITICAL';
$output = "vDisk " . $diskName . " is " . $statuses . ". Reason is: " . $reason . ". Recommended action is " . $action . ".";
}
elseif($statuses == "Unknown") {
//Health is Unknown
$overallstatus = 'UNKNOWN';
$output = "vDisk " . $diskName . " is " . $statuses . ". Reason is: " . $reason . ". Recommended action is " . $action . ".";
}
} else {
returnNagios("UNKNOWN", "Could Not Read API");
}
break;
case "disk":
try {
//Use API to run command and get XML
$regXML = getRequest($sessionVariable, "{$url}show/disk-statistics", $secure);
$regXML = new SimpleXMLElement($regXML);
foreach($regXML->OBJECT as $obj) {
$attr = $obj->attributes();
if($attr['name']=="disk-statistics") {
$diskName = (string) getEnclosureStatus($obj->PROPERTY, array('name'=>'name', 'value'=>'durable-id'));
$perfstats[$diskName]= getEnclosureStatus($obj->PROPERTY, array('name'=>'name', 'value'=>$stat), 1);
}
}
}
catch(Exception $e) {
returnNagios("UNKNOWN", $e->getMessage().". Check firmware supports command.");
}
break;
case "controller":
try {
//Use API to run command and get XML
$regXML = getRequest($sessionVariable, "{$url}show/controller-statistics", $secure);
$regXML = new SimpleXMLElement($regXML);
foreach($regXML->OBJECT as $obj) {
$attr = $obj->attributes();
if($attr['name']=="controller-statistics") {
$controllerName = (string) getEnclosureStatus($obj->PROPERTY, array('name'=>'name', 'value'=>'durable-id'));
$perfstats[$controllerName]= getEnclosureStatus($obj->PROPERTY, array('name'=>'name', 'value'=>$stat));
}
}
}
catch(Exception $e) {
returnNagios("UNKNOWN", $e->getMessage().". Check firmware supports command.");
}
break;
case "vdisk":
try {
//Use API to run command and get XML
$regXML = getRequest($sessionVariable, "{$url}show/vdisk-statistics", $secure);
$regXML = new SimpleXMLElement($regXML);
foreach($regXML->OBJECT as $obj) {
$attr = $obj->attributes();
if($attr['name']=="vdisk-statistics") {
$vdiskName = (string) getEnclosureStatus($obj->PROPERTY, array('name'=>'name', 'value'=>'name'));
$perfstats[$vdiskName]= getEnclosureStatus($obj->PROPERTY, array('name'=>'name', 'value'=>$stat));
}
}
}
catch(Exception $e) {
returnNagios("UNKNOWN", $e->getMessage().". Check firmware supports command.");
}
break;
case "volume":
try {
//Use API to run command and get XML
$regXML = getRequest($sessionVariable, "{$url}show/volume-statistics", $secure);
$regXML = new SimpleXMLElement($regXML);
foreach($regXML->OBJECT as $obj) {
$attr = $obj->attributes();
if($attr['name']=="volume-statistics") {
$volumeName = (string) getEnclosureStatus($obj->PROPERTY, array('name'=>'name', 'value'=>'volume-name'));
$perfstats[$volumeName]= getEnclosureStatus($obj->PROPERTY, array('name'=>'name', 'value'=>$stat));
}
}
}
catch(Exception $e) {
returnNagios("UNKNOWN", $e->getMessage().". Check firmware supports command.");
}
break;
case "vdisk-read-latency":
$stat = "avg-read-rsp-time";
try {
//Use API to run command and get XML
$regXML = getRequest($sessionVariable, "{$url}show/vdisk-statistics", $secure);
$regXML = new SimpleXMLElement($regXML);
foreach($regXML->OBJECT as $obj) {
$attr = $obj->attributes();
#print_r($obj);
if($attr['name']=="vdisk-statistics") {
$vdiskName = (string) getEnclosureStatus($obj->PROPERTY, array('name'=>'name', 'value'=>'name'));
$perfstats[$vdiskName]= getEnclosureStatus($obj->PROPERTY, array('name'=>'name', 'value'=>$stat));
}
}
}
catch(Exception $e) {
returnNagios("UNKNOWN", $e->getMessage().". Check firmware supports command.");
}
break;
case "vdisk-write-latency":
$stat = "avg-write-rsp-time";
try {
//Use API to run command and get XML
$regXML = getRequest($sessionVariable, "{$url}show/vdisk-statistics", $secure);
$regXML = new SimpleXMLElement($regXML);
foreach($regXML->OBJECT as $obj) {
$attr = $obj->attributes();
#print_r($obj);
if($attr['name']=="vdisk-statistics") {
$vdiskName = (string) getEnclosureStatus($obj->PROPERTY, array('name'=>'name', 'value'=>'name'));
$perfstats[$vdiskName]= getEnclosureStatus($obj->PROPERTY, array('name'=>'name', 'value'=>$stat));
}
}
}
catch(Exception $e) {
returnNagios("UNKNOWN", $e->getMessage().". Check firmware supports command.");
}
break;
default :
echo "Unknown command specified";
Usage();
exit(3);
break;
}
$nonPerfCommands = array('status', 'named-volume', 'named-vdisk');
if(!in_array($command,$nonPerfCommands)) {
if(isset($warning) && isset($critical)) {
$perfOutput = parsePerfData($perfstats, $uom, $warnType, $warning, $critical);
$overallStatus = $perfOutput[1];
$output = "{$command} {$stat} - ".$perfOutput[0];
}
else {
$perfOutput = parsePerfData($perfstats, $uom);
$output = "{$command} {$stat} - ";
$output .= $perfOutput;
$overallStatus = "OK";
}
}
returnNagios($overallStatus, $output);
}
else {
//if Auth is unsucessful return Status UKNOWN
returnNagios("UNKNOWN", "Authentication Unsuccessful");
}
function parsePerfData($perfData, $uom="", $warnType=false, $warning=0, $critical=0) {
$output ="";
$perfOutput ="";
$overallState = "OK";
foreach($perfData as $key => $val) {
$perfOutput .= " {$key}={$val}{$uom};";
if($warnType != false) {
switch($warnType) {
case "lessthan":
if($val < $warning && $val > $critical) {
$overallState = "WARNING";
$output .= "WARNING ";
}
if($val < $critical) {
$overallState = "CRITICAL";
$output .= "CRITICAL ";
}
break;
case "greaterthan":
if($val > $warning && $val < $critical) {
$overallState = "WARNING";
$output .= "WARNING ";
}
if($val > $critical) {
$overallState = "CRITICAL";
$output .= "CRITICAL ";
}
break;
}
$perfOutput .=$warning.";".$critical."; ";
}
else {
$perfOutput .= ";; ";
}
$output .= " {$key} {$val}{$uom}, ";
}
$output = $output."|".$perfOutput;
if($warnType != false) {
$arrReturn = array($output, $overallState);
return $arrReturn;
}
else {
return $output;
}
}
function getEnclosureStatus($encXML, $propertyName) {
//Loop through all Property Values in the Object and match values passed in with array key value pair
foreach($encXML as $prop) {
$attr = $prop->attributes();
if($attr[$propertyName['name']] == $propertyName['value']) {
$status = (string)$prop;
}
}
if(!isset($status)) {
throw new Exception('No Value Found');
}
return $status;
}
function getRequest($sessionKey, $reqUrl, $secure) {
if(class_exists('HttpRequest')) {
//Send HTTP request to API and return response
if($secure) {
$ssl_array = array('version' => 3);
$r = new HttpRequest("$reqUrl", HttpRequest::METH_GET, array('ssl' => $ssl_array));
}
else {
$r = new HttpRequest("$reqUrl", HttpRequest::METH_GET);
}
$r->setOptions(array('cookies'=>array('wbisessionkey'=>$sessionKey, 'wbiusername'=>''), 'connecttimeout'=>120,'timeout'=>120));
$r->setBody();
try {
$responce = $r->send()->getBody();
return $responce;
} catch (HttpException $ex) {
throw $ex;
}
}
else {
if(!function_exists("curl_init")) {
throw new Exception("HTTPRequest or CURL Libraries aren't installed");
}
$ch = curl_init($reqUrl);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_COOKIE, "wbisessionkey=".$sessionKey."; wbiusername=;");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
try{
$responce = curl_exec($ch);
$error = curl_error($ch);
curl_close($ch);
if($error != "") {
throw new Exception("CURL Error: " . $error);
}
return $responce;
} catch(Exception $e) {
curl_close($ch);
throw $e;
}
}
}
function Usage() {
//echo usage for the script
echo "
This script sends HTTP Requests to the specified HP P2000 Array to determine its health
and outputs performance data fo other checks.
Required Variables:
-H Hostname or IP Address
-U Username
-P Password
Optional Variables:
These options are not required. Both critical and warning must be specified together
If warning/critical is specified -t must be specified or it defaults to greaterthan.
-s Set to 1 for Secure HTTPS Connection
-c Sets what you want to do
status - get the status of the SAN
disk - Get performance data of the disks
controller - Get performance data of the controllers
named-volume - Get the staus of an individual volume - MUST have -n volumename specified
named-vdisk - Get the staus of an individual vdisk - MUST have -n volumename specified
vdisk - Get performance data of the VDisks
volume - Get performance data of the volumes
vdisk-write-latency - Get vdisk write latency (only available in later firmwares)
vdisk-read-latency - Get vdisk read latency (only available in later firmwares)
-S specify the stats to get for performance data. ONLY works when -c is specified
-u Units of measure. What should be appended to performance values. ONLY used when -c specified.
-w Specify Warning value
-C Specify Critical value
-t Specify how critical warning is calculated (DEFAULT greaterthan)
lessthan - if value is lessthan warning/critical return warning/critical
greaterthan - if value is greaterthan warning/critical return warning/critical
-n Volume Name to be used with -c named-volume or -c named-vdisk
Examples
Just get the status of the P2000
./check_p2000_api.php -H 192.168.0.2 -U manage -P !manage
Get the status of the volume name volume1 on the P2000
./check_p2000_api.php -H 192.168.0.2 -U manage -P !manage -c named-volume -n volume1
Get the CPU load of the controllers and append % to the output
./check_p2000_api.php -H 192.168.0.2 -U manage -P !manage -s 1 -c controller -S cpu-load -u \"%\"
Get the CPU load of the controllers and append % to the output warning if its over 30 or critical if its over 60
./check_p2000_api.php -H 192.168.0.2 -U manage -P !manage -s 1 -c controller -S cpu-load -u \"%\" -w 30 -C 60
Setting option -c to anything other than status will output performance data for Nagios to process.
You can find certain stat options to use by logging into SAN Manager through the web interface and
manually running the commands in the API. Some options are iops, bytes-per-second-numeric, cpu-load,
write-cache-percent and others. If using Warning/Critical options specify a stat without any Units
otherwise false states will be returned. You can specify units yourself using -u option.
";
}
function returnNagios($Result="UNKNOWN", $message="") {
//Return to nagios with appropriate exit code
switch($Result) {
case "OK":
echo "OK : ".$message;
exit(0);
case "WARNING":
echo "WARNING : ".$message;
exit(1);
case "CRITICAL":
echo "CRITICAL : ".$message;
exit(2);
case "UNKNOWN":
echo "UNKNOWN: ".$message;
exit(3);
}
}
?>