From 3259a9bec97cf502a780d70c0ab2a3394f8a6407 Mon Sep 17 00:00:00 2001 From: Pavel Rochnyack Date: Sun, 24 Apr 2016 20:00:40 +0600 Subject: [PATCH] tail plugin: Allow custom plugin name for file instances --- src/collectd.conf.pod | 13 ++++++++----- src/tail.c | 16 ++++++++++++---- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/collectd.conf.pod b/src/collectd.conf.pod index 3f7bb412..4bd8423b 100644 --- a/src/collectd.conf.pod +++ b/src/collectd.conf.pod @@ -7519,6 +7519,7 @@ user using (extended) regular expressions, as described in L. + PluginName "mail" Instance "exim" Interval 60 @@ -7550,11 +7551,13 @@ The config consists of one or more B blocks, each of which configures one logfile to parse. Within each B block, there are one or more B blocks, which configure a regular expression to search for. -The B option in the B block may be used to set the plugin -instance. So in the above example the plugin name C would be used. -This plugin instance is for all B blocks that B it, until the -next B option. This way you can extract several plugin instances from -one logfile, handy when parsing syslog and the like. +The B and B options in the B block may be used to set +the plugin name and instance respectively. So in the above example the plugin name +C would be used. + +These options are applied for all B blocks that B it, until the +next B or B option. This way you can extract several plugin +instances from one logfile, handy when parsing syslog and the like. The B option allows you to define the length of time between reads. If this is not set, the default Interval will be used. diff --git a/src/tail.c b/src/tail.c index 1b720b83..f7f061a9 100644 --- a/src/tail.c +++ b/src/tail.c @@ -34,7 +34,8 @@ /* * * - * Instance "exim" + * PluginName "mail" + * Instance "exim" * Interval 60 * * Regex "S=([1-9][0-9]*)" @@ -134,6 +135,7 @@ static int ctail_config_add_match_dstype(ctail_config_match_t *cm, } /* int ctail_config_add_match_dstype */ static int ctail_config_add_match(cu_tail_match_t *tm, + const char *plugin_name, const char *plugin_instance, oconfig_item_t *ci, cdtime_t interval) { ctail_config_match_t cm = {0}; @@ -191,7 +193,8 @@ static int ctail_config_add_match(cu_tail_match_t *tm, if (status == 0) { // TODO(octo): there's nothing "simple" about the latency stuff … status = tail_match_add_match_simple( - tm, cm.regex, cm.excluderegex, cm.flags, "tail", plugin_instance, + tm, cm.regex, cm.excluderegex, cm.flags, + (plugin_name != NULL) ? plugin_name : "tail", plugin_instance, cm.type, cm.type_instance, cm.latency, interval); if (status != 0) @@ -210,6 +213,7 @@ static int ctail_config_add_match(cu_tail_match_t *tm, static int ctail_config_add_file(oconfig_item_t *ci) { cu_tail_match_t *tm; cdtime_t interval = 0; + char *plugin_name = NULL; char *plugin_instance = NULL; int num_matches = 0; @@ -229,12 +233,15 @@ static int ctail_config_add_file(oconfig_item_t *ci) { oconfig_item_t *option = ci->children + i; int status = 0; - if (strcasecmp("Instance", option->key) == 0) + if (strcasecmp("PluginName", option->key) == 0) + status = cf_util_get_string (option, &plugin_name); + else if (strcasecmp("Instance", option->key) == 0) status = cf_util_get_string(option, &plugin_instance); else if (strcasecmp("Interval", option->key) == 0) cf_util_get_cdtime(option, &interval); else if (strcasecmp("Match", option->key) == 0) { - status = ctail_config_add_match(tm, plugin_instance, option, interval); + status = ctail_config_add_match(tm, plugin_name, plugin_instance, option, + interval); if (status == 0) num_matches++; /* Be mild with failed matches.. */ @@ -247,6 +254,7 @@ static int ctail_config_add_file(oconfig_item_t *ci) { break; } /* for (i = 0; i < ci->children_num; i++) */ + sfree(plugin_name); sfree(plugin_instance); if (num_matches == 0) { -- 2.11.0