tail_csv plugin: Rename the "Index" option to "ValueFrom".
authorFlorian Forster <octo@collectd.org>
Sat, 23 Mar 2013 07:57:43 +0000 (08:57 +0100)
committerFlorian Forster <octo@collectd.org>
Sat, 23 Mar 2013 07:57:43 +0000 (08:57 +0100)
src/collectd.conf.in
src/collectd.conf.pod
src/tail_csv.c

index 8afad3e..75e2291 100644 (file)
 #   <Metric "dropped">
 #       Type "percent"
 #       Instance "dropped"
 #   <Metric "dropped">
 #       Type "percent"
 #       Instance "dropped"
-#       Index 1
+#       ValueFrom 1
 #   </Metric>
 #   <Metric "mbps">
 #       Type "bytes"
 #       Instance "wire-realtime"
 #   </Metric>
 #   <Metric "mbps">
 #       Type "bytes"
 #       Instance "wire-realtime"
-#       Index 2
+#       ValueFrom 2
 #   </Metric>
 #   <Metric "alerts">
 #       Type "alerts_per_second"
 #   </Metric>
 #   <Metric "alerts">
 #       Type "alerts_per_second"
-#       Index 3
+#       ValueFrom 3
 #   </Metric>
 #   <Metric "kpps">
 #       Type "kpackets_wire_per_sec.realtime"
 #   </Metric>
 #   <Metric "kpps">
 #       Type "kpackets_wire_per_sec.realtime"
-#       Index 4
+#       ValueFrom 4
 #   </Metric>
 #   <File "/var/log/snort/snort.stats">
 #       Instance "snort-eth0"
 #   </Metric>
 #   <File "/var/log/snort/snort.stats">
 #       Instance "snort-eth0"
index 75509e8..c740808 100644 (file)
@@ -5170,12 +5170,11 @@ I<Type's> definition.
 If set, I<TypeInstance> is used to populate the type instance field of the
 created value lists. Otherwise, no type instance is used.
 
 If set, I<TypeInstance> is used to populate the type instance field of the
 created value lists. Otherwise, no type instance is used.
 
-=item B<Index> I<Index>
+=item B<ValueFrom> I<Index>
 
 Each line in the statistics file is broken into many fields with the first
 field, the timestamp of the line, is index with zero. This option configures to
 
 Each line in the statistics file is broken into many fields with the first
 field, the timestamp of the line, is index with zero. This option configures to
-read the value from the field with index I<Index>. Since the first field is
-always the timestamp, I<Index> must be greater than zero.
+read the value from the field with index I<Index>.
 
 =back
 
 
 =back
 
index dc89f0d..3a8304a 100644 (file)
@@ -37,7 +37,7 @@ struct metric_definition_s {
     char *type;
     char *instance;
     int data_source_type;
     char *type;
     char *instance;
     int data_source_type;
-    int index;
+    int value_from;
     struct metric_definition_s *next;
 };
 typedef struct metric_definition_s metric_definition_t;
     struct metric_definition_s *next;
 };
 typedef struct metric_definition_s metric_definition_t;
