From: Manuel Luis SanmartĂ­n Rozada Date: Wed, 20 May 2015 20:16:24 +0000 (+0200) Subject: Allow autoload of matches and targets in the same way of plugins. X-Git-Tag: collectd-5.11.0~37^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a3978b3233f1210b064990a013b8d6df943ecc0d;p=thirdparty%2Fcollectd.git Allow autoload of matches and targets in the same way of plugins. --- diff --git a/src/daemon/filter_chain.c b/src/daemon/filter_chain.c index d5e14a341..6bbf97099 100644 --- a/src/daemon/filter_chain.c +++ b/src/daemon/filter_chain.c @@ -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);