[Nagiosplug-devel] check_http - Possible bug following redirects.

Aravind Gottipati aravind at freeshell.org
Wed Sep 20 08:31:49 CEST 2006


Hi,

I could not get check_http to follow http redirects.  It fails in cases
where the return headers have a line that starts with L like this
example below.

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
check_http -I 63.245.209.26  -H www.worldfirefoxday.com -f follow -v -u /
GET / HTTP/1.0
User-Agent: check_http/1.81 (nagios-plugins 1.4.1)
Host: www.worldfirefoxday.com

http://63.245.209.26:80/ is 439 characters
STATUS: HTTP/1.1 302 Found
**** HEADER ****
Date: Wed, 20 Sep 2006 06:12:31 GMT
Server: Apache/2.0.52 (Red Hat)
Last-Modified: Wed, 20 Sep 2006 06:12:31 GMT
Pragma: no-cache
Location: http://www.worldfirefoxday.com/en/
Content-Length: 0
Connection: close
Content-Type: text/html; charset=UTF-8
**** CONTENT ****

GET /Last-Modified: HTTP/1.0
User-Agent: check_http/1.81 (nagios-plugins 1.4.1)
Host: www.worldfirefoxday.com

http://www.worldfirefoxday.com:80/Last-Modified: is 483 characters
STATUS: HTTP/1.1 404 Not Found
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

The problem seems to be with line in the redir function in check_http.c
if (sscanf (pos, "%[Ll]%*[Oo]%*[Cc]%*[Aa]%*[Tt]%*[Ii]%*[Oo]%*[Nn]:%n", xx, &i) < 1) {

Checking the value of i seems to be a better indicator of the match than
the return value of sscanf.  The following patch fixes this problem for
me.

Aravind.


diff -uNr nagios-plugins-1.4.3/plugins/check_http.c nagios-plugins-1.4.3_new/plugins/check_http.c
--- nagios-plugins-1.4.3/plugins/check_http.c   2006-04-05 00:58:27.000000000 -0700
+++ nagios-plugins-1.4.3_new/plugins/check_http.c       2006-08-30 02:34:35.000000000 -0700
@@ -1073,9 +1073,8 @@
     die (STATE_UNKNOWN, _("Could not allocate url\n"));
 
   while (pos) {
-
-    if (sscanf (pos, "%[Ll]%*[Oo]%*[Cc]%*[Aa]%*[Tt]%*[Ii]%*[Oo]%*[Nn]:%n", xx, &i) < 1) {
-
+    sscanf (pos, "%[Ll]%*[Oo]%*[Cc]%*[Aa]%*[Tt]%*[Ii]%*[Oo]%*[Nn]:%n", xx, &i);
+    if (i == 0) {
       pos += (size_t) strcspn (pos, "\r\n");
       pos += (size_t) strspn (pos, "\r\n");
       if (strlen(pos) == 0) 




More information about the Devel mailing list