Переглянути джерело

Added log facility option

Ethan Galstad 18 роки тому
батько
коміт
cef36584d8
10 змінених файлів з 113 додано та 14 видалено
  1. 1 0
      Changelog
  2. 1 1
      LEGAL
  3. 17 1
      configure
  4. 4 0
      configure.in
  5. 3 1
      include/config.h.in
  6. 6 6
      include/dh.h
  7. 3 2
      include/nrpe.h
  8. 8 1
      sample-config/nrpe.cfg.in
  9. 69 2
      src/nrpe.c
  10. 1 0
      subst.in

+ 1 - 0
Changelog

@@ -8,6 +8,7 @@ NRPE Changelog
 -----------------
 - Added lib64 library paths to configure script for 64-bit systems (John Maag)
 - Added --with-ssl-lib configure script option
+- Added --with-log-facility option to control syslog logging (Ryan Ordway and Brian Seklecki)
 
 
 2.10 - 10/19/2007

+ 1 - 1
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 registered trademarks of Ethan Galstad.
+Nagios and the Nagios logo are registered trademarks of Nagios Enterprises.
 All other trademarks, servicemarks, registered trademarks, and 
 registered servicemarks are the property of their respective owner(s).
 

+ 17 - 1
configure

@@ -310,7 +310,7 @@ ac_includes_default="\
 # include <unistd.h>
 #endif"
 
-ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS INSTALL_PROGRAM INSTALL_SCRIPT INSTALL_DATA INSTALL build build_cpu build_vendor build_os host host_cpu host_vendor host_os CC CFLAGS LDFLAGS CPPFLAGS ac_ct_CC EXEEXT OBJEXT SET_MAKE CPP EGREP SNPRINTF_O OTHERLIBS SOCKETLIBS LIBWRAPLIBS HAVE_SSL nrpe_user nrpe_group NRPE_INSTALL_OPTS nrpe_port nagios_user nagios_group NAGIOS_INSTALL_OPTS PERL LIBOBJS LTLIBOBJS'
+ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS INSTALL_PROGRAM INSTALL_SCRIPT INSTALL_DATA INSTALL build build_cpu build_vendor build_os host host_cpu host_vendor host_os CC CFLAGS LDFLAGS CPPFLAGS ac_ct_CC EXEEXT OBJEXT SET_MAKE CPP EGREP SNPRINTF_O OTHERLIBS SOCKETLIBS LIBWRAPLIBS HAVE_SSL log_facility nrpe_user nrpe_group NRPE_INSTALL_OPTS nrpe_port nagios_user nagios_group NAGIOS_INSTALL_OPTS PERL LIBOBJS LTLIBOBJS'
 ac_subst_files=''
 
 # Initialize some variables set by options.
@@ -855,6 +855,7 @@ Optional Packages:
 --with-ssl-inc=DIR sets location of the SSL include files
 --with-ssl-lib=DIR sets location of the SSL libraries
 --with-kerberos-inc=DIR sets location of the Kerberos include files
+--with-log-facility=<facility> sets NRPE syslog facility
 --with-nrpe-user=<user> sets user name to run NRPE
 --with-nrpe-group=<group> sets group name to run NRPE
 --with-nrpe-port=<port> sets port number for NRPE to listen on
@@ -6729,6 +6730,20 @@ _ACEOF
 fi
 
 
+# Check whether --with-log_facility or --without-log_facility was given.
+if test "${with_log_facility+set}" = set; then
+  withval="$with_log_facility"
+  log_facility=$withval
+else
+  log_facility=daemon
+fi;
+
+cat >>confdefs.h <<_ACEOF
+#define NRPE_LOG_FACILITY "$log_facility"
+_ACEOF
+
+
+
 # Check whether --with-nrpe_user or --without-nrpe_user was given.
 if test "${with_nrpe_user+set}" = set; then
   withval="$with_nrpe_user"
@@ -7421,6 +7436,7 @@ s,@OTHERLIBS@,$OTHERLIBS,;t t
 s,@SOCKETLIBS@,$SOCKETLIBS,;t t
 s,@LIBWRAPLIBS@,$LIBWRAPLIBS,;t t
 s,@HAVE_SSL@,$HAVE_SSL,;t t
+s,@log_facility@,$log_facility,;t t
 s,@nrpe_user@,$nrpe_user,;t t
 s,@nrpe_group@,$nrpe_group,;t t
 s,@NRPE_INSTALL_OPTS@,$NRPE_INSTALL_OPTS,;t t

+ 4 - 0
configure.in

@@ -340,6 +340,10 @@ if test x$check_for_ssl = xyes; then
 
 fi
 
