Sfoglia il codice sorgente

Syntax changes, new init scripts for Debian and FreeBSD

Ethan Galstad 23 anni fa
parent
commit
f5ba65444c
14 ha cambiato i file con 218 aggiunte e 63 eliminazioni
  1. 3 0
      Changelog
  2. 2 2
      LEGAL
  3. 2 2
      README
  4. 2 2
      common/common.h
  5. 2 2
      configure
  6. 2 2
      configure.in
  7. 5 6
      init-script
  8. 34 0
      init-script.debian
  9. 28 0
      init-script.freebsd
  10. 5 5
      src/Makefile.in
  11. 41 13
      src/check_nrpe.c
  12. 66 24
      src/nrpe.c
  13. 22 3
      src/utils.c
  14. 4 2
      src/utils.h

+ 3 - 0
Changelog

@@ -6,6 +6,9 @@ NRPE Changelog
 1.6 - ??/??/2002
 ----------------
 - Updated sample commands to match new plugin argument format
+- Added sample init scripts for FreeBSD and Debian (Andrew Ryder)
+- Syntax changes (-H option specifies host name in check_nrpe, 
+  -c option specifies config file in nrpe)
 
 
 1.5 - 06/03/2002

+ 2 - 2
LEGAL

@@ -4,7 +4,7 @@ in this distribution are provided AS IS with NO WARRANTY OF ANY KIND,
 INCLUDING THE WARRANTY OF DESIGN, MERCHANTABILITY, AND FITNESS FOR
 A PARTICULAR PURPOSE.
 
-Nagios and the Nagios logo are trademarks of Ethan Galstad. All 
-other trademarks, servicemarks, registered trademarks, and 
+Nagios and the Nagios logo are registered trademarks of Ethan Galstad.
+All other trademarks, servicemarks, registered trademarks, and 
 registered servicemarks are the property of their respective owner(s).
 

+ 2 - 2
README

@@ -98,7 +98,7 @@ of TCP wrappers, you need to do the following things:
    /etc/inetd.conf as follows:
 
 
-	nrpe 	stream 	tcp 	nowait 	<user> /usr/sbin/tcpd <nrpebin> -i <nrpecfg>
+	nrpe 	stream 	tcp 	nowait 	<user> /usr/sbin/tcpd <nrpebin> --inetd -c <nrpecfg>
 
 
    - Replace <user> with the name of the user that the nrpe server should run as.
@@ -124,7 +124,7 @@ of TCP wrappers, you need to do the following things:
         	wait            = no
 	        user            = <user>
         	server          = <nrpebin>
-	        server_args     = -i <nrpecfg>
+	        server_args     = --inetd -c <nrpecfg>
         	log_on_failure  += USERID
 	        disable         = no
 		only_from       = <ipaddress1> <ipaddress2> ...

+ 2 - 2
common/common.h

@@ -22,8 +22,8 @@
  ************************************************************************/
 
 
-#define PROGRAM_VERSION "1.5"
-#define MODIFICATION_DATE "06-03-2002"
+#define PROGRAM_VERSION "1.6"
+#define MODIFICATION_DATE "07-08-2002"
 
 #define OK		0
 #define ERROR		-1

+ 2 - 2
configure

@@ -530,9 +530,9 @@ fi
 
 
 PKG_NAME=nrpe
-PKG_VERSION="1.5"
+PKG_VERSION="1.6"
 PKG_HOME_URL="http://www.nagios.org/"
-PKG_REL_DATE="06-03-2002"
+PKG_REL_DATE="07-08-2002"
 
 
 ac_aux_dir=

+ 2 - 2
configure.in

@@ -4,9 +4,9 @@ AC_CONFIG_HEADER(common/config.h)
 AC_PREFIX_DEFAULT(/usr/local/nagios)
 
 PKG_NAME=nrpe
-PKG_VERSION="1.5"
+PKG_VERSION="1.6"
 PKG_HOME_URL="http://www.nagios.org/"
-PKG_REL_DATE="06-03-2002"
+PKG_REL_DATE="07-08-2002"
 
 dnl Figure out how to invoke "install" and what install options to use.
 

+ 5 - 6
init-script

@@ -27,10 +27,9 @@ fi
 # Check that networking is up.
 [ ${NETWORKING} = "no" ] && exit 0
 
