/*
* <Plugin tail>
* <File "/var/log/exim4/mainlog">
- * Instance "exim"
+ * Plugin "mail"
+ * Instance "exim"
* Interval 60
* <Match>
* Regex "S=([1-9][0-9]*)"
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;
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)
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,
+ const char *plugin_name,
const char *plugin_instance,
oconfig_item_t *ci, cdtime_t interval) {
ctail_config_match_t cm = {0};
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)
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.. */
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;
if (temp == NULL) {
ERROR("tail plugin: realloc failed.");
tail_match_destroy(tm);
- return (-1);
+ return -1;
}
tail_match_list = temp;
tail_match_list_num++;
}
- return (0);
+ return 0;
} /* int ctail_config_add_file */
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) {
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) {
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],
});
}
- return (0);
+ return 0;
} /* int ctail_init */
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) {