Page 1 of 1

Nagios PHP Plugin Wont Scrape Remotely

Posted: Wed Feb 06, 2013 8:47 am
by grkblood13
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.

Code: Select all

#!/usr/bin/php
<?php
$http = file_get_contents("http://localhost/index.html");
print trim("OUTPUT - $http")."\n";
?>

Re: Nagios PHP Plugin Wont Scrape Remotely

Posted: Wed Feb 06, 2013 12:15 pm
by sreinhardt
Does the plugin that you created have read and execute permissions for the user that nrpe daemon was running as? Also, and it shouldn't be the case, but is the nrpe daemon dropping once started, or running as the user that starts it instead of the nrpe user?

Re: Nagios PHP Plugin Wont Scrape Remotely

Posted: Wed Feb 06, 2013 12:26 pm
by abrist
I just tested your use case. I had no problem running it locally, locally through nrpe, remotely through nrpe, and through nrpe from XI. All cases work, but the output is multiline, so the first line only outputs: "OUTPUT -" which would result in fail in XI. I did not run into any issues with running the instance from the cli compared to through nrpe. As sreinhardt pointed out, you may have permission issues.

Re: Nagios PHP Plugin Wont Scrape Remotely

Posted: Wed Feb 06, 2013 12:30 pm
by grkblood13
The problem ended up being what a lot of weird problems come from - SELinux. Creating a module for the plugin and then installing it with semodule fixed the issue.

Re: Nagios PHP Plugin Wont Scrape Remotely

Posted: Wed Feb 06, 2013 12:31 pm
by abrist
Ah, good ole selinux. Best of luck with your future endeavors.