NRPE patch

Jason Martin jhmartin at toger.us
Mon Jul 26 17:06:10 CEST 2004


On Sun, Jul 25, 2004 at 11:47:49AM +0200, Andreas Ericsson wrote:
> 
> 
> Jason Martin wrote:
> >The attached patch against nrpe-cvs HEAD does the following:
> Can you please resubmit the patch in a unified diff format (i.e. diff 
> -urN ....)?
I've attached the regenerated patch, crated with diff -urN

-Jason Martin
-- 
Shift happpens. - Doppler
This message is PGP/MIME signed.
-------------- next part --------------
diff -urN nrpe-cvs/CVS/Entries plugins_build/nrpe-2.1/CVS/Entries
--- nrpe-cvs/CVS/Entries	Wed Dec 31 16:00:00 1969
+++ plugins_build/nrpe-2.1/CVS/Entries	Thu Jul 22 10:52:58 2004
@@ -0,0 +1,20 @@
+D/contrib////
+D/include////
+D/sample-config////
+D/src////
+/LEGAL/1.1/Tue Jul  9 04:42:03 2002//
+/Makefile.in/1.1/Sat Nov  1 19:14:17 2003//
+/README/1.1/Wed Oct 15 23:14:25 2003//
+/README.SSL/1.1/Fri Mar 14 02:37:05 2003//
+/SECURITY/1.1/Wed Oct 15 23:14:25 2003//
+/configure/1.1/Sat Mar  6 23:17:42 2004//
+/configure.in/1.1/Sat Mar  6 23:17:42 2004//
+/init-script.debian.in/1.1/Sat Mar  6 23:17:42 2004//
+/init-script.freebsd.in/1.1/Wed Jan  8 01:11:36 2003//
+/init-script.in/1.1/Wed Jan  8 01:11:36 2003//
+/init-script.suse.in/1.1/Sat Nov  1 19:14:17 2003//
+/install-sh/1.1/Sat Jun 23 17:02:57 2001//
+/nrpe.spec/1.1/Wed Nov 12 23:37:48 2003//
+/subst.in/1.1/Tue Dec 31 06:03:33 2002//
+/update-version/1.1/Wed Oct 15 23:14:25 2003//
+/Changelog/1.2/Thu Jul 22 17:52:01 2004//
diff -urN nrpe-cvs/CVS/Repository plugins_build/nrpe-2.1/CVS/Repository
--- nrpe-cvs/CVS/Repository	Wed Dec 31 16:00:00 1969
+++ plugins_build/nrpe-2.1/CVS/Repository	Thu Jul 22 10:13:18 2004
@@ -0,0 +1 @@
+plugins_build/nrpe-2.1
diff -urN nrpe-cvs/CVS/Root plugins_build/nrpe-2.1/CVS/Root
--- nrpe-cvs/CVS/Root	Wed Dec 31 16:00:00 1969
+++ plugins_build/nrpe-2.1/CVS/Root	Thu Jul 22 10:13:18 2004
@@ -0,0 +1 @@
+:pserver:localhost:/home/cvs
diff -urN nrpe-cvs/Changelog plugins_build/nrpe-2.1/Changelog
--- nrpe-cvs/Changelog	Sat Mar  6 15:17:42 2004
+++ plugins_build/nrpe-2.1/Changelog	Thu Jul 22 10:58:44 2004
@@ -13,6 +13,12 @@
 - SSL protocol used is now limited to TLSv1
 - Any output from plugins after first line is now ignored before
   plugin process is closed
+- Close STDERR before executing plugin through inetd, reduce CRC32 errors
+- Improve wording of error messages (Jason Martin)
+- Return more error message through to check_nrpe if a valid 
+  connection exists instead of bailing out (Jason Martin)
+- Return error message for plugin output of only "\n" (Jason Martin)
+
 
 
 2.0 - 09/08/2003