+AC_ARG_WITH(log_facility,--with-log-facility=<facility> sets NRPE syslog facility,log_facility=$withval,log_facility=daemon)
+AC_SUBST(log_facility)
+AC_DEFINE_UNQUOTED(NRPE_LOG_FACILITY,["$log_facility"])
+
 AC_ARG_WITH(nrpe_user,--with-nrpe-user=<user> sets user name to run NRPE,nrpe_user=$withval,nrpe_user=nagios)
 AC_ARG_WITH(nrpe_group,--with-nrpe-group=<group> sets group name to run NRPE,nrpe_group=$withval,nrpe_group=nagios)
 AC_ARG_WITH(nrpe_port,--with-nrpe-port=<port> sets port number for NRPE to listen on,nrpe_port=$withval,nrpe_port=5666)

+ 3 - 1
include/config.h.in

@@ -2,7 +2,7 @@
  *
  * NRPE Common Header File
  * Copyright (c) 1999-2007 Ethan Galstad (nagios@nagios.org)
- * Last Modified: 08-13-2007
+ * Last Modified: 11-23-2007
  *
  * License:
  *
@@ -30,6 +30,8 @@
 
 #define DEFAULT_SERVER_PORT	@nrpe_port@	/* default port to use */
 
+#define NRPE_LOG_FACILITY       @log_facility@
+
 #undef ENABLE_COMMAND_ARGUMENTS
 
 #undef socklen_t

+ 6 - 6
include/dh.h

