When run against time, here are the values. It takes less than 5 seconds to run:
Code: Select all
real 0m2.144s
user 0m0.099s
sys 0m0.015sCode: Select all
real 0m2.144s
user 0m0.099s
sys 0m0.015sAre you running the plugin as the nagios user?dgatlas wrote:I've written a plugin in php which I can run at the command line fine.
Code: Select all
su nagios
./my_plugin --arguements blahYes. Running the script as the nagios user also produces the desired output:Are you running the plugin as the nagios user?
Code: Select all
su nagios ./my_plugin --arguements blah
Code: Select all
# su nagios
$ ./my_plugin -H 192.168.100.100 -S
Running
$
It's throwing the error at:Box293 wrote:At this point I suggest commenting out chunks of code in your plugin and then forcing a check from Nagios. Kind of like drawing a line in the sand.
This will help diagnose if a part of the plugin is causing the issue.
Code: Select all
$result = curl_exec($curl);Code: Select all
function getSystem($url, $cookiejar) {
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HEADER => false,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_ENCODING => "",
CURLOPT_USERAGENT => 'spider',
CURLOPT_AUTOREFERER => true,
CURLOPT_CONNECTTIMEOUT => 30,
CURLOPT_TIMEOUT => 30,
CURLOPT_MAXREDIRS => 10,
CURLOPT_COOKIEFILE => $cookiejar,
CURLOPT_COOKIEJAR => $cookiejar,
CURLOPT_URL => $url
));
$result = curl_exec($curl);
curl_close($curl);
return $result;
}
Code: Select all
(No output returned from plugin)Code: Select all
COMMAND: /usr/local/nagios/libexec/my_plugin.php -H 192.168.100.100 -S
OUTPUT: RunningCode: Select all
function getSystem($url, $cookiejar) {
$options_array = array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HEADER => false,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_ENCODING => "",
CURLOPT_USERAGENT => 'spider',
CURLOPT_AUTOREFERER => true,
CURLOPT_CONNECTTIMEOUT => 30,
CURLOPT_TIMEOUT => 30,
CURLOPT_MAXREDIRS => 10,
CURLOPT_COOKIEFILE => $cookiejar,
CURLOPT_COOKIEJAR => $cookiejar,
CURLOPT_URL => $url
);
$curl = curl_init();
curl_setopt_array($curl, $options_array);
$result = curl_exec($curl);
curl_close($curl);
return $result;
}Code: Select all
CURLOPT_COOKIEFILE => $cookiejar,
CURLOPT_COOKIEJAR => $cookiejar,Be wary of using the Test Check Command button as those commands are executed as the user apache instead of nagios and some funny character escaping can occur. Use the "force an immediate check" on the service screen for a true test.dgatlas wrote:Also when defining the service, there is a "Test Check Command" button, which also outputs correctly.
Code: Select all
CURLOPT_COOKIEJAR => $cookiejarCode: Select all
CURLOPT_CONNECTTIMEOUT => 30,
CURLOPT_TIMEOUT => 30,Code: Select all
CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_TIMEOUT => 10,Code: Select all
(No output returned from plugin)Code: Select all
exit(1);Running as "nagios" still outputs correctly. Both usingBe wary of using the Test Check Command button as those commands are executed as the user apache instead of nagios and some funny character escaping can occur. Use the "force an immediate check" on the service screen for a true test.
Code: Select all
su nagiosCode: Select all
sudo -u nagios -H ./my_plugin ...