diff -urN nrpe-cvs/contrib/CVS/Entries plugins_build/nrpe-2.1/contrib/CVS/Entries
--- nrpe-cvs/contrib/CVS/Entries	Wed Dec 31 16:00:00 1969
+++ plugins_build/nrpe-2.1/contrib/CVS/Entries	Thu Jul 22 10:16:07 2004
@@ -0,0 +1,3 @@
+/README.nrpe_check_control/1.1/Fri Oct 24 01:00:40 2003//
+/nrpe_check_control.c/1.1/Fri Feb 22 01:15:34 2002//
+D
diff -urN nrpe-cvs/contrib/CVS/Repository plugins_build/nrpe-2.1/contrib/CVS/Repository
--- nrpe-cvs/contrib/CVS/Repository	Wed Dec 31 16:00:00 1969
+++ plugins_build/nrpe-2.1/contrib/CVS/Repository	Thu Jul 22 10:15:04 2004
@@ -0,0 +1 @@
+plugins_build/nrpe-2.1/contrib
diff -urN nrpe-cvs/contrib/CVS/Root plugins_build/nrpe-2.1/contrib/CVS/Root
--- nrpe-cvs/contrib/CVS/Root	Wed Dec 31 16:00:00 1969
+++ plugins_build/nrpe-2.1/contrib/CVS/Root	Thu Jul 22 10:15:04 2004
@@ -0,0 +1 @@
+:pserver:localhost:/home/cvs
diff -urN nrpe-cvs/include/CVS/Entries plugins_build/nrpe-2.1/include/CVS/Entries
--- nrpe-cvs/include/CVS/Entries	Wed Dec 31 16:00:00 1969
+++ plugins_build/nrpe-2.1/include/CVS/Entries	Thu Jul 22 10:39:13 2004
@@ -0,0 +1,6 @@
+/config.h.in/1.1/Wed Nov 12 23:37:48 2003//
+/nrpe.h/1.1/Wed Oct 15 23:21:23 2003//
+/utils.h/1.1/Wed Oct 15 23:21:23 2003//
+/common.h/1.2/Thu Jul 22 17:19:01 2004//
+/dh.h/1.2/Thu Jul 22 17:21:42 2004//
+D
diff -urN nrpe-cvs/include/CVS/Repository plugins_build/nrpe-2.1/include/CVS/Repository
--- nrpe-cvs/include/CVS/Repository	Wed Dec 31 16:00:00 1969
+++ plugins_build/nrpe-2.1/include/CVS/Repository	Thu Jul 22 10:15:16 2004
@@ -0,0 +1 @@
+plugins_build/nrpe-2.1/include
diff -urN nrpe-cvs/include/CVS/Root plugins_build/nrpe-2.1/include/CVS/Root
--- nrpe-cvs/include/CVS/Root	Wed Dec 31 16:00:00 1969
+++ plugins_build/nrpe-2.1/include/CVS/Root	Thu Jul 22 10:15:16 2004
@@ -0,0 +1 @@
+:pserver:localhost:/home/cvs
diff -urN nrpe-cvs/include/common.h plugins_build/nrpe-2.1/include/common.h
--- nrpe-cvs/include/common.h	Sat Mar  6 15:17:42 2004
+++ plugins_build/nrpe-2.1/include/common.h	Thu Jul 22 10:42:04 2004
@@ -24,7 +24,7 @@
 #include "config.h"
 
 #define PROGRAM_VERSION "2.1"
-#define MODIFICATION_DATE "01-19-2004"
+#define MODIFICATION_DATE "7-22-2004"
 
 #define OK		0
 #define ERROR		-1
diff -urN nrpe-cvs/sample-config/CVS/Entries plugins_build/nrpe-2.1/sample-config/CVS/Entries
--- nrpe-cvs/sample-config/CVS/Entries	Wed Dec 31 16:00:00 1969
+++ plugins_build/nrpe-2.1/sample-config/CVS/Entries	Thu Jul 22 10:16:07 2004
@@ -0,0 +1,3 @@
+/nrpe.cfg.in/1.1/Wed Oct 15 23:21:23 2003//
+/nrpe.xinetd.in/1.1/Wed Oct 15 23:21:23 2003//
+D
diff -urN nrpe-cvs/sample-config/CVS/Repository plugins_build/nrpe-2.1/sample-config/CVS/Repository
--- nrpe-cvs/sample-config/CVS/Repository	Wed Dec 31 16:00:00 1969
+++ plugins_build/nrpe-2.1/sample-config/CVS/Repository	Thu Jul 22 10:15:39 2004
@@ -0,0 +1 @@
+plugins_build/nrpe-2.1/sample-config
diff -urN nrpe-cvs/sample-config/CVS/Root plugins_build/nrpe-2.1/sample-config/CVS/Root
--- nrpe-cvs/sample-config/CVS/Root	Wed Dec 31 16:00:00 1969
+++ plugins_build/nrpe-2.1/sample-config/CVS/Root	Thu Jul 22 10:15:39 2004
@@ -0,0 +1 @@
+:pserver:localhost:/home/cvs
diff -urN nrpe-cvs/src/CVS/Entries plugins_build/nrpe-2.1/src/CVS/Entries
--- nrpe-cvs/src/CVS/Entries	Wed Dec 31 16:00:00 1969
+++ plugins_build/nrpe-2.1/src/CVS/Entries	Thu Jul 22 10:52:58 2004
@@ -0,0 +1,5 @@
+/Makefile.in/1.1/Wed Oct 15 23:14:26 2003//
+/utils.c/1.1/Wed Jul 21 16:22:43 2004//
+/nrpe.c/1.2/Thu Jul 22 17:33:16 2004//
+/check_nrpe.c/1.2/Thu Jul 22 17:50:00 2004//
+D
diff -urN nrpe-cvs/src/CVS/Repository plugins_build/nrpe-2.1/src/CVS/Repository
--- nrpe-cvs/src/CVS/Repository	Wed Dec 31 16:00:00 1969
+++ plugins_build/nrpe-2.1/src/CVS/Repository	Thu Jul 22 10:15:50 2004
@@ -0,0 +1 @@
+plugins_build/nrpe-2.1/src
diff -urN nrpe-cvs/src/CVS/Root plugins_build/nrpe-2.1/src/CVS/Root
--- nrpe-cvs/src/CVS/Root	Wed Dec 31 16:00:00 1969
+++ plugins_build/nrpe-2.1/src/CVS/Root	Thu Jul 22 10:15:50 2004
@@ -0,0 +1 @@
+:pserver:localhost:/home/cvs
diff -urN nrpe-cvs/src/check_nrpe.c plugins_build/nrpe-2.1/src/check_nrpe.c
--- nrpe-cvs/src/check_nrpe.c	Thu May 20 15:41:02 2004
+++ plugins_build/nrpe-2.1/src/check_nrpe.c	Thu Jul 22 10:50:00 2004
@@ -85,7 +85,7 @@
 		printf("Usage: check_nrpe -H <host> [-n] [-p <port>] [-t <timeout>] [-c <command>] [-a <arglist...>]\n");
 		printf("\n");
 		printf("Options:\n");
