Service check timed out after 60.04 seconds

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
dgatlas
Posts: 16
Joined: Thu Dec 11, 2014 1:42 pm

Service check timed out after 60.04 seconds

Post by dgatlas »

I've written a plugin in php which I can run at the command line fine.

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.015s
But... in the XI interface I get: (Service check timed out after 60.04 seconds). When I increase the nagios service_check_timeout to 120 i get: (Service check timed out after 120.05 seconds)
User avatar
Box293
Too Basu
Posts: 5126
Joined: Sun Feb 07, 2010 10:55 pm
Location: Deniliquin, Australia
Contact:

Re: Service check timed out after 60.04 seconds

Post by Box293 »

dgatlas wrote:I've written a plugin in php which I can run at the command line fine.
Are you running the plugin as the nagios user?

Code: Select all

su nagios
./my_plugin --arguements blah
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
dgatlas
Posts: 16
Joined: Thu Dec 11, 2014 1:42 pm

Re: Service check timed out after 60.04 seconds

Post by dgatlas »

Are you running the plugin as the nagios user?

Code: Select all

su nagios
./my_plugin --arguements blah
Yes. Running the script as the nagios user also produces the desired output:

Code: Select all

# su nagios
$ ./my_plugin -H 192.168.100.100 -S
Running
$
User avatar
Box293
Too Basu
Posts: 5126
Joined: Sun Feb 07, 2010 10:55 pm
Location: Deniliquin, Australia
Contact:

Re: Service check timed out after 60.04 seconds

Post by Box293 »

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.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
dgatlas
Posts: 16
Joined: Thu Dec 11, 2014 1:42 pm

Re: Service check timed out after 60.04 seconds

Post by dgatlas »

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.
It's throwing the error at:

Code: Select all

$result = curl_exec($curl);
Here's the entire method. I don't see anything that could be causing this. I have the same line in another method in the same script that does not cause this issue.

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;
}
dgatlas
Posts: 16
Joined: Thu Dec 11, 2014 1:42 pm

Re: Service check timed out after 60.04 seconds

Post by dgatlas »

Now the plugin seems to run but shows

Code: Select all

(No output returned from plugin)

Also when defining the service, there is a "Test Check Command" button, which also outputs correctly.

Code: Select all

COMMAND: /usr/local/nagios/libexec/my_plugin.php -H 192.168.100.100 -S
OUTPUT: Running
The plugin was uploaded through the XI Admin page > Manage Plugins
User avatar
Box293
Too Basu
Posts: 5126
Joined: Sun Feb 07, 2010 10:55 pm
Location: Deniliquin, Australia
Contact:

Re: Service check timed out after 60.04 seconds

Post by Box293 »

I'm not familiar with curl but I've been looking online at some examples.

I know this is probably not going to make a difference, but perhaps define the array first.

Code: 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;
}
Is there a specific error that is being returned?

Also, are CURLOPT_COOKIEFILE and CURLOPT_COOKIEJAR supposed to be using the same variable $cookiejar?

Code: Select all

      CURLOPT_COOKIEFILE      => $cookiejar,
      CURLOPT_COOKIEJAR       => $cookiejar,
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
User avatar
Box293
Too Basu
Posts: 5126
Joined: Sun Feb 07, 2010 10:55 pm
Location: Deniliquin, Australia
Contact:

Re: Service check timed out after 60.04 seconds

Post by Box293 »

dgatlas wrote:Also when defining the service, there is a "Test Check Command" button, which also outputs correctly.
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.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
dgatlas
Posts: 16
Joined: Thu Dec 11, 2014 1:42 pm

Re: Service check timed out after 60.04 seconds

Post by dgatlas »

I've removed

Code: Select all

CURLOPT_COOKIEJAR       => $cookiejar
already, that was just for debug. The script seems to pass all that after I changed:

Code: Select all

CURLOPT_CONNECTTIMEOUT  => 30,
CURLOPT_TIMEOUT         => 30,
to

Code: Select all

CURLOPT_CONNECTTIMEOUT  => 10,
CURLOPT_TIMEOUT         => 10,
Now it doesn't display any output:

Code: Select all

(No output returned from plugin)
If I change the exit code to

Code: Select all

exit(1);
That change is reflected on the dashboard with a "Warning" status but still no output.
dgatlas
Posts: 16
Joined: Thu Dec 11, 2014 1:42 pm

Re: Service check timed out after 60.04 seconds

Post by dgatlas »

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.
Running as "nagios" still outputs correctly. Both using

Code: Select all

su nagios
and

Code: Select all

sudo -u nagios -H ./my_plugin ...
and yes I'm using "Schedule a forced immediate check".
Locked