Nagios PHP Plugin Wont Scrape Remotely

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
grkblood13
Posts: 2
Joined: Wed Feb 06, 2013 8:33 am

Nagios PHP Plugin Wont Scrape Remotely

Post 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";
?>
sreinhardt
-fno-stack-protector
Posts: 4366
Joined: Mon Nov 19, 2012 12:10 pm

Re: Nagios PHP Plugin Wont Scrape Remotely

Post 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?
Nagios-Plugins maintainer exclusively, unless you have other C language bugs with open-source nagios projects, then I am happy to help! Please pm or use other communication to alert me to issues as I no longer track the forum.
abrist
Red Shirt
Posts: 8334
Joined: Thu Nov 15, 2012 1:20 pm

Re: Nagios PHP Plugin Wont Scrape Remotely

Post 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.
Former Nagios employee
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
grkblood13
Posts: 2
Joined: Wed Feb 06, 2013 8:33 am

Re: Nagios PHP Plugin Wont Scrape Remotely

Post 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.
abrist
Red Shirt
Posts: 8334
Joined: Thu Nov 15, 2012 1:20 pm

Re: Nagios PHP Plugin Wont Scrape Remotely

Post by abrist »

Ah, good ole selinux. Best of luck with your future endeavors.
Former Nagios employee
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
Locked