Anonymous Anonymous - 1 year ago 249
PHP Question

Curl isn't woking with Nagios

I'm currently developing a nagios plugin with PHP and cURL.

My problem is that my script is working well when i use it with PHP like this :

#php /usr/local/nagios/plugins/script.php

I mean it returns me a 200 HTTP CODE.

But with nagios it returns me a 0 HTTP CODE. It's strange because the php is working with NAGIOS (i can read variables...). So the problem is that Nagios can't use cURL.

Can someone give me a clue ? Thanks.

Here you can see my code.

$widgeturl = "";
$agent = "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv: Gecko/2009070611 Firefox/3.0.12";
if (!function_exists("curl_init")) die("pushMeTo needs CURL module, please install CURL on your php.");

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $widgeturl);

$page = curl_exec($ch); //or die("Curl exe failed");
$code=curl_getinfo($ch, CURLINFO_HTTP_CODE);

if ($code==200) {
fwrite(STDOUT, $page.'Working well : '.$code);
else {
fwrite(STDOUT, $page.'not working : '.$code);

Solution :
It was because the proxy was basically set on my OS (centOS), but Nagios was not using it instead of PHP. So i just had to put : curl_setopt($ch, CURLOPT_PROXY, 'myproxy:8080'); curl_setopt($ch, CURLOPT_PROXYUSERPWD, "user:pass"); Hope it could help someone

Answer Source
curl_setopt($ch, CURLOPT_PROXY, 'myproxy:8080'); 
curl_setopt($ch, CURLOPT_PROXYUSERPWD, "user:pass")