[icinga-checkins] icinga.org: icinga-core/mforni/core: Icinga can send log messages to syslogd using a local facility instead of the default one

git at icinga.org git at icinga.org
Sun May 16 22:35:23 CEST 2010


Module: icinga-core
Branch: mforni/core
Commit: b09fe3d2f9bfe7bbe89ef23e31c2c7b969230d11
URL:    https://git.icinga.org/?p=icinga-core.git;a=commit;h=b09fe3d2f9bfe7bbe89ef23e31c2c7b969230d11

Author: Massimo Forni <forni.massimo at gmail.com>
Date:   Sun May 16 22:34:23 2010 +0200

Icinga can send log messages to syslogd using a local facility instead of the default one

fixes #347

---

 AUTHORS                     |    1 +
 Changelog                   |    1 +
 base/config.c               |   29 +++++++++++++++++++++++++++--
 base/icinga.c               |    2 ++
 base/logging.c              |   33 +++++++++++++++++++++++++++++++++
 base/utils.c                |    3 +++
 include/icinga.h            |    3 +++
 sample-config/icinga.cfg.in |   16 ++++++++++++++++
 8 files changed, 86 insertions(+), 2 deletions(-)

diff --git a/AUTHORS b/AUTHORS
index b751f6f..bbd9594 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -21,3 +21,4 @@ Ton Voon
 Vitali Voroth
 William Preston
 Wolfgang Nieder
+Massimo Forni
diff --git a/Changelog b/Changelog
index 5292633..531b0d6 100644
--- a/Changelog
+++ b/Changelog
@@ -6,6 +6,7 @@ Icinga 1.0.x Change Log
 
 ENHANCEMENTS
 * core: init script shows config errors option; don't remove pidfile if icinga did not stop in a timely manner
+* core: icinga can send log messages to syslogd using a local facility instead of the default one
 
 * idoutils: remove mysql binary selects, use case-sensitive collation instead (William Preston)
 * idoutils: Spread the list of linked lists thinner (extend objects hash slots) (Opsera Ltd)
diff --git a/base/config.c b/base/config.c
index 4a4b032..58258d0 100644
--- a/base/config.c
+++ b/base/config.c
@@ -3,7 +3,8 @@
  * CONFIG.C - Configuration input and verification routines for Icinga
  *
  * Copyright (c) 1999-2008 Ethan Galstad (egalstad at nagios.org)
- * Last Modified: 12-14-2008
+ * Copyright (c) 2010 Icinga Core Development Team and Community Contributors
+ * Last Modified: 2010-05-16
  *
  * License:
  *
@@ -64,7 +65,9 @@ extern char     *illegal_output_chars;
 extern int      use_regexp_matches;
 extern int      use_true_regexp_matching;
 
-extern int	use_syslog;
+extern int      use_syslog;
+extern int      use_syslog_local_facility;
+extern int      syslog_local_facility;
 extern int      log_notifications;
 extern int      log_service_retries;
 extern int      log_host_retries;
@@ -525,6 +528,28 @@ int read_main_config_file(char *main_config_file){
 			use_syslog=(atoi(value)>0)?TRUE:FALSE;
 			}
 
