[icinga-checkins] icinga.org: icinga-core/mfriedrich/fixes: add initial etc/module.d/ for loading <nebmodule>.cfg

git at icinga.org git at icinga.org
Sun Jan 10 08:40:18 CET 2010


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

Author: Michael Friedrich <michael.friedrich at univie.ac.at>
Date:   Sun Jan 10 08:39:49 2010 +0100

add initial etc/module.d/ for loading <nebmodule>.cfg

if event_broker in icinga.cfg has no config_file attached,
icinga parses the name of the nebmodule (without .o)
and checks for nebmodule.cfg in etc/module.d/ instead

etc/module.d/ will be created during make install-conf or
make install-idoutils

to stay compatible, idomod.cfg-sample will be copied to old
and new location.

to upgrade, do the following:
1/ update your icinga.cfg
+ cfg_module_dir=/path/to/icinga/etc/module.d
- broker_module=/path/to/icinga/bin/idomod.o config_file=/path/to/icinga/etc/idomod.cfg
+ broker_module=/path/to/icinga/bin/idomod.o

2/ mkdir /path/to/icinga/etc/module.d

3/ cp /path/to/icinga/etc/idomod.cfg /path/to/icinga/etc/module.d/

relates to #162

---

 Makefile.in                  |    2 ++
 base/config.c                |   10 ++++++++--
 base/icinga.c                |    5 +++--
 base/nebmods.c               |   38 ++++++++++++++++++++++++++++++++++++--
 module/idoutils/Makefile.in  |    3 +++
 module/idoutils/src/idomod.c |   39 +++++++++++++++++++++++++++++++--------
 sample-config/icinga.cfg.in  |   13 +++++++++++--
 xdata/xodtemplate.c          |    3 +--
 8 files changed, 95 insertions(+), 18 deletions(-)

diff --git a/Makefile.in b/Makefile.in
index 30d5140..a3cdfce 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -28,6 +28,7 @@ exec_prefix=@exec_prefix@
 LOGDIR=@localstatedir@
 CHECKRESULTDIR=@CHECKRESULTDIR@
 CFGDIR=@sysconfdir@
+CFGMODULEDIR=@sysconfdir@/module.d
 BINDIR=@bindir@
 CGIDIR=@sbindir@
 LIBEXECDIR=@libexecdir@
@@ -292,6 +293,7 @@ install-basic:
 install-config:
 	$(INSTALL) -m 775 $(INSTALL_OPTS) -d $(DESTDIR)$(CFGDIR)
 	$(INSTALL) -m 775 $(INSTALL_OPTS) -d $(DESTDIR)$(CFGDIR)/objects
+	$(INSTALL) -m 775 $(INSTALL_OPTS) -d $(DESTDIR)$(CFGMODULEDIR)
 	$(INSTALL) -b -m 664 $(INSTALL_OPTS) sample-config/icinga.cfg $(DESTDIR)$(CFGDIR)/icinga.cfg
 	$(INSTALL) -b -m 664 $(INSTALL_OPTS) sample-config/cgi.cfg $(DESTDIR)$(CFGDIR)/cgi.cfg
 	$(INSTALL) -b -m 660 $(INSTALL_OPTS) sample-config/resource.cfg $(DESTDIR)$(CFGDIR)/resource.cfg
diff --git a/base/config.c b/base/config.c
index 0b32da7..4f1e817 100644
--- a/base/config.c
+++ b/base/config.c
@@ -213,6 +213,7 @@ extern int              debug_level;
 extern int              debug_verbosity;
 extern unsigned long    max_debug_file_size;
 
+extern char		*cfg_module_dir;
 
 
 /******************************************************************/
