eespin

updated

10 years ago

E

eespin

21 Posts

0

7108

February 10th, 2017 13:00

Issues calling REST API with PHP script , curl in bash works

Hey guys, so this is my first time posting and I'm wondering if this belongs somewhere else but thought I'd get started here. My goal is to construct a few php scripts to hit our storage array rest endpoints for monitoring data and statistics and eventually feed it to influxdb and then grafana. I started with vmax, and ran into some issues so decided to jump into Isilon (thanks ADD). Anyways I am having an issue with my script it seems to return a permission denied error, I've tried many different methods including basic https (base64 encode user:pass) and creating cookies from another forum with no success. I know I don't have issues with connectivity as I'm actually able to pull things from bash on the same server with this command and from my workstation via the browser works as well:

curl -u root:a --insecure https://10.102.2.70:8080/platform/1/statistics/current?keys=all > isilon_Data.txt

However my script is failing with permission denied. I was wondering if anyone could lend a second pair of eyes. My error is below and the script is further down.

The error:

Failed to connect to 10.102.2.70: Permission denied

More details

array ( 'url' => 'https://10.102.2.70:8080/platform/1/statistics/current?keys=all', 'content_type' => NULL, 'http_code' => 0, 'header_size' => 0, 'request_size' => 0, 'filetime' => -1, 'ssl_verify_result' => 0, 'redirect_count' => 0, 'total_time' => 0, 'namelookup_time' => 3.2E-5, 'connect_time' => 0, 'pretransfer_time' => 0, 'size_upload' => 0, 'size_download' => 0, 'speed_download' => 0, 'speed_upload' => 0, 'download_content_length' => -1, 'upload_content_length' => -1, 'starttransfer_time' => 0, 'redirect_time' => 0, 'certinfo' => array ( ), 'primary_ip' => '10.102.2.70', 'primary_port' => 8080, 'local_ip' => '', 'local_port' => 0, 'redirect_url' => '', )error occured during curl exec. Additioanl info:

$http_header = array('Content-Type: application/json');

$username = "root";

$password = "a";

$ch = curl_init('https://10.102.2.70:8080/platform/1/statistics/current?keys=all');

curl_setopt_array($ch, array(

    CURLOPT_USERPWD => "$username:$password",

    CURLOPT_HTTPAUTH => CURLAUTH_BASIC,

    CURLOPT_RETURNTRANSFER => TRUE,

    CURLOPT_HTTPHEADER => $http_header,

    CURLOPT_SSL_VERIFYPEER => false

));

$curl_response = curl_exec($ch);

if ($curl_response === false) {

    $info = curl_getinfo($ch);

    $error = curl_error($ch);

    curl_close($ch);

    echo "
The error:
";

    print $error;

    echo"
More details
";

    die('error occured during curl exec. Additioanl info: ' . var_export($info));

}

curl_close($ch);

$decoded = json_decode($curl_response);

if (isset($decoded->response->status) && $decoded->response->status == 'ERROR') {

    die('error occured: ' . $decoded->response->errormessage);

}

echo 'response ok!';

var_export($decoded->response);

?>