@@ -4,12 +4,12 @@
 DH *get_dh512()
 	{
 	static unsigned char dh512_p[]={
-		0xB4,0xC4,0xCB,0xF8,0x94,0xEE,0x4D,0x73,0x23,0xF9,0xB0,0xC4,
-		0x07,0xB5,0x69,0xC8,0x7B,0x85,0x10,0xA6,0xB6,0x56,0x2B,0x52,
-		0xDB,0x7C,0xC6,0x39,0x34,0x1B,0xAB,0x68,0xB2,0x05,0x8F,0x87,
-		0x0D,0x53,0xD1,0x32,0x85,0xDC,0xEE,0xA4,0x92,0xBF,0x1B,0x40,
-		0x99,0x76,0xF5,0x28,0xA4,0xAC,0x35,0xD6,0x3F,0x7C,0x23,0xE0,
-		0xBC,0xE9,0x34,0x03,
+		0x95,0xC8,0x9C,0x13,0xC7,0x80,0x1E,0x4E,0x5D,0x18,0x4F,0x0D,
+		0x56,0x7A,0xCB,0xFE,0xE3,0xFF,0x10,0xE4,0x7C,0xF7,0x7E,0x7F,
+		0xF7,0x14,0x48,0x21,0x74,0x34,0xF6,0x80,0xF1,0xAF,0xD7,0x88,
+		0xDD,0xFF,0xB2,0x87,0x95,0xF6,0x10,0x06,0xD6,0x8F,0x11,0xD8,
+		0xEA,0xAC,0x6F,0x15,0x73,0xC3,0xC0,0x67,0xB0,0x4F,0xC1,0xAD,
+		0xBD,0x21,0xE7,0xE3,
 		};
 	static unsigned char dh512_g[]={
 		0x02,

+ 3 - 2
include/nrpe.h

@@ -1,8 +1,8 @@
 /************************************************************************
  *
  * NRPE.H - NRPE Include File
- * Copyright (c) 1999-2006 Ethan Galstad (nagios@nagios.org)
- * Last Modified: 02-23-2006
+ * Copyright (c) 1999-2007 Ethan Galstad (nagios@nagios.org)
+ * Last Modified: 11-23-2007
  *
  * License:
  *
@@ -36,6 +36,7 @@ void wait_for_connections(void);
 void handle_connection(int);
 int read_config_file(char *);
 int read_config_dir(char *);
+int get_log_facility(char *);
 int add_command(char *,char *);
 command *find_command(char *);
 void sighandler(int);

+ 8 - 1
sample-config/nrpe.cfg.in

@@ -2,7 +2,7 @@
 # Sample NRPE Config File 
 # Written by: Ethan Galstad (nagios@nagios.org)
 # 
-# Last Modified: 03-09-2007
+# Last Modified: 11-23-2007
 #
 # NOTES:
 # This is a sample configuration file for the NRPE daemon.  It needs to be
@@ -11,6 +11,13 @@
 #############################################################################
 
 
+# LOG FACILITY
+# The syslog facility that should be used for logging purposes.
+
+log_facility=@log_facility@
+
+
+
 # PID FILE
 # The name of the file in which the NRPE daemon should write it's process ID
 # number.  The file is only written if the NRPE daemon is started by the root

+ 69 - 2
src/nrpe.c

@@ -4,7 +4,7 @@
  * Copyright (c) 1999-2007 Ethan Galstad (nagios@nagios.org)
  * License: GPL
  *
- * Last Modified: 10-19-2007
+ * Last Modified: 11-23-2007
  *
  * Command line: nrpe -c <config_file> [--inetd | --daemon]
  *
@@ -48,6 +48,7 @@ char    *command_name=NULL;
 char    *macro_argv[MAX_COMMAND_ARGUMENTS];
 
 char    config_file[MAX_INPUT_BUFFER]="nrpe.cfg";
+int     log_facility=LOG_DAEMON;
 int     server_port=DEFAULT_SERVER_PORT;
 char    server_address[16]="0.0.0.0";
 int     socket_timeout=DEFAULT_SOCKET_TIMEOUT;
@@ -162,7 +163,9 @@ int main(int argc, char **argv){
 
 
 	/* open a connection to the syslog facility */
-        openlog("nrpe",LOG_PID,LOG_DAEMON); 
+	/* facility name may be overridden later */
+	get_log_facility(NRPE_LOG_FACILITY);
+        openlog("nrpe",LOG_PID,log_facility); 
 
 	/* make sure the config file uses an absolute path */
 	if(config_file[0]!='/'){
@@ -499,6 +502,16 @@ int read_config_file(char *filename){
 		else if(!strcmp(varname,"pid_file"))
 			pid_file=strdup(varvalue);
 
+		else if(!strcmp(varname,"log_facility")){
+			if((get_log_facility(varvalue))==OK){
+				/* re-open log using new facility */
+				closelog();
+				openlog("nrpe",LOG_PID,log_facility); 
+				}
+			else
+				syslog(LOG_WARNING,"Invalid log_facility specified in config file '%s' - Line %d\n",filename,line);
+			}
+
 		else{
 			syslog(LOG_WARNING,"Unknown option specified in config file '%s' - Line %d\n",filename,line);
 			continue;
@@ -576,6 +589,60 @@ int read_config_dir(char *dirname){
         }
 
 
+
+/* determines facility to use with syslog */
+int get_log_facility(char *varvalue){
+
+	if(!strcmp(varvalue,"kern"))
+		log_facility=LOG_KERN;
+	else if(!strcmp(varvalue,"user"))
+		log_facility=LOG_USER;
+	else if(!strcmp(varvalue,"mail"))
+		log_facility=LOG_MAIL;
+	else if(!strcmp(varvalue,"daemon"))
+		log_facility=LOG_DAEMON;
+	else if(!strcmp(varvalue,"auth"))
+		log_facility=LOG_AUTH;
+	else if(!strcmp(varvalue,"syslog"))
+		log_facility=LOG_SYSLOG;
+	else if(!strcmp(varvalue,"lrp"))
+		log_facility=LOG_LPR;
+	else if(!strcmp(varvalue,"news"))
+		log_facility=LOG_NEWS;
+	else if(!strcmp(varvalue,"uucp"))
+		log_facility=LOG_UUCP;
+	else if(!strcmp(varvalue,"cron"))
+		log_facility=LOG_CRON;
+	else if(!strcmp(varvalue,"authpriv"))
+		log_facility=LOG_AUTHPRIV;
+	else if(!strcmp(varvalue,"ftp"))
+		log_facility=LOG_FTP;
+	else if(!strcmp(varvalue,"local0"))
+		log_facility=LOG_LOCAL0;
+	else if(!strcmp(varvalue,"local1"))
+		log_facility=LOG_LOCAL1;
+	else if(!strcmp(varvalue,"local2"))
+		log_facility=LOG_LOCAL2;
+	else if(!strcmp(varvalue,"local3"))
+		log_facility=LOG_LOCAL3;
+	else if(!strcmp(varvalue,"local4"))
+		log_facility=LOG_LOCAL4;
+	else if(!strcmp(varvalue,"local5"))
+		log_facility=LOG_LOCAL5;
+	else if(!strcmp(varvalue,"local6"))
+		log_facility=LOG_LOCAL6;
+	else if(!strcmp(varvalue,"local7"))
+		log_facility=LOG_LOCAL7;
+	else{
+		log_facility=LOG_DAEMON;
+		return ERROR;
+		}
+
+	return OK;
+	}
+
+
+
 /* adds a new command definition from the config file to the list in memory */
 int add_command(char *command_name, char *command_line){
 	command *new_command;

+ 1 - 0
subst.in

@@ -23,6 +23,7 @@ while ($f = shift @ARGV) {
 		s|\@nrpe_user\@|@nrpe_user@|g;
 		s|\@nrpe_group\@|@nrpe_group@|g;
 		s|\@nrpe_port\@|@nrpe_port@|g;
+		s|\@log_facility\@|@log_facility@|g;
 		s|\@libexecdir\@|@libexecdir@|g; # put all --with-vars before directories
 		s|\@localstatedir\@|@localstatedir@|g;
 		s|\@sysconfdir\@|@sysconfdir@|g;