X-Git-Url: https://git.octo.it/?p=collectd.git;a=blobdiff_plain;f=src%2Ftail.c;h=a6471d832572e7074dde0865e76a943391598f7f;hp=bb4eb30bf34e51d32d7876f81c258daaa84513df;hb=ec51ddee94fa2ba1e01fe0e336ccc9c190a198ff;hpb=edcf39cc377d2de0744412209de4eeb50ca7ed5f diff --git a/src/tail.c b/src/tail.c index bb4eb30b..a6471d83 100644 --- a/src/tail.c +++ b/src/tail.c @@ -34,7 +34,8 @@ /* * * - * Instance "exim" + * Plugin "mail" + * Instance "exim" * Interval 60 * * Regex "S=([1-9][0-9]*)" @@ -58,15 +59,15 @@ struct ctail_config_match_s { }; typedef struct ctail_config_match_s ctail_config_match_t; -static cu_tail_match_t **tail_match_list = NULL; -static size_t tail_match_list_num = 0; +static cu_tail_match_t **tail_match_list; +static size_t tail_match_list_num; static cdtime_t tail_match_list_intervals[255]; static int ctail_config_add_match_dstype(ctail_config_match_t *cm, oconfig_item_t *ci) { if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) { WARNING("tail plugin: `DSType' needs exactly one string argument."); - return (-1); + return -1; } char const *ds_type = ci->values[0].value.string; @@ -93,7 +94,7 @@ static int ctail_config_add_match_dstype(ctail_config_match_t *cm, int status = latency_config(&cm->latency, ci, "tail"); if (status != 0) - return (status); + return status; } else if (strncasecmp("Counter", ds_type, strlen("Counter")) == 0) { cm->flags = UTILS_MATCH_DS_TYPE_COUNTER; if (strcasecmp("CounterSet", ds_type) == 0) @@ -127,13 +128,13 @@ static int ctail_config_add_match_dstype(ctail_config_match_t *cm, if (cm->flags == 0) { WARNING("tail plugin: `%s' is not a valid argument to `DSType'.", ci->values[0].value.string); - return (-1); + return -1; } - return (0); + return 0; } /* int ctail_config_add_match_dstype */ -static int ctail_config_add_match(cu_tail_match_t *tm, +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,8 +192,9 @@ 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, - cm.type, cm.type_instance, cm.latency, interval); + 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) ERROR("tail plugin: tail_match_add_match_simple failed."); @@ -204,37 +206,41 @@ static int ctail_config_add_match(cu_tail_match_t *tm, sfree(cm.type_instance); latency_config_free(cm.latency); - return (status); + return status; } /* int ctail_config_add_match */ 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; if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) { WARNING("tail plugin: `File' needs exactly one string argument."); - return (-1); + return -1; } tm = tail_match_create(ci->values[0].value.string); if (tm == NULL) { ERROR("tail plugin: tail_match_create (%s) failed.", ci->values[0].value.string); - return (-1); + return -1; } for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *option = ci->children + i; int status = 0; - if (strcasecmp("Instance", option->key) == 0) + if (strcasecmp("Plugin", 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,13 +253,14 @@ 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) { ERROR("tail plugin: No (valid) matches found for file `%s'.", ci->values[0].value.string); tail_match_destroy(tm); - return (-1); + return -1; } else { cu_tail_match_t **temp; @@ -262,7 +269,7 @@ static int ctail_config_add_file(oconfig_item_t *ci) { if (temp == NULL) { ERROR("tail plugin: realloc failed."); tail_match_destroy(tm); - return (-1); + return -1; } tail_match_list = temp; @@ -271,7 +278,7 @@ static int ctail_config_add_file(oconfig_item_t *ci) { tail_match_list_num++; } - return (0); + return 0; } /* int ctail_config_add_file */ static int ctail_config(oconfig_item_t *ci) { @@ -285,7 +292,7 @@ static int ctail_config(oconfig_item_t *ci) { } } /* for (i = 0; i < ci->children_num; i++) */ - return (0); + return 0; } /* int ctail_config */ static int ctail_read(user_data_t *ud) { @@ -294,10 +301,10 @@ static int ctail_read(user_data_t *ud) { status = tail_match_read((cu_tail_match_t *)ud->data); if (status != 0) { ERROR("tail plugin: tail_match_read failed."); - return (-1); + return -1; } - return (0); + return 0; } /* int ctail_read */ static int ctail_init(void) { @@ -305,11 +312,11 @@ static int ctail_init(void) { if (tail_match_list_num == 0) { WARNING("tail plugin: File list is empty. Returning an error."); - return (-1); + return -1; } for (size_t i = 0; i < tail_match_list_num; i++) { - ssnprintf(str, sizeof(str), "tail-%zu", i); + snprintf(str, sizeof(str), "tail-%zu", i); plugin_register_complex_read(NULL, str, ctail_read, tail_match_list_intervals[i], @@ -318,7 +325,7 @@ static int ctail_init(void) { }); } - return (0); + return 0; } /* int ctail_init */ static int ctail_shutdown(void) { @@ -329,7 +336,7 @@ static int ctail_shutdown(void) { sfree(tail_match_list); tail_match_list_num = 0; - return (0); + return 0; } /* int ctail_shutdown */ void module_register(void) { @@ -337,5 +344,3 @@ void module_register(void) { plugin_register_init("tail", ctail_init); plugin_register_shutdown("tail", ctail_shutdown); } /* void module_register */ - -/* vim: set sw=2 sts=2 ts=8 : */