gpt4 book ai didi

php - Curl 不适用于 Nagios

转载 作者:太空宇宙 更新时间:2023-11-03 17:17:31 24 4
gpt4 key购买 nike

我目前正在使用 PHP 和 cURL 开发一个 nagios 插件。

我的问题是,当我像这样将它与 PHP 一起使用时,我的脚本运行良好:

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

我的意思是它返回一个 200 HTTP CODE。

但是对于 nagios,它会返回一个 0 HTTP CODE。这很奇怪,因为 PHP 正在与 NAGIOS 一起工作(我可以读取变量......)。所以问题是 Nagios 不能使用 cURL。

谁能给我一个线索?谢谢。

在这里你可以看到我的代码。

<?php
$widgeturl = "http://google.com";
$agent = "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.12) 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);
exit(0);
}
else {
fwrite(STDOUT, $page.'not working : '.$code);
exit(1);
}
curl_close($ch);

解决方案:这是因为代理基本上是在我的操作系统(centOS)上设置的,但是 Nagios 并没有使用它来代替 PHP。所以我只需要输入:curl_setopt($ch, CURLOPT_PROXY, 'myproxy:8080'); curl_setopt($ch, CURLOPT_PROXYUSERPWD, "user:pass");希望它可以帮助某人

最佳答案

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

关于php - Curl 不适用于 Nagios,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23102460/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com