@@ -105,12 +105,12 @@ static int tcsv_read_metric (instance_definition_t *id,
     if (md->data_source_type == -1)
         return (EINVAL);
 
     if (md->data_source_type == -1)
         return (EINVAL);
 
-    if (md->index >= fields_num)
+    if (md->value_from >= fields_num)
         return (EINVAL);
 
     t = parse_time (fields[0]);
 
         return (EINVAL);
 
     t = parse_time (fields[0]);
 
-    status = parse_value (fields[md->index], &v, md->data_source_type);
+    status = parse_value (fields[md->value_from], &v, md->data_source_type);
     if (status != 0)
         return (status);
 
     if (status != 0)
         return (status);
 
@@ -178,10 +178,10 @@ static int tcsv_read_buffer (instance_definition_t *id,
     for (i = 0; i < id->metric_list_len; ++i){
         metric_definition_t *md = id->metric_list[i];
 
     for (i = 0; i < id->metric_list_len; ++i){
         metric_definition_t *md = id->metric_list[i];
 
-        if (((size_t) md->index) >= metrics_num) {
+        if (((size_t) md->value_from) >= metrics_num) {
             ERROR ("tail_csv plugin: Metric \"%s\": Request for index %i when "
                     "only %zu fields are available.",
             ERROR ("tail_csv plugin: Metric \"%s\": Request for index %i when "
                     "only %zu fields are available.",
-                    md->name, md->index, metrics_num);
+                    md->name, md->value_from, metrics_num);
             continue;
         }
 
             continue;
         }
 
@@ -251,18 +251,23 @@ static void tcsv_metric_definition_destroy(void *arg){
     tcsv_metric_definition_destroy (next);
 }
 
     tcsv_metric_definition_destroy (next);
 }
 
-static int tcsv_config_add_metric_index(metric_definition_t *md, oconfig_item_t *ci){
+static int tcsv_config_get_index(oconfig_item_t *ci, int *ret_index) {
+    int index;
+
     if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_NUMBER)){
     if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_NUMBER)){
-        WARNING("tail_csv plugin: `Index' needs exactly one integer argument.");
+        WARNING("tail_csv plugin: The \"%s\" config option needs exactly one "
+                "integer argument.", ci->key);
         return (-1);
     }
 
         return (-1);
     }
 
-    md->index = (int)ci->values[0].value.number;
-    if (md->index <= 0){
-        WARNING("tail_csv plugin: `Index' must be higher than 0.");
+    index = (int) ci->values[0].value.number;
+    if (index < 0) {
+        WARNING("tail_csv plugin: The \"%s\" config option must be positive "
+                "(or zero).", ci->key);
         return (-1);
     }
 
         return (-1);
     }
 
+    *ret_index = index;
     return (0);
 }
 
     return (0);
 }
 
@@ -280,6 +285,7 @@ static int tcsv_config_add_metric(oconfig_item_t *ci){
     md->type = NULL;
     md->instance = NULL;
     md->data_source_type = -1;
     md->type = NULL;
     md->instance = NULL;
     md->data_source_type = -1;
+    md->value_from = -1;
     md->next = NULL;
 
     status = cf_util_get_string (ci, &md->name);
     md->next = NULL;
 
     status = cf_util_get_string (ci, &md->name);
@@ -296,8 +302,8 @@ static int tcsv_config_add_metric(oconfig_item_t *ci){
             status = cf_util_get_string(option, &md->type);
         else if (strcasecmp("Instance", option->key) == 0)
             status = cf_util_get_string(option, &md->instance);
             status = cf_util_get_string(option, &md->type);
         else if (strcasecmp("Instance", option->key) == 0)
             status = cf_util_get_string(option, &md->instance);
-        else if (strcasecmp("Index", option->key) == 0)
-            status = tcsv_config_add_metric_index(md, option);
+        else if (strcasecmp("ValueFrom", option->key) == 0)
+            status = tcsv_config_get_index (option, &md->value_from);
         else {
             WARNING("tail_csv plugin: Option `%s' not allowed here.", option->key);
             status = -1;
         else {
             WARNING("tail_csv plugin: Option `%s' not allowed here.", option->key);
             status = -1;
@@ -316,8 +322,8 @@ static int tcsv_config_add_metric(oconfig_item_t *ci){
     if (md->type == NULL) {
         WARNING("tail_csv plugin: Option `Type' must be set.");
         status = -1;
     if (md->type == NULL) {
         WARNING("tail_csv plugin: Option `Type' must be set.");
         status = -1;
-    } else if (md->index == 0) {
-        WARNING("tail_csv plugin: Option `Index' must be set.");
+    } else if (md->value_from < 0) {
+        WARNING("tail_csv plugin: Option `ValueFrom' must be set.");
         status = -1;
     }
     if (status != 0) {
         status = -1;
     }
     if (status != 0) {
@@ -325,9 +331,6 @@ static int tcsv_config_add_metric(oconfig_item_t *ci){
         return (status);
     }
 
         return (status);
     }
 
-    DEBUG ("tail_csv plugin: md = { name = %s, type = %s, index = %d }",
-            md->name, md->type, md->index);
-
     if (metric_head == NULL)
         metric_head = md;
     else {
     if (metric_head == NULL)
         metric_head = md;
     else {