]> git.ipfire.org Git - thirdparty/collectd.git/commitdiff
Allow autoload of matches and targets in the same way of plugins.
authorManuel Luis Sanmartín Rozada <manuel.luis@gmail.com>
Wed, 20 May 2015 20:16:24 +0000 (22:16 +0200)
committerManuel Luis Sanmartín Rozada <manuel.luis@gmail.com>
Thu, 26 Sep 2019 00:02:16 +0000 (02:02 +0200)
src/daemon/filter_chain.c

index d5e14a3414377c1bba21c62497b31e76a45d5ed1..6bbf97099a3211238a5db1cd2482a69442986861 100644 (file)
@@ -218,6 +218,33 @@ static int fc_config_add_match(fc_match_t **matches_head, /* {{{ */
     ptr = ptr->next;
   }
 
+  if (ptr == NULL && IS_TRUE (global_option_get ("AutoLoadPlugin"))) {
+    char plugin_name[NAME_MAX];
+
+    status = ssnprintf (plugin_name, sizeof (plugin_name), "match_%s",
+       ci->values[0].value.string);
+    if ((status < 0) || ((size_t) status >= sizeof (plugin_name))) {
+      ERROR ("Automatically loading plugin \"match_%s\" failed:"
+               " plugin name would have been truncated.",
+               ci->values[0].value.string);
+      return -1;
+    }
+
+    status = plugin_load (plugin_name, /* flags = */ 0);
+    if (status != 0) {
+      ERROR ("Automatically loading plugin \"%s\" failed "
+          "with status %i.", plugin_name, status);
+      return status;
+    }
+
+    ptr = match_list_head;
+    while (ptr != NULL) {
+      if (strcasecmp (ptr->name, ci->values[0].value.string) == 0)
+        break;
+      ptr = ptr->next;
+    }
+  }
+
   if (ptr == NULL) {
     WARNING("Filter subsystem: Cannot find a \"%s\" match. "
             "Did you load the appropriate plugin?",
@@ -277,7 +304,35 @@ static int fc_config_add_target(fc_target_t **targets_head, /* {{{ */
     ptr = ptr->next;
   }
 
-  if (ptr == NULL) {
+  if (ptr == NULL && IS_TRUE (global_option_get ("AutoLoadPlugin"))) {
+    char plugin_name[NAME_MAX];
+
+    status = ssnprintf (plugin_name, sizeof (plugin_name), "target_%s",
+       ci->values[0].value.string);
+    if ((status < 0) || ((size_t) status >= sizeof (plugin_name))) {
+      ERROR ("Automatically loading plugin \"target_%s\" failed:"
+               " plugin name would have been truncated.",
+               ci->values[0].value.string);
+      return -1;
+    }
+
+    status = plugin_load (plugin_name, /* flags = */ 0);
+    if (status != 0) {
+      ERROR ("Automatically loading plugin \"%s\" failed "
+          "with status %i.", plugin_name, status);
+      return status;
+    }
+
+    ptr = target_list_head;
+    while (ptr != NULL) {
+      if (strcasecmp (ptr->name, ci->values[0].value.string) == 0)
+        break;
+      ptr = ptr->next;
+    }
+  }
+
+  if (ptr == NULL)
+  {
     WARNING("Filter subsystem: Cannot find a \"%s\" target. "
             "Did you load the appropriate plugin?",
             ci->values[0].value.string);