-		printf(" -n         = Do no use SSL\n");
+		printf(" -n         = Do not use SSL\n");
 		printf(" <host>     = The address of the host running the NRPE daemon\n");
 		printf(" [port]     = The port on which the daemon is running (default=%d)\n",DEFAULT_SERVER_PORT);
 		printf(" [timeout]  = Number of seconds before connection times out (default=%d)\n",DEFAULT_SOCKET_TIMEOUT);
@@ -415,7 +415,7 @@
 
 void alarm_handler(int sig){
 
-	printf("CHECK_NRPE: Socket timeout after %d seconds.\n",socket_timeout);
+	printf("CHECK_NRPE: Socket timeout after %d seconds, either host is unreachable or plugin exceeded max runtime.\n",socket_timeout);
 
 	exit(STATE_CRITICAL);
         }
diff -urN nrpe-cvs/src/nrpe.c plugins_build/nrpe-2.1/src/nrpe.c
--- nrpe-cvs/src/nrpe.c	Thu May 20 15:41:02 2004
+++ plugins_build/nrpe-2.1/src/nrpe.c	Thu Jul 22 10:33:16 2004
@@ -59,6 +59,7 @@
 char    *command_name=NULL;
 char    *macro_argv[MAX_COMMAND_ARGUMENTS];
 
+char    *error_msg;
 char    config_file[MAX_INPUT_BUFFER]="nrpe.cfg";
 int     server_port=DEFAULT_SERVER_PORT;
 char    server_address[16]="0.0.0.0";
@@ -863,30 +864,37 @@
 	if(validate_request(&receive_packet)==ERROR){
 
 		/* log an error */
-		syslog(LOG_ERR,"Client request was invalid, bailing out...");
-
+		syslog(LOG_ERR,"Client request was invalid, skipping execution...");
 		/* free memory */
 		free(command_name);
 		command_name=NULL;
 		for(x=0;x<MAX_COMMAND_ARGUMENTS;x++){
 			free(macro_argv[x]);
 			macro_argv[x]=NULL;
-	                }
+		}
 
+		/* If we got an error code but no text then just close the connection */
+	   if (error_msg == NULL) {
 #ifdef HAVE_SSL
 		SSL_shutdown(ssl);
 		SSL_free(ssl);
 #endif
 
 		return;
-	        }
-
+      }
+	}
 	/* log info to syslog facility */
 	if(debug==TRUE)
 		syslog(LOG_DEBUG,"Host is asking for command '%s' to be run...",receive_packet.buffer);
 
+	/* If validate_request populated an error message, send just that */
+	if (error_msg != NULL) {
+		snprintf(buffer,sizeof(buffer),"%s",error_msg);
+		buffer[sizeof(buffer)-1]='\x0';
+		result=STATE_UNKNOWN;
+	}
 	/* if this is the version check command, just spew it out */
