[Nagiosplug-devel] check_tcp patch

Ollie Cook ollie at uk.clara.net
Thu Dec 9 05:32:18 CET 2004


Hi,

check_tcp in 1.4.0alpha2 uses strstr(3) to determine whether or not the
expected string appears in the server's output.

Using check_nntp this causes unexpected behaviour under Diablo. For example
if I use:

  check_nntp -H $HOSTADDRESS$

I get a false positive because the server's output might be:

  502 obfuscated.hostname: Transfer permission - newmaster at domain.com (DIABLO 5-CUR-20031207-02)

check_nntp is expecting a response of "200" or "201" and it's getting it (from
the Diablo version timestamp).

I've attached a short patch which checks for the expected string at the start
of the server's output. It also prints out what the response was in the error
message which will help people in debugging why their checks are failing.

I realise that this is a change of behaviour the people might not expect if
they're used to the match happening anywhere in a line. In that case, might I
suggest this be added as another option (e.g. -E ?)

Furthermore I've changed the state from warning to critical because I think not
getting the output you expect from a service is very serious. Do others agree?
Perhaps this also ought to be configurable?

Cheers,

Ollie

-- 
Ollie Cook         Systems Architect, Claranet UK
ollie at uk.clara.net               +44 20 7685 8065
-------------- next part --------------
--- check_tcp.c.orig	Thu Dec  9 13:01:37 2004
+++ check_tcp.c	Wed Dec  8 14:23:10 2004
@@ -333,8 +333,8 @@
 				if (verbose)
 					printf ("%d %d\n", i, (int)server_expect_count);
 				if (i >= (int)server_expect_count)
-					die (STATE_WARNING, _("Invalid response from host\n"));
-				if (strstr (status, server_expect[i]))
+					die (STATE_CRITICAL, _("Unexpected response from host: %s\n"), status);
+				if (strncmp(status, server_expect[i], strlen(server_expect[i])) == 0)
 					break;
 			}
 		}


More information about the Devel mailing list