regilero / check_phpfpm_status

Nagios check for php-fpm status report
GNU General Public License v3.0
39 stars 19 forks source link

Use of uninitialized value $webcontent #12

Closed jkroepke closed 9 years ago

jkroepke commented 9 years ago

Hi!

I got this error on execute this check:

# ./check_fpm -H 127.0.0.1 -s localhost -u /fpm_status -d
Use of uninitialized value $o_warn_thresold in concatenation (.) or string at ./check_fpm line 190.

Debug thresolds:
Use of uninitialized value $o_crit_thresold in concatenation (.) or string at ./check_fpm line 191.
Warning: () => Min Idle: -1 Max Reached :-1 MaxQueue: -1
Critical () => : Min Idle: -1 Max Reached: -1 MaxQueue : -1

DEBUG: HTTP url:
http://localhost/fpm_status
DEBUG: HTTP request:
IP used (better if it's an IP):127.0.0.1
GET http://localhost/fpm_status
Host: localhost

DEBUG: HTTP response:200 OK
text/plain;charset=-1
Use of uninitialized value $webcontent in print at ./check_fpm line 292.
Use of uninitialized value $webcontent in pattern match (m//) at ./check_fpm line 313.
Use of uninitialized value $webcontent in pattern match (m//) at ./check_fpm line 320.
Use of uninitialized value $webcontent in pattern match (m//) at ./check_fpm line 326.
Use of uninitialized value $webcontent in pattern match (m//) at ./check_fpm line 332.
Use of uninitialized value $webcontent in pattern match (m//) at ./check_fpm line 338.
Use of uninitialized value $webcontent in pattern match (m//) at ./check_fpm line 344.
Use of uninitialized value $webcontent in pattern match (m//) at ./check_fpm line 350.
Use of uninitialized value $webcontent in pattern match (m//) at ./check_fpm line 356.
Use of uninitialized value $webcontent in pattern match (m//) at ./check_fpm line 362.
Use of uninitialized value $webcontent in pattern match (m//) at ./check_fpm line 368.
Use of uninitialized value $webcontent in pattern match (m//) at ./check_fpm line 374.

DEBUG Parse results => Pool:
AcceptedConn:0
ActiveProcesses:0 TotalProcesses :0 IdleProcesses :0
MaxActiveProcesses :0 MaxChildrenReached :0
ListenQueue :0 ListenQueueLen : 0 MaxListenQueue: 0

Debug: data from temporary file:
LastUptime: 0
 LastAcceptedConn: 0
 LastMaxChildrenReached: 0
 LastMaxListenQueue: 0

PHP-FPM OK - , 0.037 sec. response time, Busy/Idle 0/0, (max: 0, reached: 0), ReqPerSec 0.0, Queue 0 (len: 0, reached: 0)|Idle=0 Busy=0 MaxProcesses=0 MaxProcessesReach=0 Queue=0 MaxQueueReach=0 QueueLen=0 ReqPerSec=0.000000

This php-fpm status side work with curl:

# curl localhost/fpm_status
pool:                 php
process manager:      dynamic
start time:           21/Jul/2015:19:39:52 +0200
start since:          1362
accepted conn:        171
listen queue:         0
max listen queue:     0
listen queue len:     0
idle processes:       1
active processes:     1
total processes:      2
max active processes: 1
max children reached: 0
slow requests:        0

I'm using Ubuntu 14.04 LTS and php5-fpm 5.5.9.

regilero commented 9 years ago

To remove the first warnings you can assign a critical and warning thresolds with options -w and -c. But the script should manage better this case (no thresolds + debug).

Now the undefined $webcontent is very strange.

You have $response->is_success, $response->status_line and $response->header('Content-Type') but $response->decoded_content is null...

it comes from:

my $webcontent = undef;
if ($response->is_success) {
    $webcontent=$response->decoded_content;
    if (defined ($o_debug)) {
        print "\nDEBUG: HTTP response:";
        print $response->status_line;
        print "\n".$response->header('Content-Type');
        print "\n";
        print $webcontent;
    }

Looking at the documentation here: http://search.cpan.org/~ether/HTTP-Message-6.10/lib/HTTP/Message.pm#mess for 'decoded_content', it seems that the return may be undef if aContent-Encoding or charset is not supported.

Could you try with :

$webcontent=$response->decoded_content( charset_strict=>1, raise_error => TRUE);

or:

$webcontent=$response->decoded_content( charset_strict=>1, raise_error => TRUE, alt_charset => none);

There's certainly somethig strange in your HTTP response, and we could use it to make the script more robust to strange things.

jkroepke commented 9 years ago

Hi,

the Problem ist this:

Content-Type: text/plain;charset=-1

I have a installed nginx. nginx overrides now the header with text/plain;charset=utf8 and it works perfertly, but it is just a workaround.

php5-fpm looks like to send this invalid? Content-Type ..

About your changes:

I removed the workaround on my nginx to test the changes, here are the results:

./check_phpfpm_status
Bareword "TRUE" not allowed while "strict subs" in use at ./check_phpfpm_status line 286.
Bareword "none" not allowed while "strict subs" in use at ./check_phpfpm_status line 286.

When I remove the "use strict;" line, got this error(first change):

Unknown encoding '-1' at /usr/share/perl5/HTTP/Message.pm line 377.
        ...propagated at /usr/share/perl5/HTTP/Message.pm line 392.
 at ./check_phpfpm_status line 286.

Second change works great!

Unquoted string "none" may clash with future reserved word at ./check_phpfpm_status line 286.
PHP-FPM OK - php, 0.056 sec. response time, Busy/Idle 1/7, (max: 8, reached: 0), ReqPerSec 0.0, Queue 0 (len: 0, reached: 0)|Idle=7 Busy=1 MaxProcesses=8 MaxProcessesReach=0 Queue=0 MaxQueueReach=0 QueueLen=0 ReqPerSec=0.000000
regilero commented 9 years ago

Ok, it seems we should use the alt_charset keyword, I'm not a PERL expert, seems that my example code was pretty wrong, try with quotes around none and TRUE.

regilero commented 9 years ago

So this should be the right code, isn'it ?

$webcontent=$response->decoded_content( charset_strict=>1, raise_error => 1, alt_charset => 'none' );
jkroepke commented 9 years ago

I have no knowledge about perl. What about the strict subs error?

regilero commented 9 years ago

The warnings are because the quotes are required. I committed a change, can you tests withthis version?

jkroepke commented 9 years ago

Works perfectly now,

Thank you.

regilero commented 9 years ago

Thanks for testing.