@@ -1095,7 +1096,7 @@ int read_main_config_file(char *main_config_file){
 
 		else if(!strcmp(variable,"aggregate_status_updates")){
 
-			/* DEPRECATED - ALL UPDATED ARE AGGREGATED AS OF Icinga 3.X */
+			/* DEPRECATED - ALL UPDATED ARE AGGREGATED */
 			/*aggregate_status_updates=(atoi(value)>0)?TRUE:FALSE;*/
 
 			logit(NSLOG_CONFIG_WARNING,TRUE,"Warning: aggregate_status_updates directive ignored.  All status file updates are now aggregated.");
@@ -1223,6 +1224,11 @@ int read_main_config_file(char *main_config_file){
 #endif
 		        }
 
+		else if(!strcmp(variable,"cfg_module_dir")){
+
+			cfg_module_dir=(char *)strdup(value);
+		}
+
 		else if(!strcmp(variable,"use_regexp_matching"))
 			use_regexp_matches=(atoi(value)>0)?TRUE:FALSE;
 
@@ -1325,7 +1331,7 @@ int read_main_config_file(char *main_config_file){
 			continue;
 		else if(strstr(variable,"service_perfdata")==variable)
 			continue;
-		else if(strstr(input,"cfg_file=")==input || strstr(input,"cfg_dir=")==input)
+		else if(strstr(input,"cfg_file=")==input || strstr(input,"cfg_dir=")==input || strstr(input,"cfg_module_dir=")==input)
 			continue;
 		else if(strstr(input,"state_retention_file=")==input)
 			continue;
diff --git a/base/icinga.c b/base/icinga.c
index 9ca55e8..f2e3b74 100644
--- a/base/icinga.c
+++ b/base/icinga.c
@@ -269,8 +269,9 @@ int             debug_level=DEFAULT_DEBUG_LEVEL;
 int             debug_verbosity=DEFAULT_DEBUG_VERBOSITY;
 unsigned long   max_debug_file_size=DEFAULT_MAX_DEBUG_FILE_SIZE;
 
-
-
+#ifdef USE_EVENT_BROKER
+char		*cfg_module_dir = NULL;
+#endif
 
 /* Following main() declaration required by older versions of Perl ut 5.00503 */
 #ifdef EMBEDDEDPERL
diff --git a/base/nebmods.c b/base/nebmods.c
index 745687e..63528cc 100644
--- a/base/nebmods.c
+++ b/base/nebmods.c
@@ -37,6 +37,7 @@ nebcallback **neb_callback_list=NULL;
 
 extern char     *temp_path;
 
+extern char	*cfg_module_dir;
 
 /*#define DEBUG*/
 
@@ -80,12 +81,28 @@ int neb_deinit_modules(void){
 	return OK;
         }
 
+/* extract module name from path */
+char *neb_extract_module_name(char *path_name) {
 
+	char *module_name = NULL;
+	char *file_name = NULL;
+
+	if(path_name!=NULL) {
+		file_name = strrchr(path_name,'/') + 1;
+		module_name=strtok(file_name,".");
+	}
+
+	free(file_name);
+
+	return module_name;
+}
 
 /* add a new module to module list */
 int neb_add_module(char *filename,char *args,int should_be_loaded){
 	nebmodule *new_module=NULL;
 	int x=OK;
+	char *module_name = NULL;
+	char *module_cfg = NULL;
 
 	if(filename==NULL)
 		return ERROR;
@@ -97,7 +114,24 @@ int neb_add_module(char *filename,char *args,int should_be_loaded){
 
 	/* initialize vars */
 	new_module->filename=(char *)strdup(filename);
-	new_module->args=(args==NULL)?NULL:(char *)strdup(args);
+	
+	/* check if cfg_module_dir set and filename for config lookup */
+	if(args==NULL) {
+
+		if((module_name=neb_extract_module_name(args))==NULL) {
+			module_name = "idomod";
+		}
+
+		asprintf(&module_cfg,"%s/%s.cfg", cfg_module_dir, module_name);
+	
+		new_module->args=module_cfg;
+
+		log_debug_info(DEBUGL_EVENTBROKER,0,"Set module: name='%s', module_cfgs='%s'\n",module_name,module_cfg);
+	}
+	else {
+		new_module->args=(char *)strdup(args);
+	}
+
 	new_module->should_be_loaded=should_be_loaded;
 	new_module->is_currently_loaded=FALSE;
 	for(x=0;x<NEBMODULE_MODINFO_NUMITEMS;x++)
@@ -114,7 +148,7 @@ int neb_add_module(char *filename,char *args,int should_be_loaded){
 	neb_module_list=new_module;
 
 	log_debug_info(DEBUGL_EVENTBROKER,0,"Added module: name='%s', args='%s', should_be_loaded='%d'\n",filename,args,should_be_loaded);
-
+	
 	return OK;
         }
 
diff --git a/module/idoutils/Makefile.in b/module/idoutils/Makefile.in
index f50e119..5e64a4a 100644
--- a/module/idoutils/Makefile.in
+++ b/module/idoutils/Makefile.in
@@ -14,6 +14,7 @@ prefix=@prefix@
 exec_prefix=@exec_prefix@
 LOGDIR=@localstatedir@
 CFGDIR=@sysconfdir@
+CFGMODULEDIR=@sysconfdir@/module.d
 BINDIR=@bindir@
 LIBEXECDIR=@libexecdir@
 CGIDIR=@sbindir@
@@ -46,6 +47,8 @@ install-idoutils: install
 install: 
 	cd $(SRC_BASE) && $(MAKE) $@
 	$(INSTALL) -m 775 $(INSTALL_OPTS) -d $(DESTDIR)$(CFGDIR)
+	$(INSTALL) -m 775 $(INSTALL_OPTS) -d $(DESTDIR)$(CFGMODULEDIR)
+	$(INSTALL) -m 664 $(INSTALL_OPTS) config/idomod.cfg-sample $(DESTDIR)$(CFGMODULEDIR)
 	$(INSTALL) -m 664 $(INSTALL_OPTS) config/ido2db.cfg-sample $(DESTDIR)$(CFGDIR)
 	$(INSTALL) -m 664 $(INSTALL_OPTS) config/idomod.cfg-sample $(DESTDIR)$(CFGDIR)
 
diff --git a/module/idoutils/src/idomod.c b/module/idoutils/src/idomod.c
index 46c9534..4b82adb 100644
--- a/module/idoutils/src/idomod.c
+++ b/module/idoutils/src/idomod.c
@@ -272,10 +272,13 @@ int ndomod_process_module_args(char *args){
 	int argcount=0;
 	int memblocks=64;
 	int arg=0;
+	char *cfg=NULL;
 
-	if(args==NULL)
-		return NDO_OK;
+	idomod_log_debug_info(IDOMOD_DEBUGL_PROCESSINFO, 2, "ndomod_process_module_args() start\n");
 
+	if(args==NULL) {
+		return NDO_OK; /* huh? we should bail out here */
+	}
 
 	/* get all the var/val argument pairs */
 
@@ -308,22 +311,42 @@ int ndomod_process_module_args(char *args){
 	/* terminate the arg list */
         arglist[argcount]='\x0';
 
+	idomod_log_debug_info(IDOMOD_DEBUGL_PROCESSINFO, 2, "ndomod_process_module_args() process arguments\n");
 
 	/* process each argument */
 	for(arg=0;arg<argcount;arg++){
-		if(ndomod_process_config_var(arglist[arg])==NDO_ERROR){
+
+		/* todo: make sure that no argument contains 'cfg' in idomod.cfg */
+		if(strstr(arglist[arg], "cfg")) {
+			if(!strstr(arglist[arg], "config_file")) {
+				asprintf(&cfg, "config_file=%s", arglist[arg]);
+			}
+			else {
+				asprintf(&cfg, "%s", arglist[arg]);
+			}
+		} else {
+			asprintf(&cfg, "%s", arglist[arg]);
+		}
+
+		if(ndomod_process_config_var(cfg)==NDO_ERROR){
+
 			for(arg=0;arg<argcount;arg++)
 				free(arglist[arg]);
-			free(arglist);
+				free(arglist);
+				
 			return NDO_ERROR;
-		        }
-	        }
+		}
+        }
 
 	/* free allocated memory */
 	for(arg=0;arg<argcount;arg++)
 		free(arglist[arg]);
 	free(arglist);
 
+	free(cfg);
+        
+	idomod_log_debug_info(IDOMOD_DEBUGL_PROCESSINFO, 2, "ndomod_process_module_args() end\n");
+
 	return NDO_OK;
         }
 
@@ -389,9 +412,9 @@ int ndomod_process_config_var(char *arg){
 
 	/* process the variable... */
 
-	if(!strcmp(var,"config_file"))
+	if(!strcmp(var,"config_file")) {
 		ndomod_process_config_file(val);
-
+	}
 	else if(!strcmp(var,"instance_name"))
 		ndomod_instance_name=strdup(val);
 
diff --git a/sample-config/icinga.cfg.in b/sample-config/icinga.cfg.in
index 0795ec9..f8dd8ff 100644
--- a/sample-config/icinga.cfg.in
+++ b/sample-config/icinga.cfg.in
@@ -242,14 +242,23 @@ event_broker_options=-1
 #
 #   broker_module=<modulepath> [moduleargs]
 
+# default modules config dir
+#
+# place modulename.cfg there to get it loaded automatically 
+# instead of    broker_module=@bindir@/idomod.o config_file=@sysconfdir@/idomod.cfg
+# just          broker_module=@bindir@/idomod.o
+# Icinga will look for nebmodule.cfg when using nebmodule.o
+# if --enable-idoutils is set, idomod.cfg-sample will be copied there
+cfg_module_dir=@sysconfdir@/module.d
+
+# module include
+#
 #broker_module=/somewhere/module1.o
 #broker_module=/somewhere/module2.o arg1 arg2=3 debug=0
 
 # Uncomment this to enable idomod.o
 #broker_module=@bindir@/idomod.o config_file=@sysconfdir@/idomod.cfg
 
-
-
 # LOG ROTATION METHOD
 # This is the log rotation method that Icinga should use to rotate
 # the main log file. Values are as follows..
diff --git a/xdata/xodtemplate.c b/xdata/xodtemplate.c
index f36cc56..3860e3d 100644
--- a/xdata/xodtemplate.c
+++ b/xdata/xodtemplate.c
@@ -303,8 +303,7 @@ int xodtemplate_read_config_data(char *main_config_file, int options, int cache,
 				if(result==ERROR)
 					break;
 		                }
-	                }
-
+		}
 		/* free memory and close the file */
 		my_free(config_base_dir);
 		my_free(input);





More information about the icinga-checkins mailing list