|
@@ -3,7 +3,7 @@
|
|
|
* Nagios check_tcp plugin
|
|
* Nagios check_tcp plugin
|
|
|
*
|
|
*
|
|
|
* License: GPL
|
|
* License: GPL
|
|
|
-* Copyright (c) 1999-2008 Nagios Plugins Development Team
|
|
|
|
|
|
|
+* Copyright (c) 1999-2013 Nagios Plugins Development Team
|
|
|
*
|
|
*
|
|
|
* Description:
|
|
* Description:
|
|
|
*
|
|
*
|
|
@@ -277,25 +277,30 @@ main (int argc, char **argv)
|
|
|
status = realloc(status, len + i + 1);
|
|
status = realloc(status, len + i + 1);
|
|
|
memcpy(&status[len], buffer, i);
|
|
memcpy(&status[len], buffer, i);
|
|
|
len += i;
|
|
len += i;
|
|
|
|
|
+ status[len] = '\0';
|
|
|
|
|
|
|
|
/* stop reading if user-forced */
|
|
/* stop reading if user-forced */
|
|
|
if (maxbytes && len >= maxbytes)
|
|
if (maxbytes && len >= maxbytes)
|
|
|
break;
|
|
break;
|
|
|
|
|
+
|
|
|
|
|
+ if ((match = np_expect_match(status,
|
|
|
|
|
+ server_expect,
|
|
|
|
|
+ server_expect_count,
|
|
|
|
|
+ match_flags)) != NP_MATCH_RETRY)
|
|
|
|
|
+ break;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/* no data when expected, so return critical */
|
|
/* no data when expected, so return critical */
|
|
|
if (len == 0)
|
|
if (len == 0)
|
|
|
die (STATE_CRITICAL, _("No data received from host\n"));
|
|
die (STATE_CRITICAL, _("No data received from host\n"));
|
|
|
|
|
|
|
|
- /* force null-termination and strip whitespace from end of output */
|
|
|
|
|
- status[len--] = '\0';
|
|
|
|
|
/* print raw output if we're debugging */
|
|
/* print raw output if we're debugging */
|
|
|
if(flags & FLAG_VERBOSE)
|
|
if(flags & FLAG_VERBOSE)
|
|
|
printf("received %d bytes from host\n#-raw-recv-------#\n%s\n#-raw-recv-------#\n",
|
|
printf("received %d bytes from host\n#-raw-recv-------#\n%s\n#-raw-recv-------#\n",
|
|
|
(int)len + 1, status);
|
|
(int)len + 1, status);
|
|
|
- while(isspace(status[len])) status[len--] = '\0';
|
|
|
|
|
-
|
|
|
|
|
- match = np_expect_match(status, server_expect, server_expect_count, match_flags);
|
|
|
|
|
|
|
+ /* strip whitespace from end of output */
|
|
|
|
|
+ while(--len > 0 && isspace(status[len]))
|
|
|
|
|
+ status[len] = '\0';
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (server_quit != NULL) {
|
|
if (server_quit != NULL) {
|
|
@@ -315,7 +320,7 @@ main (int argc, char **argv)
|
|
|
result = STATE_WARNING;
|
|
result = STATE_WARNING;
|
|
|
|
|
|
|
|
/* did we get the response we hoped? */
|
|
/* did we get the response we hoped? */
|
|
|
- if(match == FALSE && result != STATE_CRITICAL)
|
|
|
|
|
|
|
+ if(match != NP_MATCH_SUCCESS && result != STATE_CRITICAL)
|
|
|
result = expect_mismatch_state;
|
|
result = expect_mismatch_state;
|
|
|
|
|
|
|
|
/* reset the alarm */
|
|
/* reset the alarm */
|
|
@@ -326,10 +331,10 @@ main (int argc, char **argv)
|
|
|
* the response we were looking for. if-else */
|
|
* the response we were looking for. if-else */
|
|
|
printf("%s %s - ", SERVICE, state_text(result));
|
|
printf("%s %s - ", SERVICE, state_text(result));
|
|
|
|
|
|
|
|
- if(match == FALSE && len && !(flags & FLAG_HIDE_OUTPUT))
|
|
|
|
|
|
|
+ if(match != NP_MATCH_SUCCESS && len && !(flags & FLAG_HIDE_OUTPUT))
|
|
|
printf("Unexpected response from host/socket: %s", status);
|
|
printf("Unexpected response from host/socket: %s", status);
|
|
|
else {
|
|
else {
|
|
|
- if(match == FALSE)
|
|
|
|
|
|
|
+ if(match != NP_MATCH_SUCCESS)
|
|
|
printf("Unexpected response from host/socket on ");
|
|
printf("Unexpected response from host/socket on ");
|
|
|
else
|
|
else
|
|
|
printf("%.3f second response time on ", elapsed_time);
|
|
printf("%.3f second response time on ", elapsed_time);
|
|
@@ -339,13 +344,13 @@ main (int argc, char **argv)
|
|
|
printf("socket %s", server_address);
|
|
printf("socket %s", server_address);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (match != FALSE && !(flags & FLAG_HIDE_OUTPUT) && len)
|
|
|
|
|
|
|
+ if (match == NP_MATCH_SUCCESS && !(flags & FLAG_HIDE_OUTPUT) && len)
|
|
|
printf (" [%s]", status);
|
|
printf (" [%s]", status);
|
|
|
|
|
|
|
|
/* perf-data doesn't apply when server doesn't talk properly,
|
|
/* perf-data doesn't apply when server doesn't talk properly,
|
|
|
* so print all zeroes on warn and crit. Use fperfdata since
|
|
* so print all zeroes on warn and crit. Use fperfdata since
|
|
|
* localisation settings can make different outputs */
|
|
* localisation settings can make different outputs */
|
|
|
- if(match == FALSE)
|
|
|
|
|
|
|
+ if(match != NP_MATCH_SUCCESS)
|
|
|
printf ("|%s",
|
|
printf ("|%s",
|
|
|
fperfdata ("time", elapsed_time, "s",
|
|
fperfdata ("time", elapsed_time, "s",
|
|
|
(flags & FLAG_TIME_WARN ? TRUE : FALSE), 0,
|
|
(flags & FLAG_TIME_WARN ? TRUE : FALSE), 0,
|