Advertisement
jonwitts

Nagios HP MSA P2000 Status and Performance Monitor v2

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