+		else if(!strcmp(variable,"use_syslog_local_facility")){
+
+			if(strlen(value)!=1||value[0]<'0'||value[0]>'1'){
+				asprintf(&error_message,"Illegal value for use_syslog_local_facility");
+				error=TRUE;
+				break;
+				}
+
+			use_syslog_local_facility=(atoi(value)>0)?TRUE:FALSE;
+			}
+
+		else if(!strcmp(variable,"syslog_local_facility")){
+
+			if(strlen(value)!=1||value[0]<'0'||value[0]>'7'){
+				asprintf(&error_message,"Illegal value for syslog_local_facility");
+				error=TRUE;
+				break;
+				}
+
+			syslog_local_facility=atoi(value);
+			}
+
 		else if(!strcmp(variable,"log_notifications")){
 
 			if(strlen(value)!=1||value[0]<'0'||value[0]>'1'){
diff --git a/base/icinga.c b/base/icinga.c
index 1616dae..1a942da 100644
--- a/base/icinga.c
+++ b/base/icinga.c
@@ -87,6 +87,8 @@ int             use_regexp_matches=FALSE;
 int             use_true_regexp_matching=FALSE;
 
 int		use_syslog=DEFAULT_USE_SYSLOG;
+int		use_syslog_local_facility=DEFAULT_USE_SYSLOG_LOCAL_FACILITY;
+int		syslog_local_facility=DEFAULT_SYSLOG_LOCAL_FACILITY;
 int             log_notifications=DEFAULT_NOTIFICATION_LOGGING;
 int             log_service_retries=DEFAULT_LOG_SERVICE_RETRIES;
 int             log_host_retries=DEFAULT_LOG_HOST_RETRIES;
diff --git a/base/logging.c b/base/logging.c
index 5e19d81..e323b16 100644
--- a/base/logging.c
+++ b/base/logging.c
@@ -41,6 +41,8 @@ extern host     *host_list;
 extern service  *service_list;
 
 extern int	use_syslog;
+extern int	use_syslog_local_facility;
+extern int	syslog_local_facility;
 extern int      log_service_retries;
 extern int      log_initial_states;
 
@@ -222,6 +224,37 @@ int write_to_syslog(char *buffer, unsigned long data_type){
 		return OK;
 
 	/* write the buffer to the syslog facility */
+	if (use_syslog_local_facility) {
+		switch (syslog_local_facility) {
+			case 0:
+				syslog(LOG_LOCAL0|LOG_INFO,"%s",buffer);
+				return OK;
+			case 1:
+				syslog(LOG_LOCAL1|LOG_INFO,"%s",buffer);
+				return OK;
+			case 2:
+				syslog(LOG_LOCAL2|LOG_INFO,"%s",buffer);
+				return OK;
+			case 3:
+				syslog(LOG_LOCAL3|LOG_INFO,"%s",buffer);
+				return OK;
+			case 4:
+				syslog(LOG_LOCAL4|LOG_INFO,"%s",buffer);
+				return OK;
+			case 5:
+				syslog(LOG_LOCAL5|LOG_INFO,"%s",buffer);
+				return OK;
+			case 6:
+				syslog(LOG_LOCAL6|LOG_INFO,"%s",buffer);
+				return OK;
+			case 7:
+				syslog(LOG_LOCAL7|LOG_INFO,"%s",buffer);
+				return OK;
+			default:
+				break;
+		}
+	} 
+
 	syslog(LOG_USER|LOG_INFO,"%s",buffer);
 
 	return OK;
diff --git a/base/utils.c b/base/utils.c
index f470e3c..83b260d 100644
--- a/base/utils.c
+++ b/base/utils.c
@@ -104,6 +104,9 @@ extern int      daemon_dumps_core;
 extern int      nagios_pid;
 
 extern int	use_syslog;
+extern int	use_syslog_local_facility;
+extern int	syslog_local_facility;
+
 extern int      log_notifications;
 extern int      log_service_retries;
 extern int      log_host_retries;
diff --git a/include/icinga.h b/include/icinga.h
index e4091d8..fe5e873 100644
--- a/include/icinga.h
+++ b/include/icinga.h
@@ -51,6 +51,9 @@ extern "C" {
 
 #define DEFAULT_LOG_LEVEL					1	/* log all events to main log file */
 #define DEFAULT_USE_SYSLOG					1	/* log events to syslog? 1=yes, 0=no */
+#define DEFAULT_USE_SYSLOG_LOCAL_FACILITY			0	/* log events to a local facility instead of the default? 1=yes, 0=no */
+#define DEFAULT_SYSLOG_LOCAL_FACILITY				5	/* log events to the specified loacl facility? 1=yes, 0=no */
+
 #define DEFAULT_SYSLOG_LEVEL					2	/* log only severe events to syslog */
 
 #define DEFAULT_NOTIFICATION_LOGGING				1	/* log notification events? 1=yes, 0=no */
diff --git a/sample-config/icinga.cfg.in b/sample-config/icinga.cfg.in
index b4f96c7..022f139 100644
--- a/sample-config/icinga.cfg.in
+++ b/sample-config/icinga.cfg.in
@@ -277,6 +277,22 @@ use_syslog=1
 
 
 
+# SYSLOG FACILITY
+# If you enabled use_syslog you can set icinga to use a local facility
+# instead of the default.To enable set this option to 1, if not, set it to 0.
+
+use_syslog_local_facility=0
+
+
+
+# SYSLOG LOCAL FACILITY
+# If you specified the use_syslog_local_facility you can chose which
+# local facility to use. Valid values are from 0 to 7
+
+syslog_local_facility=5
+
+
+
 # NOTIFICATION LOGGING OPTION
 # If you don't want notifications to be logged, set this value to 0.
 # If notifications should be logged, set the value to 1.





More information about the icinga-checkins mailing list