'Nagios/Centreon PHP check script for HP MSA 2040 on HP MSA 2050

I'm trying to run this nagios/centreon check script on HPE MSA 2050 it was working on HP MSA 2040.

My error:

UNKNOWN: Authentication Unsuccessful

Everything is same as on the MSA 2040 (settings). Maybe someone is using this script and now what I need to change?

#!/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
$arguments = getopt("H:U:P:s:c:S:u:w:C:t:n:");
 
$secure = isset($arguments['s']) ? $arguments['s'] : 0;
$command = isset($arguments['c']) ? $arguments['c'] : "status";
$stat = isset($arguments['S']) ? $arguments['S'] : "iops";
$uom = isset($arguments['u']) ? $arguments['u'] : "";
$warnType = isset($arguments['t']) ? $arguments['t'] : "greaterthan";
$volumeName = isset($arguments['n']) ? $arguments['n'] : "";
 
if(isset($arguments['w']) || isset($arguments['C'])) {
        if(!isset($arguments['w']) || !isset($arguments['C'])) {
                echo "Specify warning/critical threshold \n\r";
                Usage();
                exit(3);
        }
        else {
                $warning = $arguments['w'];
                $critical = $arguments['C'];
        }
}
 
//Validate Provided arguments
if(!isset($arguments['H']) || !isset($arguments['U']) || !isset($arguments['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 = $arguments['U'] . "_" . $arguments['P'];
        $concatMD5 = md5($concatAuth);
        $hostAddr = $arguments['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];
       

script from github: https://github.com/thomasweaver/check_p2000_api



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source