X-Git-Url: https://git.octo.it/?p=collectd.git;a=blobdiff_plain;f=src%2Ftail.c;h=d5166b2a7a5d5c57857207aa18dab851ccc39367;hp=02afd7910af42ed75229020b5c5c0ed0b85b8473;hb=633c3966f770e4d46651a2fe219a18d8a9907a9f;hpb=c57f2a191b63ce73fc432befebe9fa3af97c8eb5 diff --git a/src/tail.c b/src/tail.c index 02afd791..d5166b2a 100644 --- a/src/tail.c +++ b/src/tail.c @@ -1,22 +1,27 @@ /** * collectd - src/tail.c - * Copyright (C) 2008 Florian octo Forster + * Copyright (C) 2008 Florian octo Forster * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation; only version 2 of the License is applicable. + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. * * Authors: - * Florian octo Forster + * Florian octo Forster **/ #include "collectd.h" @@ -28,8 +33,10 @@ * * * Instance "exim" + * Interval 60 * * Regex "S=([1-9][0-9]*)" + * ExcludeRegex "U=root.*S=" * DSType "CounterAdd" * Type "ipt_bytes" * Instance "total" @@ -41,30 +48,17 @@ struct ctail_config_match_s { char *regex; + char *excluderegex; int flags; char *type; char *type_instance; + cdtime_t interval; }; typedef struct ctail_config_match_s ctail_config_match_t; cu_tail_match_t **tail_match_list = NULL; size_t tail_match_list_num = 0; - -static int ctail_config_add_string (const char *name, char **dest, oconfig_item_t *ci) -{ - if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) - { - WARNING ("tail plugin: `%s' needs exactly one string argument.", name); - return (-1); - } - - sfree (*dest); - *dest = strdup (ci->values[0].value.string); - if (*dest == NULL) - return (-1); - - return (0); -} /* int ctail_config_add_string */ +cdtime_t tail_match_list_intervals[255]; static int ctail_config_add_match_dstype (ctail_config_match_t *cm, oconfig_item_t *ci) @@ -101,6 +95,26 @@ static int ctail_config_add_match_dstype (ctail_config_match_t *cm, else cm->flags = 0; } + else if (strncasecmp ("Derive", ci->values[0].value.string, strlen ("Derive")) == 0) + { + cm->flags = UTILS_MATCH_DS_TYPE_DERIVE; + if (strcasecmp ("DeriveSet", ci->values[0].value.string) == 0) + cm->flags |= UTILS_MATCH_CF_DERIVE_SET; + else if (strcasecmp ("DeriveAdd", ci->values[0].value.string) == 0) + cm->flags |= UTILS_MATCH_CF_DERIVE_ADD; + else if (strcasecmp ("DeriveInc", ci->values[0].value.string) == 0) + cm->flags |= UTILS_MATCH_CF_DERIVE_INC; + else + cm->flags = 0; + } + else if (strncasecmp ("Absolute", ci->values[0].value.string, strlen ("Absolute")) == 0) + { + cm->flags = UTILS_MATCH_DS_TYPE_ABSOLUTE; + if (strcasecmp ("AbsoluteSet", ci->values[0].value.string) == 0) + cm->flags |= UTILS_MATCH_CF_ABSOLUTE_SET; + else + cm->flags = 0; + } else { cm->flags = 0; @@ -117,7 +131,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_instance, oconfig_item_t *ci) + const char *plugin_instance, oconfig_item_t *ci, cdtime_t interval) { ctail_config_match_t cm; int status; @@ -136,13 +150,15 @@ static int ctail_config_add_match (cu_tail_match_t *tm, oconfig_item_t *option = ci->children + i; if (strcasecmp ("Regex", option->key) == 0) - status = ctail_config_add_string ("Regex", &cm.regex, option); + status = cf_util_get_string (option, &cm.regex); + else if (strcasecmp ("ExcludeRegex", option->key) == 0) + status = cf_util_get_string (option, &cm.excluderegex); else if (strcasecmp ("DSType", option->key) == 0) status = ctail_config_add_match_dstype (&cm, option); else if (strcasecmp ("Type", option->key) == 0) - status = ctail_config_add_string ("Type", &cm.type, option); + status = cf_util_get_string (option, &cm.type); else if (strcasecmp ("Instance", option->key) == 0) - status = ctail_config_add_string ("Instance", &cm.type_instance, option); + status = cf_util_get_string (option, &cm.type_instance); else { WARNING ("tail plugin: Option `%s' not allowed here.", option->key); @@ -181,8 +197,8 @@ static int ctail_config_add_match (cu_tail_match_t *tm, if (status == 0) { - status = tail_match_add_match_simple (tm, cm.regex, cm.flags, - "tail", plugin_instance, cm.type, cm.type_instance); + status = tail_match_add_match_simple (tm, cm.regex, cm.excluderegex, + cm.flags, "tail", plugin_instance, cm.type, cm.type_instance, interval); if (status != 0) { @@ -191,6 +207,7 @@ static int ctail_config_add_match (cu_tail_match_t *tm, } sfree (cm.regex); + sfree (cm.excluderegex); sfree (cm.type); sfree (cm.type_instance); @@ -200,6 +217,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_instance = NULL; int num_matches = 0; int status; @@ -224,19 +242,20 @@ static int ctail_config_add_file (oconfig_item_t *ci) { oconfig_item_t *option = ci->children + i; - if (strcasecmp ("Match", option->key) == 0) + 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); + status = ctail_config_add_match (tm, plugin_instance, option, interval); if (status == 0) num_matches++; /* Be mild with failed matches.. */ status = 0; } - else if (strcasecmp ("Instance", option->key) == 0) - status = ctail_config_add_string ("Instance", &plugin_instance, option); else { - WARNING ("tail plugin: Option `%s' not allowed here.", option->key); status = -1; } @@ -266,6 +285,7 @@ static int ctail_config_add_file (oconfig_item_t *ci) tail_match_list = temp; tail_match_list[tail_match_list_num] = tm; + tail_match_list_intervals[tail_match_list_num] = interval; tail_match_list_num++; } @@ -291,41 +311,43 @@ static int ctail_config (oconfig_item_t *ci) return (0); } /* int ctail_config */ -static int ctail_init (void) +static int ctail_read (user_data_t *ud) { - if (tail_match_list_num == 0) + int status; + + status = tail_match_read ((cu_tail_match_t *)ud->data); + if (status != 0) { - WARNING ("tail plugin: File list is empty. Returning an error."); + ERROR ("tail plugin: tail_match_read failed."); return (-1); } return (0); -} /* int ctail_init */ +} /* int ctail_read */ -static int ctail_read (void) +static int ctail_init (void) { - int success = 0; + struct timespec cb_interval; + char str[255]; + user_data_t ud; size_t i; - for (i = 0; i < tail_match_list_num; i++) + if (tail_match_list_num == 0) { - int status; + WARNING ("tail plugin: File list is empty. Returning an error."); + return (-1); + } - status = tail_match_read (tail_match_list[i]); - if (status != 0) - { - ERROR ("tail plugin: tail_match_read[%zu] failed.", i); - } - else - { - success++; - } + for (i = 0; i < tail_match_list_num; i++) + { + ud.data = (void *)tail_match_list[i]; + ssnprintf(str, sizeof(str), "tail-%zu", i); + CDTIME_T_TO_TIMESPEC (tail_match_list_intervals[i], &cb_interval); + plugin_register_complex_read (NULL, str, ctail_read, &cb_interval, &ud); } - if (success == 0) - return (-1); return (0); -} /* int ctail_read */ +} /* int ctail_init */ static int ctail_shutdown (void) { @@ -346,7 +368,6 @@ void module_register (void) { plugin_register_complex_config ("tail", ctail_config); plugin_register_init ("tail", ctail_init); - plugin_register_read ("tail", ctail_read); plugin_register_shutdown ("tail", ctail_shutdown); } /* void module_register */