This post is more than 5 years old
21 Posts
0
6805
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);
?>
Peter_Sero
1.2K Posts
0
February 11th, 2017 03:00
If your webserver is running on SELinux, try
setsebool -P httpd_can_network_connect 1
hth
-- Peter
eespin
21 Posts
0
February 11th, 2017 03:00
This definitely produced a different error, however still puzzling- so after running the command the error I received from curl_error() is : Peer's Certificate issuer is not recognized.
However we set the option: CURLOPT_SSL_VERIFYPEER => false
So it should be okay right? Still this gives me another error to work on which is great thank you!
cstacey
31 Posts
1
February 11th, 2017 09:00
An alternative would be to use the Data Insights Connector portion of the Isilon SDK which is available at Dell EMC Isilon · GitHub. It provides a service that polls one or more Isilon clusters for whatever performance metrics you want (we provide a starting set), feeds them into an instance of InfluxDB and a set of Grafana dashboards to visualize the data.
Cheers,
Chris
eespin
21 Posts
1
February 11th, 2017 13:00
Thank you Chris, that's actually the end goal - the reason we are going the php route is it's already in our environment, and I'm a bit more familiar with programming in php than python but I think if I get desperate I'd force myself to use it.
Peter_Sero
1.2K Posts
0
February 12th, 2017 00:00
Try this out, IIRC some builds of libcurl require it in order to suppress all certificate verification:
CURLOPT_SSL_VERIFYHOST => 0
-- Peter
eespin
21 Posts
0
February 27th, 2017 13:00
This ended up working for me, my array of curl options clobbered the process. Thank you everyone for your help.
$http_header = array('Content-Type: application/json','Authorization: Basic eW91X2hhdmVfbm9fcG93ZXJfaGVyZQ==');
$clusters = array('isilona','isilonb');
foreach ($clusters as $cluster) {
echo "
This is " . $cluster . "
";
$ch = curl_init("https://" . $cluster . "fqdn.com:8080/platform/1/statistics/current?keys=all");
curl_setopt($ch, CURLOPT_HTTPHEADER, $http_header);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
$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. Additional info: ' . var_export($info));
}
curl_close($ch);
print_r($curl_response);
}
?>