[icinga-checkins] icinga.org: icinga-core/mfriedrich/core: idoutils: add cfg option to enable /disable oci errors to syslog through error handler #1060

git at icinga.org git at icinga.org
Fri Jan 7 13:28:31 CET 2011


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

Author: Michael Friedrich <michael.friedrich at univie.ac.at>
Date:   Fri Jan  7 13:27:04 2011 +0100

idoutils: add cfg option to enable/disable oci errors to syslog through error handler #1060

it became necessary as on recurring errors the syslog might
be flooded with error msg.

this option disables syslog output for ocilib error msg.
default stays enabled, but it might be changed in the future.

fixes #1060

---

 Changelog                                   |    1 +
 module/idoutils/config/ido2db.cfg-sample.in |   11 +++++++++++
 module/idoutils/include/db.h                |    1 +
 module/idoutils/include/ido2db.h            |    5 +++++
 module/idoutils/src/db.c                    |   13 +++++++++----
 module/idoutils/src/ido2db.c                |    5 +++++
 6 files changed, 32 insertions(+), 4 deletions(-)

diff --git a/Changelog b/Changelog
index 272c3ea..4716899 100644
--- a/Changelog
+++ b/Changelog
@@ -31,6 +31,7 @@ ENHANCEMENTS
 
 * idoutils: add index to table icinga_statehistory for usage in reporting module #957
 * idoutils: add check for configuration file availability for idomod and ido2db (idea from Ricardo Maraschini) #1087
+* idoutils: add cfg option to enable/disable oci errors to syslog through error handler #1060
 
 * contrib: bring daemonchk.cgi building into shape (Elan Ruusamäe) #1051
 
diff --git a/module/idoutils/config/ido2db.cfg-sample.in b/module/idoutils/config/ido2db.cfg-sample.in
index 851da43..2395c3d 100644
--- a/module/idoutils/config/ido2db.cfg-sample.in
+++ b/module/idoutils/config/ido2db.cfg-sample.in
@@ -218,6 +218,7 @@ trim_db_interval=60
 housekeeping_thread_startup_delay=60
 
 
+
 # DEBUG LEVEL
 # This option determines how much (if any) debugging information will
 # be written to the debug file.  OR values together to log multiple
@@ -257,3 +258,13 @@ debug_file=@localstatedir@/ido2db.debug
 
 max_debug_file_size=1000000
 
+
+
+# OCI ERRORS TO SYSLOG
+# ido2db registers an error handler in ocilib which spits all msg
+# into debug and syslog by default. Setting this option to 0,
+# syslog output will be disabled, only debug log will be used (if
+# appropriate debug_level is set).
+
+oci_errors_to_syslog=1
+
diff --git a/module/idoutils/include/db.h b/module/idoutils/include/db.h
index 8860f7c..65cb3c3 100644
--- a/module/idoutils/include/db.h
+++ b/module/idoutils/include/db.h
@@ -33,6 +33,7 @@ typedef struct ido2db_dbconfig_struct{
 	unsigned long housekeeping_thread_startup_delay;
         unsigned long clean_realtime_tables_on_core_startup;
         unsigned long clean_config_tables_on_core_startup;
+	unsigned long oci_errors_to_syslog;
         }ido2db_dbconfig;
 
 /*************** DB server types ***************/
