Page 1 of 2

(No output returned from plugin)

PostPosted: Tue May 12, 2020 4:25 pm
by markoz88
Hi everyone,

i got a little issue with a Script that made on PHP, thes cript works fine in te command line but when i put in Nagios i retrieve the message in the descripciĆ³n: (No output returned from plugin), but the script works perfectly and shows the information that needed, what could be the problem here?

Re: (No output returned from plugin)

PostPosted: Tue May 12, 2020 4:48 pm
by ssax
Please post your service and command definitions, attach the plugin as well so that we can debug further.

Thank you

Re: (No output returned from plugin)

PostPosted: Tue May 12, 2020 4:53 pm
by cdienger
It could be a misconfiguration of the service or command definition. What do those look like? What does the full command look like when you run the script from the command line?

Re: (No output returned from plugin)

PostPosted: Tue May 12, 2020 5:15 pm
by markoz88
ssax wrote:Please post your service and command definitions, attach the plugin as well so that we can debug further.

Thank you


Command:

define command {
command_name check_springboot
command_line $USER1$/check_springboot.php --url $ARG1$
}

Service:


define service {
use local-service
host_name localhost
service_description Servicios Cobro QR
check_command check_springboot!192.168.2.196:8080/actuator/health
#register 0
}

Re: (No output returned from plugin)

PostPosted: Tue May 12, 2020 5:19 pm
by markoz88
cdienger wrote:It could be a misconfiguration of the service or command definition. What do those look like? What does the full command look like when you run the script from the command line?


The pluggin is designed to Monitoring springboot actuator health services by cURL and get the Json response; that have the status of services.

Code: Select all
#!/usr/bin/php

<?php

define('STATE_OK', 0);
define('STATE_WARNING', 1);
define('STATE_CRITICAL', 2);
define('STATE_UNKNOWN', 3);


$url_aux = getopt(null, ["url:"]);

if ($url_aux == NULL){
    echo "Error no has agregado la URL";
$url = NULL;
exit (STATE_UNKNOWN);
}

$url = $url_aux['url'];

$ch = curl_init($url);

#curl_setopt($ch, CURLOPT_URL, '$url');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Content-Type: application/json',
    'Accept: application/json'
));

$result = curl_exec($ch);

if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
}

$info = curl_getinfo ($ch);
$code = $info['http_code'];


curl_close($ch);

#$json = json_decode($result, true);
#print_r($json);

echo "\nEstado de Servicios\n";

class JSON {
    public static function prettify($json)
    {
        $array = json_decode($json, true);
        $json = json_encode($array, JSON_PRETTY_PRINT);
        return $json;
    }

}


$jsonString = $result;

echo JSON::prettify($jsonString);


if ( $code !== NULL ) {
        switch($code){
                case 200:
                    $text = "Servicios OK";
                    echo "\n$text\n";
                    exit(STATE_OK);
                case 503:
                    $text = "Servicio DOWN";
                    echo "$text\n";
                    exit(STATE_CRITICAL);
                default:
                    $text = "UKNOWN";
                    echo "$text\n";
                    exit(STATE_UNKNOWN);
                    break;
                }
}

?>

Re: (No output returned from plugin)

PostPosted: Tue May 12, 2020 5:22 pm
by markoz88
This is the view in Nagios Service:


Current Status: OK (for 0d 1h 3m 46s)
Status Information: (No output returned from plugin)

Estado de Servicios
{
"status": "UP",
"components": {
"diskSpace": {
"status": "UP",
"details": {
"total": 499462959104,
"free": 340257636352,
"threshold": 10485760
}
},
"ping": {
"status": "UP"
}
}
}
Servicios OK

Re: (No output returned from plugin)

PostPosted: Mon Jun 15, 2020 6:16 am
by maexware-dennis
Hello,

I got the exact same issue in my php script. Have you found any solution for it yet?

Re: (No output returned from plugin)

PostPosted: Mon Jul 06, 2020 3:51 pm
by scottwilkerson
I haven't dug into your full script, but I see this right at the top
Code: Select all
#!/usr/bin/php

<?php

the blank line is going to give you a blank line of output right at the beginning of the script which is what Nagios will see as the first link of output and CANNOT be blank

I would recommend changing that to
Code: Select all
#!/usr/bin/php
<?php

Re: (No output returned from plugin)

PostPosted: Fri Jul 17, 2020 9:20 am
by maexware-dennis
scottwilkerson wrote:I haven't dug into your full script, but I see this right at the top
Code: Select all
#!/usr/bin/php

<?php

the blank line is going to give you a blank line of output right at the beginning of the script which is what Nagios will see as the first link of output and CANNOT be blank

I would recommend changing that to
Code: Select all
#!/usr/bin/php
<?php



This fixed it for me. Thank you :)

Re: (No output returned from plugin)

PostPosted: Fri Jul 17, 2020 9:24 am
by maexware-dennis
scottwilkerson wrote:I haven't dug into your full script, but I see this right at the top
Code: Select all
#!/usr/bin/php

<?php

the blank line is going to give you a blank line of output right at the beginning of the script which is what Nagios will see as the first link of output and CANNOT be blank

I would recommend changing that to
Code: Select all
#!/usr/bin/php
<?php


This fixed it for me. Thank you :)