-prefix=/usr/local/nagios
-exec_prefix=${prefix}
-NrpeBin=${exec_prefix}/bin/nrpe
-NrpeCfg=${prefix}/etc/nrpe.cfg
+NrpeBin=/usr/local/nagios/bin/nrpe
+NrpeCfg=/usr/local/nagios/etc/nrpe.cfg
+LockFile=/var/lock/subsys/nrpe
 
 # See how we were called.
 case "$1" in
@@ -39,14 +38,14 @@ case "$1" in
 	echo -n "Starting nrpe: "
 	daemon $NrpeBin -d $NrpeCfg
 	echo
-	touch /var/lock/subsys/nrpe
+	touch $LockFile
 	;;
   stop)
 	# Stop daemons.
 	echo -n "Shutting down nrpe: "
 	killproc nrpe
 	echo
-	rm -f /var/lock/subsys/nrpe
+	rm -f $LockFile
 	;;
   restart)
 	$0 stop

+ 34 - 0
init-script.debian

@@ -0,0 +1,34 @@
+#!/bin/sh
+# Start/stop the nrpe daemon.
+#
+# Contributed by Andrew Ryder 06-22-02
+# Slight mods by Ethan Galstad 07-09-02
+
+NrpeBin=/usr/sbin/nrpe
+NrpeCfg=/etc/nrpe.cfg
+
+test -f $NrpeBin || exit 0
+
+case "$1" in
+start)	echo -n "Starting nagios remote plugin daemon: nrpe"
+        start-stop-daemon --start --quiet --exec $NrpeBin -- -d $NrpeCfg
+        echo "." 
+	;;
+stop)	echo -n "Stopping nagios remote plugin daemon: nrpe"
+        start-stop-daemon --stop --quiet --exec $NrpeBin
+        echo "."
+        ;;
+restart) echo -n "Restarting nagios remote plugin daemon: nrpe"
+        start-stop-daemon --stop --quiet --exec $NrpeBin
+        start-stop-daemon --start --quiet --exec $NrpeBin
+        echo "."
+        ;;
+reload|force-reload) echo -n "Reloading configuration files for nagios remote plugin daemon: nrpe"
+	# nrpe reloads automatically
+        echo "."
+        ;;
+*)	echo "Usage: /etc/init.d/nrpe start|stop|restart|reload|force-reload"
+        exit 1 
+        ;;
+esac
+exit 0

+ 28 - 0
init-script.freebsd

@@ -0,0 +1,28 @@
+#!/bin/sh
+# Start/stop the nrpe daemon.
+#
+# Contributed by Andrew Ryder 06-22-02
+# Slight mods by Ethan Galstad 07-09-02
+
+NrpeBin=/usr/local/bin/nrpe
+NrpeCfg=/usr/local/etc/nrpe.cfg
+
+case "$1" in
+start)
+	$NrpeBin -d $NrpeCfg
+	echo -n ' nrpe'
+	;;
+stop)
+		killall -TERM nrpe
+		echo -n ' nrpe'
+	;;
+restart)
+		killall -HUP nrpe
+		echo 'nrpe restarted'
+	;;
+*)
+	echo "Usage: ${0##*/}: { start | stop | restart }" 2>&1
+	exit 65
+	;;
+esac
+

+ 5 - 5
src/Makefile.in

@@ -1,7 +1,7 @@
 ###############################
 # Makefile for NRPE
 #
-# Last Modified: 12-23-2001
+# Last Modified: 07-09-2002
 ###############################
 
 
@@ -18,11 +18,11 @@ CP=@CP@
 
 all: nrpe check_nrpe
 
-nrpe: nrpe.c nrpe.h netutils.c netutils.h $(SRC_COMMON)/common.h $(SRC_COMMON)/config.h
-	$(CC) $(CFLAGS) $(LDFLAGS) $(SOCKETLIBS) nrpe.c netutils.c -o $@
+nrpe: nrpe.c nrpe.h utils.c utils.h $(SRC_COMMON)/common.h $(SRC_COMMON)/config.h
+	$(CC) $(CFLAGS) $(LDFLAGS) $(SOCKETLIBS) nrpe.c utils.c -o $@
 
