Instance "eth0"
Interval 600
Collect "snort-dropped"
+ FieldSeparator ","
#TimeFrom 0
</File>
</Plugin>
from the field with the zero-based index I<Index>. The value is interpreted as
seconds since epoch. The value is parsed as a double and may be factional.
+=item B<FieldSeparator> I<Character>
+
+Specify the character to use as field separator while parsing the CSV.
+Defaults to ',' if not specified. The value can only be a single character.
+
=back
=back
char *plugin_name;
char *instance;
char *path;
+ char field_separator;
cu_tail_t *tail;
metric_definition_t **metric_list;
size_t metric_list_len;
/* Count the number of fields. */
metrics_num = 1;
for (i = 0; i < buffer_size; i++) {
- if (buffer[i] == ',')
+ if (buffer[i] == id->field_separator)
metrics_num++;
}
metrics[0] = ptr;
i = 1;
for (ptr = buffer; *ptr != 0; ptr++) {
- if (*ptr != ',')
+ if (*ptr != id->field_separator)
continue;
*ptr = 0;
return 0;
}
+static int tcsv_config_get_separator(oconfig_item_t *ci, char *ret_char) {
+ size_t len_opt;
+
+ if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
+ WARNING("tail_csv plugin: The \"%s\" config option needs exactly one "
+ "string argument.",
+ ci->key);
+ return -1;
+ }
+
+ len_opt = strlen(ci->values[0].value.string);
+ if (len_opt != 1) {
+ WARNING("tail_csv plugin: The \"%s\" config option must be a "
+ "single character",
+ ci->key);
+ return -1;
+ }
+
+ *ret_char = ci->values[0].value.string[0];
+ return 0;
+}
+
/* Parse metric */
static int tcsv_config_add_metric(oconfig_item_t *ci) {
metric_definition_t *md;
id->path = NULL;
id->metric_list = NULL;
id->time_from = -1;
+ id->field_separator = ',';
id->next = NULL;
status = cf_util_get_string(ci, &id->path);
status = tcsv_config_get_index(option, &id->time_from);
else if (strcasecmp("Plugin", option->key) == 0)
status = cf_util_get_string(option, &id->plugin_name);
+ else if (strcasecmp("FieldSeparator", option->key) == 0)
+ status = tcsv_config_get_separator(option, &id->field_separator);
else {
WARNING("tail_csv plugin: Option `%s' not allowed here.", option->key);
status = -1;