summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 5f4cf91)
raw | patch | inline | side by side (parent: 5f4cf91)
author | Florian Forster <octo@collectd.org> | |
Wed, 20 Feb 2013 07:47:51 +0000 (08:47 +0100) | ||
committer | Florian Forster <octo@collectd.org> | |
Wed, 20 Feb 2013 07:47:51 +0000 (08:47 +0100) |
Also renamed "count" to "metrics_num" to make it clear that the two
relate to one another.
relate to one another.
src/snort.c | patch | blob | history |
diff --git a/src/snort.c b/src/snort.c
index 68be07f74050712499801d4e29e642f0738dfca8..6da5030296a83400d9c7181236d24d5eab075b7b 100644 (file)
--- a/src/snort.c
+++ b/src/snort.c
/**
* collectd - src/snort.c
* Copyright (C) 2013 Kris Nielander
- *
+ *
* 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.
value_t value;
value_list_t vl = VALUE_LIST_INIT;
- DEBUG("snort plugin: plugin_instance=%s type=%s value=%s", id->name,
+ DEBUG("snort plugin: plugin_instance=%s type=%s value=%s", id->name,
md->type, buf);
if (buf == NULL)
@@ -91,10 +91,10 @@ static int snort_read_submit(instance_definition_t *id, metric_definition_t *md,
static int snort_read(user_data_t *ud){
instance_definition_t *id;
metric_definition_t *md;
-
+
int i;
int fd;
- int count;
+ int metrics_num;
char **metrics;
char **metrics_t;
return (-1);
}
- p_start = mmap(/* addr = */ NULL, sb.st_size, PROT_READ, MAP_SHARED, fd,
+ p_start = mmap(/* addr = */ NULL, sb.st_size, PROT_READ, MAP_SHARED, fd,
/* offset = */ 0);
if (p_start == MAP_FAILED){
ERROR("snort plugin: mmap error");
}
/* Set the start value count. */
- count = 1;
+ metrics_num = 1;
- /* Set the pointer to the last line of the file and count the fields.
- (Skip the last two characters of the buffer: `\n' and `\0') */
+ /* Set the pointer to the last line of the file and count the fields.
+ (Skip the last two characters of the buffer: `\n' and `\0') */
for (p_end = (p_start + sb.st_size) - 2; p_end > p_start; --p_end){
if (*p_end == ','){
- ++count;
+ ++metrics_num;
} else if (*p_end == '\n'){
++p_end;
break;
}
}
-
- if (count == 1){
+
+ if (metrics_num == 1){
ERROR("snort plugin: last line of `%s' does not contain enough values.", id->path);
return (-1);
}
munmap(p_start, sb.st_size);
/* Create a list of all values */
- metrics = (char **)calloc(count, sizeof(char *));
- if (metrics == NULL){
+ metrics = calloc (metrics_num, sizeof (*metrics));
+ if (metrics == NULL) {
+ ERROR ("snort plugin: calloc failed.");
return (-1);
}
for (metrics_t = metrics; (*metrics_t = strsep(&buf_t, ",")) != NULL;)
if (**metrics_t != '\0')
- if (++metrics_t >= &metrics[count])
+ if (++metrics_t >= &metrics[metrics_num])
break;
/* Set last time */
/* Register values */
for (i = 0; i < id->metric_list_len; ++i){
md = id->metric_list[i];
+
+ if (md->index >= metrics_num) {
+ ERROR ("snort plugin: Metric \"%s\": Request for index %i when "
+ "only %i fields are available.",
+ md->name, md->index, metrics_num);
+ continue;
+ }
+
snort_read_submit(id, md, metrics[md->index]);
}
snort_metric_definition_destroy(md);
return (-1);
}
-
+
/* Retrieve the data source type from the types db. */
ds = plugin_get_ds(md->type);
if (ds == NULL){