B<Synopsis:>
<Plugin "tail_csv">
- <Metric "dropped">
+ <Metric "snort-dropped">
Type "percent"
Instance "dropped"
Index 1
</Metric>
- <Instance "snort-eth0">
- Path "/var/log/snort/snort.stats"
+ <File "/var/log/snort/snort.stats">
+ Instance "snort-eth0"
Interval 600
- Collect "dropped"
- </Instance>
+ Collect "snort-dropped"
+ </File>
</Plugin>
The configuration consists of one or more B<Metric> blocks that define an index
=back
-=item E<lt>B<Instance> I<Name>E<gt>
+=item E<lt>B<File> I<Path>E<gt>
-Each B<Instance> block represents on CSV file to read. The block's I<Name>
-will be used as I<plugin instance> when dispatching the values and is used to
-support multiple separate CSV files. There must be at least one I<Instance>
-block but there can be multiple if you have multiple CSV files.
+Each B<File> block represents one CSV file to read. There must be at least one
+I<File> block but there can be multiple if you have multiple CSV files.
=over 4
-=item B<Path> I<Path>
+=item B<Instance> I<PluginInstance>
-Configures the I<Path> to the statistics file to read.
+Sets the I<plugin instance> used when dispatching the values.
=item B<Collect> I<Metric>
typedef struct metric_definition_s metric_definition_t;
struct instance_definition_s {
- char *name;
+ char *instance;
char *path;
cu_tail_t *tail;
metric_definition_t **metric_list;
sstrncpy(vl.host, hostname_g, sizeof (vl.host));
sstrncpy(vl.plugin, "tail_csv", sizeof(vl.plugin));
- sstrncpy(vl.plugin_instance, id->name, sizeof(vl.plugin_instance));
+ sstrncpy(vl.plugin_instance, id->instance, sizeof(vl.plugin_instance));
sstrncpy(vl.type, md->type, sizeof(vl.type));
if (md->instance != NULL)
sstrncpy(vl.type_instance, md->instance, sizeof(vl.type_instance));
instance_definition_t *id;
id = ud->data;
- DEBUG("tail_csv plugin: tcsv_read (instance = %s)", id->name);
+ DEBUG("tail_csv plugin: tcsv_read (instance = %s)", id->instance);
if (id->tail == NULL)
{
if (status != 0)
{
ERROR ("tail_csv plugin: Instance \"%s\": cu_tail_readline failed "
- "with status %i.", id->name, status);
+ "with status %i.", id->instance, status);
return (-1);
}
if (id == NULL)
return;
- if (id->name != NULL)
- DEBUG("tail_csv plugin: Destroying instance definition `%s'.", id->name);
+ if (id->instance != NULL)
+ DEBUG("tail_csv plugin: Destroying instance definition `%s'.", id->instance);
cu_tail_destroy (id->tail);
id->tail = NULL;
- sfree(id->name);
+ sfree(id->instance);
sfree(id->path);
sfree(id->metric_list);
sfree(id);
return (-1);
}
- DEBUG("tail_csv plugin: id { name=%s md->name=%s }", id->name, metric->name);
+ DEBUG("tail_csv plugin: id { instance=%s md->name=%s }", id->instance, metric->name);
id->metric_list[i] = metric;
id->metric_list_len++;
}
/* Parse instance */
-static int tcsv_config_add_instance(oconfig_item_t *ci){
-
+static int tcsv_config_add_file(oconfig_item_t *ci)
+{
instance_definition_t* id;
int status = 0;
int i;
user_data_t cb_data;
struct timespec cb_interval;
- if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)){
- WARNING("tail_csv plugin: The `Instance' config option needs exactly one string argument.");
- return (-1);
- }
-
- id = (instance_definition_t *)malloc(sizeof(*id));
+ id = malloc(sizeof(*id));
if (id == NULL)
return (-1);
memset(id, 0, sizeof(*id));
+ id->instance = NULL;
+ id->path = NULL;
+ id->metric_list = NULL;
+ id->next = NULL;
- id->name = strdup(ci->values[0].value.string);
- if (id->name == NULL){
- free(id);
- return (-1);
+ status = cf_util_get_string (ci, &id->path);
+ if (status != 0) {
+ sfree (id);
+ return (status);
}
/* Use default interval. */
oconfig_item_t *option = ci->children + i;
status = 0;
- if (strcasecmp("Path", option->key) == 0)
- status = cf_util_get_string(option, &id->path);
+ if (strcasecmp("Instance", option->key) == 0)
+ status = cf_util_get_string(option, &id->instance);
else if (strcasecmp("Collect", option->key) == 0)
status = tcsv_config_add_instance_collect(id, option);
else if (strcasecmp("Interval", option->key) == 0)
return (-1);
}
- DEBUG("tail_csv plugin: id = { name = %s, path = %s }", id->name, id->path);
+ DEBUG("tail_csv plugin: id = { instance = %s, path = %s }", id->instance, id->path);
- ssnprintf (cb_name, sizeof (cb_name), "tail_csv/%s", id->name);
+ ssnprintf (cb_name, sizeof (cb_name), "tail_csv/%s", id->path);
memset(&cb_data, 0, sizeof(cb_data));
cb_data.data = id;
cb_data.free_func = tcsv_instance_definition_destroy;
oconfig_item_t *child = ci->children + i;
if (strcasecmp("Metric", child->key) == 0)
tcsv_config_add_metric(child);
- else if (strcasecmp("Instance", child->key) == 0)
- tcsv_config_add_instance(child);
+ else if (strcasecmp("File", child->key) == 0)
+ tcsv_config_add_file(child);
else
WARNING("tail_csv plugin: Ignore unknown config option `%s'.", child->key);
}