-	if(!strcmp(command_name,NRPE_HELLO_COMMAND)){
+	else if(!strcmp(command_name,NRPE_HELLO_COMMAND)){
 
 		snprintf(buffer,sizeof(buffer),"NRPE v%s",PROGRAM_VERSION);
 		buffer[sizeof(buffer)-1]='\x0';
@@ -935,8 +943,10 @@
 			/* see if the command timed out */
 			if(early_timeout==TRUE)
 				snprintf(buffer,sizeof(buffer)-1,"NRPE: Command timed out after %d seconds\n",command_timeout);
+			else if(!strcmp(buffer,"\n"))
+				snprintf(buffer,sizeof(buffer)-1,"NRPE: Plugin returned blank line, plugin may have failed\n");
 			else if(!strcmp(buffer,""))
-				snprintf(buffer,sizeof(buffer)-1,"NRPE: Unable to read output\n");
+				snprintf(buffer,sizeof(buffer)-1,"NRPE: Unable to read output, plugin may be missing or have failed\n");
 
 			buffer[sizeof(buffer)-1]='\x0';
 
@@ -1355,6 +1365,7 @@
 	/* make sure request doesn't contain nasties */
 	if(contains_nasty_metachars(pkt->buffer)==TRUE){
 		syslog(LOG_ERR,"Error: Request contained illegal metachars!");
+		error_msg="NRPE Error: Request contained illegal metachars!";
 		return ERROR;
 	        }
 
@@ -1362,11 +1373,13 @@
 	if(strchr(pkt->buffer,'!')){
 #ifdef ENABLE_COMMAND_ARGUMENTS
 		if(allow_arguments==FALSE){
-			syslog(LOG_ERR,"Error: Request contained command arguments, but argument option is not enabled!");
+			syslog(LOG_ERR,"Error: Request contained command arguments, but argument option is not enabled in configuration!");
+			error_msg="NRPE Error: Request contained command arguments, but argument option is not enabled in configuration!";
 			return ERROR;
 	                }
 #else
-		syslog(LOG_ERR,"Error: Request contained command arguments!");
+		syslog(LOG_ERR,"Error: Request contained command arguments but NRPE is not compiled with argument support!");
+		error_msg="NRPE Error: Request contained command arguments, but NRPE is not compiled with argument support!";
 		return ERROR;
 #endif
 	        }
@@ -1398,6 +1411,7 @@
 			        }
 			if(!strcmp(macro_argv[x],"")){
 				syslog(LOG_ERR,"Error: Request contained an empty command argument");
+				error_msg="NRPE Error: Request contained an empty command argument";
 				return ERROR;
 		                }
 		        }
diff -urN nrpe-cvs/src/utils.c plugins_build/nrpe-2.1/src/utils.c
--- nrpe-cvs/src/utils.c	Wed Oct 15 16:14:27 2003
+++ plugins_build/nrpe-2.1/src/utils.c	Wed Jul 21 09:22:43 2004
@@ -136,7 +136,7 @@
 		/* else do a DNS lookup */
 		hp=gethostbyname((const char *)host_name);
 		if(hp==NULL){
-			printf("Invalid host name '%s'\n",host_name);
+			printf("CHECK_NRPE: Error contacting remote host. Invalid host name '%s'\n",host_name);
 			return STATE_UNKNOWN;
 		        }
 
@@ -145,14 +145,14 @@
 
 	/* map transport protocol name to protocol number */
 	if(((ptrp=getprotobyname(proto)))==NULL){
-		printf("Cannot map \"%s\" to protocol number\n",proto);
+		printf("CHECK_NRPE: Error contacting remote host. Cannot map \"%s\" to protocol number\n",proto);
 		return STATE_UNKNOWN;
 	        }
 
 	/* create a socket */
 	*sd=socket(PF_INET,(!strcmp(proto,"udp"))?SOCK_DGRAM:SOCK_STREAM,ptrp->p_proto);
 	if(*sd<0){
-		printf("Socket creation failed\n");
+		printf("CHECK_NRPE: Error contacting remote host. Socket creation failed\n");
 		return STATE_UNKNOWN;
 	        }
 
@@ -161,16 +161,16 @@
 	if(result<0){
 		switch(errno){  
 		case ECONNREFUSED:
-			printf("Connection refused by host\n");
+			printf("CHECK_NRPE: Error contacting remote host. Connection refused by host\n");
 			break;
 		case ETIMEDOUT:
-			printf("Timeout while attempting connection\n");
+			printf("CHECK_NRPE: Error contacting remote host. Timeout while attempting connection\n");
 			break;
 		case ENETUNREACH:
-			printf("Network is unreachable\n");
+			printf("CHECK_NRPE: Error contacting remote host. Network is unreachable\n");
 			break;
 		default:
-			printf("Connection refused or timed out\n");
+			printf("CHECK_NRPE: Error contacting remote host. Connection refused or timed out\n");
 		        }
 
 		return STATE_CRITICAL;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 211 bytes
Desc: not available
URL: <https://www.monitoring-lists.org/archive/developers/attachments/20040726/64593cd6/attachment.sig>


More information about the Developers mailing list