[collectd] [PATCH] Added support for more than one TypesDB file.

Sebastian Harl sh at tokkee.org
Sun Jan 20 22:14:23 CET 2008


The "TypesDB" config option now accepts more than one filename. Each file will
be read in the specified order. If no filename has been given, the default
file will _not_ be read (I doubt this is a useful feature but it's imho the
most reasonable behavior).

This may, for example, be used to specify an additional file containing custom
data-set definitions. See the thread "Thought about exec and types.db" on the
mailing-list ([1]).

[1] http://mailman.verplant.org/pipermail/collectd/2008-January/001450.html

Signed-off-by: Sebastian Harl <sh at tokkee.org>
---
 src/collectd.c        |    2 --
 src/collectd.conf.pod |    4 ++--
 src/configfile.c      |   31 +++++++++++++++++++++++++++++--
 src/types_list.c      |    7 +------
 src/types_list.h      |    2 +-
 5 files changed, 33 insertions(+), 13 deletions(-)

diff --git a/src/collectd.c b/src/collectd.c
index 70223b7..c9ae66d 100644
--- a/src/collectd.c
+++ b/src/collectd.c
@@ -29,7 +29,6 @@
 
 #include "plugin.h"
 #include "configfile.h"
-#include "types_list.h"
 
 /*
  * Global variables
@@ -260,7 +259,6 @@ static int do_init (void)
 	}
 #endif
 
-	read_types_list ();
 	plugin_init_all ();
 
 	return (0);
diff --git a/src/collectd.conf.pod b/src/collectd.conf.pod
index 021d193..7e416b4 100644
--- a/src/collectd.conf.pod
+++ b/src/collectd.conf.pod
@@ -72,9 +72,9 @@ setting using the B<-P> command-line option.
 
 Path to the plugins (shared objects) of collectd.
 
-=item B<TypesDB> I<File>
+=item B<TypesDB> I<File> [I<File> ...]
 
-Set the file that contains the data-set descriptions.
+Set one or more files that contain the data-set descriptions.
 
 =item B<Interval> I<Seconds>
 
diff --git a/src/configfile.c b/src/configfile.c
index 867338d..706e2d1 100644
--- a/src/configfile.c
+++ b/src/configfile.c
@@ -27,6 +27,7 @@
 #include "common.h"
 #include "plugin.h"
 #include "configfile.h"
+#include "types_list.h"
 #include "utils_threshold.h"
 
 #define ESCAPE_NULL(str) ((str) == NULL ? "(null)" : (str))
@@ -66,6 +67,7 @@ typedef struct cf_global_option_s
 /*
  * Prototypes of callback functions
  */
+static int dispatch_value_typesdb (const oconfig_item_t *ci);
 static int dispatch_value_plugindir (const oconfig_item_t *ci);
 static int dispatch_value_loadplugin (const oconfig_item_t *ci);
 
@@ -77,6 +79,7 @@ static cf_complex_callback_t *complex_callback_head = NULL;
 
 static cf_value_map_t cf_value_map[] =
 {
+	{"TypesDB",    dispatch_value_typesdb},
 	{"PluginDir",  dispatch_value_plugindir},
 	{"LoadPlugin", dispatch_value_loadplugin}
 };
@@ -89,11 +92,12 @@ static cf_global_option_t cf_global_options[] =
 	{"Hostname",    NULL, NULL},
 	{"FQDNLookup",  NULL, "false"},
 	{"Interval",    NULL, "10"},
-	{"ReadThreads", NULL, "5"},
-	{"TypesDB",     NULL, PLUGINDIR"/types.db"} /* FIXME: Configure path */
+	{"ReadThreads", NULL, "5"}
 };
 static int cf_global_options_num = STATIC_ARRAY_LEN (cf_global_options);
 
+static int cf_default_typesdb = 1;
+
 /*
  * Functions to handle register/unregister, search, and other plugin related
  * stuff
@@ -188,6 +192,27 @@ static int dispatch_global_option (const oconfig_item_t *ci)
 	return (-1);
 } /* int dispatch_global_option */
 
+static int dispatch_value_typesdb (const oconfig_item_t *ci)
+{
+	int i = 0;
+
+	assert (strcasecmp (ci->key, "TypesDB") == 0);
+
+	cf_default_typesdb = 0;
+
+	if (ci->values_num < 1)
+		return (-1);
+
+	for (i = 0; i < ci->values_num; ++i)
+	{
+		if (OCONFIG_TYPE_STRING != ci->values[i].type)
+			continue;
+
+		read_types_list (ci->values[i].value.string);
+	}
+	return (0);
+} /* int dispatch_value_typesdb */
+
 static int dispatch_value_plugindir (const oconfig_item_t *ci)
 {
 	assert (strcasecmp (ci->key, "PluginDir") == 0);
@@ -593,5 +618,7 @@ int cf_read (char *filename)
 			dispatch_block (conf->children + i);
 	}
 
+	if (cf_default_typesdb)
+		read_types_list (PLUGINDIR"/types.db"); /* FIXME: Configure path */
 	return (0);
 } /* int cf_read */
diff --git a/src/types_list.c b/src/types_list.c
index 002761c..43e8790 100644
--- a/src/types_list.c
+++ b/src/types_list.c
@@ -169,17 +169,12 @@ static void parse_file (FILE *fh)
   } /* while (fgets) */
 } /* void parse_file */
 
-int read_types_list (void)
+int read_types_list (const char *file)
 {
-  const char *file;
   FILE *fh;
 
-  file = global_option_get ("TypesDB");
   if (file == NULL)
-  {
-    ERROR ("global_option_get (\"TypesDB\") returned NULL.");
     return (-1);
-  }
 
   fh = fopen (file, "r");
   if (fh == NULL)
diff --git a/src/types_list.h b/src/types_list.h
index c7e6aa0..8fe6ce8 100644
--- a/src/types_list.h
+++ b/src/types_list.h
@@ -22,6 +22,6 @@
  *   Florian octo Forster <octo at verplant.org>
  **/
 
-int read_types_list (void);
+int read_types_list (const char *file);
 
 #endif /* TYPES_LIST_H */
-- 
1.5.4.rc2.84.gf85fd

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://mailman.verplant.org/pipermail/collectd/attachments/20080120/543af984/attachment.pgp 


More information about the collectd mailing list