Allowed custom plugin name in 'dbi', 'oracle' and 'postgresql' plugins (per Database...
authorPavel Rochnyack <pavel2000@ngs.ru>
Thu, 12 May 2016 10:24:00 +0000 (16:24 +0600)
committerPavel Rochnyack <pavel2000@ngs.ru>
Mon, 10 Jul 2017 10:13:15 +0000 (17:13 +0700)
src/collectd.conf.in
src/collectd.conf.pod
src/dbi.c
src/oracle.c
src/postgresql.c

index 3eaeb5d..8ab20d1 100644 (file)
 #              </Result>
 #      </Query>
 #      <Database "customers_db">
+#              #PluginName "mycompany"
 #              Driver "mysql"
 #              DriverOption "host" "localhost"
 #              DriverOption "username" "collectd"
 #    </Result>
 #  </Query>
 #  <Database "product_information">
+#    #PluginName "warehouse"
 #    ConnectID "db01"
 #    Username "oracle"
 #    Password "secret"
 #              StoreRates true
 #      </Writer>
 #      <Database foo>
+#              #PluginName "kingdom"
 #              Host "hostname"
 #              Port "5432"
 #              User "username"
index 9b31de7..b4fe2f9 100644 (file)
@@ -2017,6 +2017,7 @@ than those of other plugins. It usually looks something like this:
       </Result>
     </Query>
     <Database "product_information">
+      #PluginName "warehouse"
       Driver "mysql"
       Interval 120
       DriverOption "host" "localhost"
@@ -2198,6 +2199,11 @@ the daemon. Other than that, that name is not used.
 
 =over 4
 
+=item B<PluginName> I<PluginName>
+
+Use I<PluginName> as the plugin name when submitting query results from
+this B<Database>. Defaults to 'dbi'.
+
 =item B<Interval> I<Interval>
 
 Sets the interval (in seconds) in which the values will be collected from this
@@ -5589,6 +5595,7 @@ plugin's documentation above for details.
       </Result>
     </Query>
     <Database "product_information">
+      #PluginName "warehouse"
       ConnectID "db01"
       Username "oracle"
       Password "secret"
@@ -5611,6 +5618,11 @@ values submitted to the daemon. Other than that, that name is not used.
 
 =over 4
 
+=item B<PluginName> I<PluginName>
+
+Use I<PluginName> as the plugin name when submitting query results from
+this B<Database>. Defaults to 'oracle'.
+
 =item B<ConnectID> I<ID>
 
 Defines the "database alias" or "service name" to connect to. Usually, these
@@ -5964,6 +5976,7 @@ L<http://www.postgresql.org/docs/manuals/>.
     </Writer>
 
     <Database foo>
+      PluginName "kingdom"
       Host "hostname"
       Port "5432"
       User "username"
@@ -6285,6 +6298,11 @@ activating this option. The draw-back is, that data covering the specified
 amount of time will be lost, for example, if a single statement within the
 transaction fails or if the database server crashes.
 
+=item B<PluginName> I<PluginName>
+
+Use I<PluginName> as the plugin name when submitting query results from
+this B<Database>. Defaults to 'postgresql'.
+
 =item B<Instance> I<name>
 
 Specify the plugin instance name that should be used instead of the database
index ac307ff..ba91bff 100644 (file)
--- a/src/dbi.c
+++ b/src/dbi.c
@@ -62,6 +62,7 @@ struct cdbi_database_s /* {{{ */
 {
   char *name;
   char *select_db;
+  char *plugin_name;
 
   cdtime_t interval;
 
@@ -172,7 +173,10 @@ static void cdbi_database_free(cdbi_database_t *db) /* {{{ */
     return;
 
   sfree(db->name);
+  sfree(db->select_db);
+  sfree(db->plugin_name);
   sfree(db->driver);
+  sfree(db->host);
 
   for (size_t i = 0; i < db->driver_options_num; i++) {
     sfree(db->driver_options[i].key);
@@ -298,6 +302,8 @@ static int cdbi_config_add_database(oconfig_item_t *ci) /* {{{ */
       status = cf_util_get_string(child, &db->host);
     else if (strcasecmp("Interval", child->key) == 0)
       status = cf_util_get_cdtime(child, &db->interval);
+    else if (strcasecmp("PluginName", child->key) == 0)
+      status = cf_util_get_string(child, &db->plugin_name);
     else {
       WARNING("dbi plugin: Option `%s' not allowed here.", child->key);
       status = -1;
@@ -540,7 +546,8 @@ static int cdbi_read_database_query(cdbi_database_t *db, /* {{{ */
 
   udb_query_prepare_result(
       q, prep_area, (db->host ? db->host : hostname_g),
-      /* plugin = */ "dbi", db->name, column_names, column_num,
+      /* plugin = */ (db->plugin_name != NULL) ? db->plugin_name : "dbi",
+      db->name, column_names, column_num,
       /* interval = */ (db->interval > 0) ? db->interval : 0);
 
   /* 0 = error; 1 = success; */
index 2d98f0a..69e519b 100644 (file)
@@ -62,6 +62,7 @@ struct o_database_s {
   char *connect_id;
   char *username;
   char *password;
+  char *plugin_name;
 
   udb_query_preparation_area_t **q_prep_areas;
   udb_query_t **queries;
@@ -141,6 +142,7 @@ static void o_database_free(o_database_t *db) /* {{{ */
   sfree(db->username);
   sfree(db->password);
   sfree(db->queries);
+  sfree(db->plugin_name);
 
   if (db->q_prep_areas != NULL)
     for (size_t i = 0; i < db->queries_num; ++i)
@@ -192,6 +194,7 @@ static int o_config_add_database(oconfig_item_t *ci) /* {{{ */
   db->connect_id = NULL;
   db->username = NULL;
   db->password = NULL;
+  db->plugin_name = NULL;
 
   status = cf_util_get_string(ci, &db->name);
   if (status != 0) {
@@ -211,6 +214,8 @@ static int o_config_add_database(oconfig_item_t *ci) /* {{{ */
       status = cf_util_get_string(child, &db->username);
     else if (strcasecmp("Password", child->key) == 0)
       status = cf_util_get_string(child, &db->password);
+    else if (strcasecmp("PluginName", child->key) == 0)
+      status = cf_util_get_string(child, &db->plugin_name);
     else if (strcasecmp("Query", child->key) == 0)
       status = udb_query_pick_from_list(child, queries, queries_num,
                                         &db->queries, &db->queries_num);
@@ -545,7 +550,8 @@ static int o_read_database_query(o_database_t *db, /* {{{ */
 
   status = udb_query_prepare_result(
       q, prep_area, (db->host != NULL) ? db->host : hostname_g,
-      /* plugin = */ "oracle", db->name, column_names, column_num,
+      /* plugin = */ (db->plugin_name != NULL) ? db->plugin_name : "oracle",
+      db->name, column_names, column_num,
       /* interval = */ 0);
   if (status != 0) {
     ERROR("oracle plugin: o_read_database_query (%s, %s): "
index d0c0ae1..70467c2 100644 (file)
@@ -139,6 +139,7 @@ typedef struct {
   char *password;
 
   char *instance;
+  char *plugin_name;
 
   char *sslmode;
 
@@ -250,6 +251,8 @@ static c_psql_database_t *c_psql_database_new(const char *name) {
 
   db->instance = sstrdup(name);
 
+  db->plugin_name = NULL;
+
   db->sslmode = NULL;
 
   db->krbsrvname = NULL;
@@ -300,6 +303,8 @@ static void c_psql_database_delete(void *data) {
 
   sfree(db->instance);
 
+  sfree(db->plugin_name);
+
   sfree(db->sslmode);
 
   sfree(db->krbsrvname);
@@ -539,9 +544,11 @@ static int c_psql_exec_query(c_psql_database_t *db, udb_query_t *q,
   else
     host = db->host;
 
-  status =
-      udb_query_prepare_result(q, prep_area, host, "postgresql", db->instance,
-                               column_names, (size_t)column_num, db->interval);
+  status = udb_query_prepare_result(
+      q, prep_area, host,
+      (db->plugin_name != NULL) ? db->plugin_name : "postgresql",
+      db->instance, column_names, (size_t)column_num, db->interval);
+
   if (0 != status) {
     log_err("udb_query_prepare_result failed with status %i.", status);
     BAIL_OUT(-1);
@@ -1139,6 +1146,8 @@ static int c_psql_config_database(oconfig_item_t *ci) {
       cf_util_get_string(c, &db->password);
     else if (0 == strcasecmp(c->key, "Instance"))
       cf_util_get_string(c, &db->instance);
+    else if (0 == strcasecmp (c->key, "PluginName"))
+      cf_util_get_string (c, &db->plugin_name);
     else if (0 == strcasecmp(c->key, "SSLMode"))
       cf_util_get_string(c, &db->sslmode);
     else if (0 == strcasecmp(c->key, "KRBSrvName"))