Nagios PHP Plugin Wont Scrape Remotely
Posted: Wed Feb 06, 2013 8:47 am
I created a nagios plugin written in php that scrapes a website for json, parses for a value and returns the result. This plugin works fine when I run it locally but whenever I trying to run it remotely using check_nrpe the scrape portion of the plugin fails.
Trying to debug this, I stopped the NRPE daemon on the remote host, sued to the nrpe user and restarted the daemon manually. Doing this the plugin then began to work when execute remotely through check_nrpe.
The weird thing is that regardless of whether I run it by hand or by service script its running as the nrpe user. Why would this fail to execute remotely when the nrpe daemon is started by the service script but work when started by hand?
Below is an example plugin that I wrote to show whats failing. This isn't the main plugin I wrote but it replicates the exact same issue that I discussed above. In this example localhost/index.html contains the string "0" so the desired output is "OUTPUT - 0" but using the conditions that fail you get "OUTPUT -" as the output.
Trying to debug this, I stopped the NRPE daemon on the remote host, sued to the nrpe user and restarted the daemon manually. Doing this the plugin then began to work when execute remotely through check_nrpe.
The weird thing is that regardless of whether I run it by hand or by service script its running as the nrpe user. Why would this fail to execute remotely when the nrpe daemon is started by the service script but work when started by hand?
Below is an example plugin that I wrote to show whats failing. This isn't the main plugin I wrote but it replicates the exact same issue that I discussed above. In this example localhost/index.html contains the string "0" so the desired output is "OUTPUT - 0" but using the conditions that fail you get "OUTPUT -" as the output.
Code: Select all
#!/usr/bin/php
<?php
$http = file_get_contents("http://localhost/index.html");
print trim("OUTPUT - $http")."\n";
?>