diff --git a/module/idoutils/include/ido2db.h b/module/idoutils/include/ido2db.h
index e64c036..6e86926 100644
--- a/module/idoutils/include/ido2db.h
+++ b/module/idoutils/include/ido2db.h
@@ -210,6 +210,7 @@ typedef struct ido2db_dbconninfo_struct{
 	unsigned long housekeeping_thread_startup_delay;
 	unsigned long clean_realtime_tables_on_core_startup;
 	unsigned long clean_config_tables_on_core_startup;
+	unsigned long oci_errors_to_syslog;
 	time_t last_table_trim_time;
 	time_t last_logentry_time;
 	char *last_logentry_data;
@@ -361,6 +362,10 @@ typedef struct ido2db_input_data_info_struct{
 
 #define DEFAULT_HOUSEKEEPING_THREAD_STARTUP_DELAY 60
 
+/************* default trim db interval ********/
+
+#define DEFAULT_OCI_ERRORS_TO_SYSLOG 		1
+
 /***************** functions *******************/
 
 /* config */
diff --git a/module/idoutils/src/db.c b/module/idoutils/src/db.c
index 5a776fe..7d8e5ab 100644
--- a/module/idoutils/src/db.c
+++ b/module/idoutils/src/db.c
@@ -510,7 +510,7 @@ int ido2db_db_connect(ido2db_idi *idi) {
 	}
 
         /* initialize prepared statements */
-	ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_db_connet() prepare statements start\n");
+	ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_db_connect() prepare statements start\n");
 
 	/* object inserts */
         if(ido2db_oci_prepared_statement_objects_insert(idi) == IDO_ERROR) {
@@ -1000,7 +1000,7 @@ int ido2db_db_connect(ido2db_idi *idi) {
         }
 
 
-	ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_db_connet() prepare statements end\n");
+	ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_db_connect() prepare statements end\n");
 
 #endif /* Oracle ocilib specific */
 
@@ -2717,12 +2717,17 @@ void ido2db_ocilib_err_handler(OCI_Error *err) {
 		const mtext *sql = OCI_GetSql(OCI_ErrorGetStatement(err));
 
 		if (sql != NULL) {
-			syslog(LOG_USER | LOG_INFO, "ERROR: QUERY '%s'\n", sql);
+			if(ido2db_db_settings.oci_errors_to_syslog==IDO_TRUE) {
+				syslog(LOG_USER | LOG_INFO, "ERROR: QUERY '%s'\n", sql);
+			}
 			ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ERROR: QUERY '%s'\n", sql);
 		}
 	}
 
-	syslog(LOG_USER | LOG_INFO, "ERROR: MSG '%s'\n", OCI_ErrorGetString(err));
+	if(ido2db_db_settings.oci_errors_to_syslog==IDO_TRUE) {
+		syslog(LOG_USER | LOG_INFO, "ERROR: MSG '%s'\n", OCI_ErrorGetString(err));
+	}
+
 	ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ERROR: MSG '%s'\n", OCI_ErrorGetString(err));
 }
 
diff --git a/module/idoutils/src/ido2db.c b/module/idoutils/src/ido2db.c
index 7e3601f..0b624a9 100644
--- a/module/idoutils/src/ido2db.c
+++ b/module/idoutils/src/ido2db.c
@@ -584,6 +584,10 @@ int ido2db_process_config_var(char *arg){
 		ido2db_db_settings.clean_config_tables_on_core_startup=(atoi(val)>0)?IDO_TRUE:IDO_FALSE;
 	}
 
+        else if(!strcmp(var,"oci_errors_to_syslog")){
+                ido2db_db_settings.oci_errors_to_syslog=(atoi(val)>0)?IDO_TRUE:IDO_FALSE;
+	}
+
 	ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_process_config_var() end\n");
 
 	return IDO_OK;
@@ -614,6 +618,7 @@ int ido2db_initialize_variables(void){
 	ido2db_db_settings.housekeeping_thread_startup_delay=(unsigned long)DEFAULT_HOUSEKEEPING_THREAD_STARTUP_DELAY; /* set the default if missing in ido2db.cfg */
 	ido2db_db_settings.clean_realtime_tables_on_core_startup=IDO_TRUE; /* default is cleaning on startup */
 	ido2db_db_settings.clean_config_tables_on_core_startup=IDO_TRUE;
+	ido2db_db_settings.oci_errors_to_syslog=DEFAULT_OCI_ERRORS_TO_SYSLOG;
 
 	ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_initialize_variables() end\n");
 	return IDO_OK;





More information about the icinga-checkins mailing list