-check_nrpe: check_nrpe.c netutils.c netutils.h $(SRC_COMMON)/common.h $(SRC_COMMON)/config.h
-	$(CC) $(CFLAGS) $(LDFLAGS) $(SOCKETLIBS) check_nrpe.c netutils.c -o $@
+check_nrpe: check_nrpe.c utils.c utils.h $(SRC_COMMON)/common.h $(SRC_COMMON)/config.h
+	$(CC) $(CFLAGS) $(LDFLAGS) $(SOCKETLIBS) check_nrpe.c utils.c -o $@
 
 clean:
 	rm -f core nrpe check_nrpe

+ 41 - 13
src/check_nrpe.c

@@ -4,9 +4,9 @@
  * Copyright (c) 1999-2002 Ethan Galstad (nagios@nagios.org)
  * License: GPL
  *
- * Last Modified: 06-03-2002
+ * Last Modified: 07-08-2002
  *
- * Command line: CHECK_NRPE <host_address> [-p port] [-c command] [-wt warn_time] \
+ * Command line: CHECK_NRPE -H <host_address> [-p port] [-c command] [-wt warn_time] \
  *                          [-ct crit_time] [-to to_sec]
  *
  * Description:
@@ -20,7 +20,7 @@
 
 #include "../common/common.h"
 #include "../common/config.h"
-#include "netutils.h"
+#include "utils.h"
 
 #define DEFAULT_NRPE_COMMAND	"_NRPE_CHECK"  /* check version of NRPE daemon */
 
@@ -30,6 +30,9 @@ char server_name[MAX_HOST_ADDRESS_LENGTH];
 char query_string[MAX_PACKETBUFFER_LENGTH]=DEFAULT_NRPE_COMMAND;;
 int socket_timeout=DEFAULT_SOCKET_TIMEOUT;
 
+int show_help=FALSE;
+int show_license=FALSE;
+int show_version=FALSE;
 
 
 int process_arguments(int,char **);
