[icinga-checkins] icinga.org: icinga-nrpe/mfriedrich/fixes: * change check_nrpe exit code on socket errors to UNKNOWN via option -s ( Stephen Gran) #2113

git at icinga.org git at icinga.org
Thu Nov 24 16:09:29 CET 2011


Module: icinga-nrpe
Branch: mfriedrich/fixes
Commit: 35d19ac9c5bfbf7fced569948f7cb925599cd385
URL:    https://git.icinga.org/?p=icinga-nrpe.git;a=commit;h=35d19ac9c5bfbf7fced569948f7cb925599cd385

Author: Michael Friedrich <michael.friedrich at univie.ac.at>
Date:   Thu Nov 24 16:09:15 2011 +0100

* change check_nrpe exit code on socket errors to UNKNOWN via option -s (Stephen Gran) #2113

refs #2113

---

 Changelog        |    2 ++
 THANKS           |    1 +
 src/check_nrpe.c |   14 +++++++++++---
 3 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/Changelog b/Changelog
index f0cad0c..f0e4269 100644
--- a/Changelog
+++ b/Changelog
@@ -11,6 +11,7 @@ ENHANCEMENTS
 * enhancing NRPE for large output (Opsview Team) #377
 * create new init script and add install-init to Makefile #2069
 * add SSL x509 certificate support (breaks with existing anonymous DH mode!) #291
+* change check_nrpe exit code on socket errors to UNKNOWN via option -s (Stephen Gran) #2113
 
 FIXES
 
@@ -47,6 +48,7 @@ CHANGES
 	** privatekey_file=/etc/icinga-nrpe/server.key
 * add new check_nrpe options
 	** -C <certificate> -k <key> -r <ca-certificate>
+	** -s for UNKNOWN socket timeout exit state
 
 
 ***********************
diff --git a/THANKS b/THANKS
index ccfeeb5..10cbfe9 100644
--- a/THANKS
+++ b/THANKS
@@ -20,6 +20,7 @@ If we missed your name, let us know.
 * Assaf Flatto
 * Michael Friedrich
 * Ethan Galstad
+* Stephen Gran
 * Rene Klootwijk
 * Jacob L
 * Bret Lambert
diff --git a/src/check_nrpe.c b/src/check_nrpe.c
index 5be3e21..de1cdf6 100644
--- a/src/check_nrpe.c
+++ b/src/check_nrpe.c
@@ -29,6 +29,7 @@ char *server_name = NULL;
 char *command_name = NULL;
 int socket_timeout = DEFAULT_SOCKET_TIMEOUT;
 int timeout_return_code = STATE_CRITICAL;
+int socket_error_return_code=STATE_CRITICAL;
 int sd;
 
 char query[MAX_INPUT_BUFFER] = "";
@@ -86,11 +87,12 @@ int main(int argc, char **argv) {
 
 	if (result != OK || show_help == TRUE) {
 
-		printf("Usage: check_nrpe -H <host> -C <certificate> -k <key> -r <ca-certificate> [-n] [-u] [-p <port>] [-t <timeout>] [-c <command>] [-a <arglist...>]\n");
+		printf("Usage: check_nrpe -H <host> -C <certificate> -k <key> -r <ca-certificate> [-n] [-u] [-s] [-p <port>] [-t <timeout>] [-c <command>] [-a <arglist...>]\n");
 		printf("\n");
 		printf("Options:\n");
 		printf(" -n               = Do not use SSL\n");
-		printf(" -u               = Make socket timeouts return an UNKNOWN state instead of CRITICAL\n");
+		printf(" -u               = Make command timeouts return an UNKNOWN state instead of CRITICAL\n");
+		printf(" -s               = Make socket errors return an UNKNOWN state instead of CRITICAL\n");
 		printf(" <host>           = The address of the host running the NRPE daemon\n");
 		printf(" <certificate>    = The client certificate to use\n");
 		printf(" <ca-certificate> = The client certificate to use\n");
@@ -164,6 +166,8 @@ int main(int argc, char **argv) {
 
 	/* try to connect to the host at the given port number */
 	result = my_tcp_connect(server_name, server_port, &sd);
+	if (result==STATE_CRITICAL)
+		result=socket_error_return_code;
 
 #ifdef HAVE_SSL
 	/* do SSL handshake */
@@ -368,6 +372,7 @@ int process_arguments(int argc, char **argv) {
 		{"privatekey", required_argument, 0, 'k'},
 		{"args", required_argument, 0, 'a'},
 		{"no-ssl", no_argument, 0, 'n'},
+		{"socket-error-timeout", no_argument, 0, 's'},
 		{"unknown-timeout", no_argument, 0, 'u'},
 		{"timeout", required_argument, 0, 't'},
 		{"port", required_argument, 0, 'p'},
@@ -381,7 +386,7 @@ int process_arguments(int argc, char **argv) {
 	if (argc < 2)
 		return ERROR;
 
-	snprintf(optchars, MAX_INPUT_BUFFER, "H:C:k:r:c:a:t:p:nuhl");
+	snprintf(optchars, MAX_INPUT_BUFFER, "H:C:k:r:c:a:t:p:nsuhl");
 
 	while (1) {
 #ifdef HAVE_GETOPT_LONG
@@ -434,6 +439,9 @@ int process_arguments(int argc, char **argv) {
 		case 'n':
 			use_ssl = FALSE;
 			break;
+		case 's':
+			socket_error_return_code = STATE_UNKNOWN;
+			break;
 		case 'u':
 			timeout_return_code = STATE_UNKNOWN;
 			break;





More information about the icinga-checkins mailing list