@@ -49,17 +52,22 @@ int main(int argc, char **argv){
 
 	result=process_arguments(argc,argv);
 
-	if(result!=OK){
+        if(result!=OK || show_help==TRUE || show_license==TRUE || show_version==TRUE){
 
-		printf("Incorrect command line arguments supplied\n");
-		printf("\n");
+		if(result!=OK)
+			printf("Incorrect command line arguments supplied\n");
+                printf("\n");
 		printf("NRPE Plugin for Nagios\n");
 		printf("Copyright (c) 1999-2002 Ethan Galstad (nagios@nagios.org)\n");
 		printf("Version: %s\n",PROGRAM_VERSION);
 		printf("Last Modified: %s\n",MODIFICATION_DATE);
 		printf("License: GPL\n");
 		printf("\n");
-		printf("Usage: %s <host_address> [-p port] [-c command] [-wt warn_time]\n",argv[0]);
+	        }
+
+	if(result!=OK || show_help==TRUE){
+
+		printf("Usage: %s -H <host_address> [-p port] [-c command] [-wt warn_time]\n",argv[0]);
 		printf("          [-ct crit_time] [-to to_sec]\n");
 		printf("\n");
 		printf("Options:\n");
@@ -78,10 +86,15 @@ int main(int argc, char **argv){
 		printf("to execute plugins on remote hosts and 'fake' the results to make Nagios think\n");
 		printf("the plugin is being run locally.\n");
 		printf("\n");
-
-		return STATE_UNKNOWN;
 	        }
 
+	if(show_license==TRUE)
+		display_license();
+
+        if(result!=OK || show_help==TRUE || show_license==TRUE || show_version==TRUE)
+		exit(STATE_UNKNOWN);
+
+
 	/* initialize alarm signal handling */
 	signal(SIGALRM,alarm_handler);
 
@@ -168,14 +181,23 @@ int process_arguments(int argc, char **argv){
 	if(argc<2)
 		return ERROR;
 
-	/* first option is always the server name/address */
+	/* handle older style command line format - host address was first argument */
 	strncpy(server_name,argv[1],sizeof(server_name)-1);
 	server_name[sizeof(server_name)-1]='\x0';
 
-	/* process all remaining arguments */
-	for(x=3;x<=argc;x++){
+	/* process all arguments */
+	for(x=2;x<=argc;x++){
 
-		if(!strcmp(argv[x-1],"-c")){
+		if(!strcmp(argv[x-1],"-H")){
+			if(x<argc){
+				strncpy(server_name,argv[x],sizeof(server_name)-1);
+				server_name[sizeof(server_name)-1]='\x0';
+				x++;
+			        }
+			else
+				return ERROR;
+		        }
+		else if(!strcmp(argv[x-1],"-c")){
 			if(x<argc){
 				strncpy(query_string,argv[x],sizeof(query_string)-1);
 				query_string[sizeof(query_string)-1]='\x0';
@@ -202,6 +224,12 @@ int process_arguments(int argc, char **argv){
 			else
 				return ERROR;
 		        }
+		else if(!strcmp(argv[x-1],"-h") || !strcmp(argv[x-1],"--help"))
+			show_help=TRUE;
+		else if(!strcmp(argv[x-1],"--license"))
+			show_license=TRUE;
+		else if(!strcmp(argv[x-1],"--version"))
+			show_version=TRUE;
 		else
 			return ERROR;
 	        }

+ 66 - 24
src/nrpe.c

@@ -4,9 +4,9 @@
  * Copyright (c) 1999-2002 Ethan Galstad (nagios@nagios.org)
  * License: GPL
  *
- * Last Modified: 06-03-2002
+ * Last Modified: 07-08-2002
  *
- * Command line: nrpe [-i | -d] <config_file>
+ * Command line: nrpe [--inetd | --standalone] -c <config_file>
  *
  * Description:
  *
@@ -21,12 +21,14 @@
 #include "../common/common.h"
 #include "../common/config.h"
 #include "nrpe.h"
-#include "netutils.h"
+#include "utils.h"
 
 #define COMMAND_TIMEOUT		60			/* timeout for execution of plugins */
 #define MAXFD                   64
 
 
+int process_arguments(int,char **);
+
 void wait_for_connections(void);
 void handle_connection(int);
 int read_config_file(char *);
@@ -41,6 +43,7 @@ int my_system(char *,int,int *,char *,int);            	/* executes a command vi
 void my_system_sighandler(int);				/* handles timeouts when executing commands via my_system() */
 
 
+char    config_file[MAX_INPUT_BUFFER]="nrpe.cfg";
 char    allowed_hosts[MAX_INPUT_BUFFER];
 int     server_port=DEFAULT_SERVER_PORT;
 char    server_address[16]="0.0.0.0";
@@ -51,6 +54,9 @@ command *command_list=NULL;
 char    *nrpe_user=NULL;
 char    *nrpe_group=NULL;
 
+int     show_help=FALSE;
+int     show_license=FALSE;
+int     show_version=FALSE;
 int     use_inetd=TRUE;
 int     debug=FALSE;
 
@@ -60,22 +66,11 @@ int main(int argc, char **argv){
 	int error=FALSE;
 	int result;
 	int i;
-	char config_file[MAX_INPUT_BUFFER];
 	char buffer[MAX_INPUT_BUFFER];
 
-	/* check command line arguments */
-	if(argc!=3)
-		error=TRUE;
-	else{
-		if(!strcmp(argv[1],"-d"))
-			use_inetd=FALSE;
-		else if(!strcmp(argv[1],"-i"))
-			use_inetd=TRUE;
-		else
-			error=TRUE;
-	        }
+	result=process_arguments(argc,argv);
 
-	if(error==TRUE){
+        if(result!=OK || show_help==TRUE || show_license==TRUE || show_version==TRUE){
 
 		printf("\n");
 		printf("NRPE - Nagios Remote Plugin Executor\n");
@@ -84,11 +79,17 @@ int main(int argc, char **argv){
 		printf("Last Modified: %s\n",MODIFICATION_DATE);
 		printf("License: GPL\n");
 		printf("\n");
-		printf("Usage: %s <-i | -d> <config_file>\n",argv[0]);
+	        }
+
+	if(result!=OK || show_help==TRUE){
+
+		printf("Usage: %s -c <config_file> [mode]\n",argv[0]);
 		printf("\n");
 		printf("Options:\n");
-		printf("  -i      Run as a service under inetd or xinetd\n");
-		printf("  -d      Run as a standalone daemon\n");
+		printf(" <config_file> = Name of config file to use\n");
+		printf(" [mode]        = Determines how NRPE should run. Valid modes:\n");
+		printf("   --inetd     = Run as a service under inetd or xinetd\n");
+		printf("   --daemon    = Run as a standalone daemon\n");
 		printf("\n");
 		printf("Notes:\n");
 		printf("This program is designed to process requests from the check_nrpe\n");
@@ -99,17 +100,18 @@ int main(int argc, char **argv){
 		printf("config file) and return the plugin output and return code to the\n");
 		printf("check_nrpe plugin.\n");
 		printf("\n");
+		}
+
+	if(show_license==TRUE)
+		display_license();
 
+        if(result!=OK || show_help==TRUE || show_license==TRUE || show_version==TRUE)
 		exit(STATE_UNKNOWN);
-		}
+
 
 	/* open a connection to the syslog facility */
         openlog("nrpe",LOG_PID,LOG_DAEMON); 
 
-	/* grab the config file */
-	strncpy(config_file,argv[2],sizeof(config_file)-1);
-	config_file[sizeof(config_file)-1]='\x0';
-
 	/* make sure the config file uses an absolute path */
 	if(config_file[0]!='/'){
 
@@ -925,3 +927,43 @@ int drop_privileges(char *user, char *group){
 
 	return OK;
         }
+
+
+/* process command line arguments */
+int process_arguments(int argc, char **argv){
+	int x;
+
+
+	/* no options were supplied */
+	if(argc<2)
+		return ERROR;
+
+	/* process all arguments */
+	for(x=2;x<=argc;x++){
+
+		if(!strcmp(argv[x-1],"-c")){
+			if(x<argc){
+				strncpy(config_file,argv[x],sizeof(config_file)-1);
+				config_file[sizeof(config_file)-1]='\x0';
+				x++;
+			        }
+			else
+				return ERROR;
+		        }
+		else if(!strcmp(argv[x-1],"-d") || !strcmp(argv[x-1],"--daemon"))
+			use_inetd=FALSE;
+		else if(!strcmp(argv[1],"-i") || !strcmp(argv[x-1],"--inetd"))
+			use_inetd=TRUE;
+		else if(!strcmp(argv[x-1],"-h") || !strcmp(argv[x-1],"--help"))
+			show_help=TRUE;
+		else if(!strcmp(argv[x-1],"-l") || !strcmp(argv[x-1],"--license"))
+			show_license=TRUE;
+		else if(!strcmp(argv[x-1],"-V") || !strcmp(argv[x-1],"--version"))
+			show_version=TRUE;
+		else
+			return ERROR;
+	        }
+
+	return OK;
+        }
+

+ 22 - 3
src/netutils.c → src/utils.c

@@ -1,11 +1,11 @@
 /****************************************************************************
  *
- * NETUTILS.C - NRPE Network Utilities
+ * UTILS.C - NRPE Utility Functions
  *
  * License: GPL
  * Copyright (c) 1999-2002 Ethan Galstad (nagios@nagios.org)
  *
- * Last Modified: 02-21-2002
+ * Last Modified: 07-09-2002
  *
  * Description:
  *
@@ -30,7 +30,7 @@
  ****************************************************************************/
 
 #include "../common/common.h"
-#include "netutils.h"
+#include "utils.h"
 
 
 /* opens a connection to a remote host/tcp port */
@@ -294,3 +294,22 @@ int recvall(int s, char *buf, int *len, int timeout){
 	/* return <=0 on failure, bytes received on success */
 	return (n<=0)?n:total;
         }
+
+
+/* show license */
+void display_license(void){
+
+	printf("This program is free software; you can redistribute it and/or modify\n");
+	printf("it under the terms of the GNU General Public License as published by\n");
+	printf("the Free Software Foundation; either version 2 of the License, or\n");
+	printf("(at your option) any later version.\n\n");
+	printf("This program is distributed in the hope that it will be useful,\n");
+	printf("but WITHOUT ANY WARRANTY; without even the implied warranty of\n");
+	printf("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n");
+	printf("GNU General Public License for more details.\n\n");
+	printf("You should have received a copy of the GNU General Public License\n");
+	printf("along with this program; if not, write to the Free Software\n");
+	printf("Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\n\n");
+
+	return;
+        }

+ 4 - 2
src/netutils.h → src/utils.h

@@ -1,11 +1,11 @@
 /************************************************************************************************
  *
- * NETUTILS.H - NRPE Network Utilities Include File
+ * UTILS.H - NRPE Utilities Include File
  *
  * License: GPL
  * Copyright (c) 1999-2002 Ethan Galstad (nagios@nagios.org)
  *
- * Last Modified: 02-21-2002
+ * Last Modified: 07-09-2002
  *
  * Description:
  *
@@ -41,6 +41,8 @@ void strip(char *);
 int sendall(int,char *,int *);
 int recvall(int,char *,int *,int);
 
+void display_license(void);
+