Merge branch 'collectd-4.6'
authorFlorian Forster <octo@leeloo.lan.home.verplant.org>
Sun, 22 Feb 2009 18:49:33 +0000 (19:49 +0100)
committerFlorian Forster <octo@leeloo.lan.home.verplant.org>
Sun, 22 Feb 2009 18:49:33 +0000 (19:49 +0100)
Conflicts:

src/bind.c

ChangeLog
bindings/perl/Collectd/Unixsock.pm
contrib/cussh.pl
src/bind.c
src/ipmi.c
src/types.db
version-gen.sh

index 6445cdc..10a4cc1 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2009-02-22, Version 4.6.1
+       * collectd: Many documentation fixes.
+       * Collectd::Unixsock: Error handling has been improved.
+       * regex match: Don't link with the PCRE library.
+       * bind plugin: Various bugs have been fixed. Thanks to Bruno PrĂ©mont
+         for finding and fixing most of them.
+       * ipmi plugin: Fix an off-by-one error which could cause segmentation
+         faults. Thanks to Peter Holik for his patch.
+
 2009-02-16, Version 4.6.0
        * collectd: Added the `filter chain' infrastructure, which allows the
          user to use `matches' and `targets' to control value processing.
        * swap plugin: Code for OpenBSD (and possibly other *BSDs) has been
          added.
 
+2009-02-22, Version 4.5.3
+       * build system: The check for libupsclient even when `pkg-config' is
+         not available.
+       * collectd: Fix error handling in the global cache.
+       * Collectd::Unixsock: Error handling has been improved.
+       * ascent plugin: Fix a memory leak. Thanks to Bruno PrĂ©mont for his
+         patch.
+       * ipmi plugin: Fix an off-by-one error which could cause segmentation
+         faults. Thanks to Peter Holik for his patch.
+       * tcpconns plugin: An endianness problem has been fixed in the *BSD
+         code. Thanks to "thated" for reporting this.
+
 2009-01-02, Version 4.5.2
        * build system: Check for `mysql.h' and `mysql/mysql.h', since the
          file may be in both locations, especially when the database was
index eb6e389..4403178 100644 (file)
@@ -287,7 +287,21 @@ sub putval
        }
        else
        {
-               my $time = $args{'time'} ? $args{'time'} : time ();
+               my $time;
+
+               if ("ARRAY" ne ref ($args{'values'}))
+               {
+                       cluck ("Invalid `values' argument (expected an array ref)");
+                       return;
+               }
+
+               if (! scalar @{$args{'values'}})
+               {
+                       cluck ("Empty `values' array");
+                       return;
+               }
+
+               $time = $args{'time'} ? $args{'time'} : time ();
                $values = join (':', $time, map { defined ($_) ? $_ : 'U' } (@{$args{'values'}}));
        }
 
index ee4c893..c143aea 100755 (executable)
@@ -110,13 +110,42 @@ use Collectd::Unixsock();
        exit 0;
 }
 
+sub tokenize {
+       my $line     = shift || return;
+       my $line_ptr = $line;
+       my @line     = ();
+
+       my $token_pattern = qr/[^"\s]+|"[^"]+"/;
+
+       while (my ($token) = $line_ptr =~ m/^($token_pattern)\s+/) {
+               $line_ptr = $';
+               push @line, $token;
+       }
+
+       if ($line_ptr =~ m/^$token_pattern$/) {
+               push @line, $line_ptr;
+       }
+       else {
+               my ($token) = split m/ /, $line_ptr, 1;
+               print STDERR "Failed to parse line: $line\n";
+               print STDERR "Parse error near token \"$token\".\n";
+               return;
+       }
+
+       foreach my $l (@line) {
+               if ($l =~ m/^"(.*)"$/) {
+                       $l = $1;
+               }
+       }
+       return @line;
+}
+
 sub getid {
        my $string = shift || return;
 
-       print $$string . $/;
        my ($h, $p, $pi, $t, $ti) =
-               $$string =~ m#^([^/]+)/([^/-]+)(?:-([^/]+))?/([^/-]+)(?:-([^/]+))?\s*#;
-       $$string = $';
+               $string =~ m#^([^/]+)/([^/-]+)(?:-([^/]+))?/([^/-]+)(?:-([^/]+))?\s*#;
+       $string = $';
 
        return if ((! $h) || (! $p) || (! $t));
 
@@ -172,7 +201,7 @@ HELP
        return 1;
 } # cmd_help
 
-=item B<GETVAL> I<Identifier>
+=item B<PUTVAL> I<Identifier> I<Valuelist>
 
 =cut
 
@@ -180,18 +209,37 @@ sub putval {
        my $sock = shift || return;
        my $line = shift || return;
 
-       my $id = getid(\$line);
+       my @line = tokenize($line);
+
+       my $id;
+       my $ret;
+
+       if (! @line) {
+               return;
+       }
+
+       if (scalar(@line) < 2) {
+               print STDERR "Synopsis: PUTVAL <id> <value0> [<value1> ...]" . $/;
+               return;
+       }
+
+       $id = getid($line[0]);
 
        if (! $id) {
-               print STDERR $sock->{'error'} . $/;
+               print STDERR "Invalid id \"$line[0]\"." . $/;
                return;
        }
 
        my ($time, @values) = split m/:/, $line;
-       return $sock->putval(%$id, time => $time, values => \@values);
+       $ret = $sock->putval(%$id, time => $time, values => \@values);
+
+       if (! $ret) {
+               print STDERR "socket error: " . $sock->{'error'} . $/;
+       }
+       return $ret;
 }
 
-=item B<PUTVAL> I<Identifier> I<Valuelist>
+=item B<GETVAL> I<Identifier>
 
 =cut
 
@@ -199,17 +247,31 @@ sub getval {
        my $sock = shift || return;
        my $line = shift || return;
 
-       my $id = getid(\$line);
+       my @line = tokenize($line);
+
+       my $id;
+       my $vals;
+
+       if (! @line) {
+               return;
+       }
+
+       if (scalar(@line) < 1) {
+               print STDERR "Synopsis: GETVAL <id>" . $/;
+               return;
+       }
+
+       $id = getid($line[0]);
 
        if (! $id) {
-               print STDERR $sock->{'error'} . $/;
+               print STDERR "Invalid id \"$line[0]\"." . $/;
                return;
        }
 
-       my $vals = $sock->getval(%$id);
+       $vals = $sock->getval(%$id);
 
        if (! $vals) {
-               print STDERR $sock->{'error'} . $/;
+               print STDERR "socket error: " . $sock->{'error'} . $/;
                return;
        }
 
@@ -227,6 +289,8 @@ sub flush {
        my $sock = shift || return;
        my $line = shift;
 
+       my @line = tokenize($line);
+
        my $res;
 
        if (! $line) {
@@ -235,7 +299,7 @@ sub flush {
        else {
                my %args = ();
 
-               foreach my $i (split m/ /, $line) {
+               foreach my $i (@line) {
                        my ($option, $value) = $i =~ m/^([^=]+)=(.+)$/;
                        next if (! ($option && $value));
 
@@ -264,10 +328,9 @@ sub flush {
        }
 
        if (! $res) {
-               print STDERR $sock->{'error'} . $/;
-               return;
+               print STDERR "socket error: " . $sock->{'error'} . $/;
        }
-       return 1;
+       return $res;
 }
 
 =item B<LISTVAL>
@@ -276,13 +339,19 @@ sub flush {
 
 sub listval {
        my $sock = shift || return;
+       my $line = shift;
 
        my @res;
 
+       if ($line ne "") {
+               print STDERR "Synopsis: LISTVAL" . $/;
+               return;
+       }
+
        @res = $sock->listval();
 
        if (! @res) {
-               print STDERR $sock->{'error'} . $/;
+               print STDERR "socket error: " . $sock->{'error'} . $/;
                return;
        }
 
@@ -300,19 +369,29 @@ sub putnotif {
        my $sock = shift || return;
        my $line = shift || return;
 
+       my @line = tokenize($line);
+
+       my $ret;
+
        my (%values) = ();
-       foreach my $i (split m/ /, $line) {
-               my($key,$val) = split m/=/, $i, 2;
+       foreach my $i (@line) {
+               my ($key, $val) = split m/=/, $i, 2;
                if ($key && $val) {
                        $values{$key} = $val;
                }
                else {
-                       $values{'message'} .= ' '.$key;
+                       $values{'message'} = defined($values{'message'})
+                               ? ($values{'message'} . ' ' . $key)
+                               : $key;
                }
        }
        $values{'time'} ||= time();
-       my(@tmp) = %values;
-       return $sock->putnotif(%values);
+
+       $ret = $sock->putnotif(%values);
+       if (! $ret) {
+               print STDERR "socket error: " . $sock->{'error'} . $/;
+       }
+       return $ret;
 }
 
 =back
index 13967bb..4b3662f 100644 (file)
@@ -59,7 +59,7 @@
  * `list_info_ptr_t' are passed to the callbacks in the `void *user_data'
  * pointer.
  */
-typedef int (*list_callback_t) (const char *name, counter_t value,
+typedef int (*list_callback_t) (const char *name, value_t value,
     time_t current_time, void *user_data);
 
 struct cb_view_s
@@ -131,7 +131,7 @@ static const translation_info_t nsstats_translation_table[] = /* {{{ */
   /* Rejects */
   { "AuthQryRej",      "dns_reject",   "authorative" },
   { "RecQryRej",       "dns_reject",   "recursive"   },
-  { "XfrRej",          "dns_reject",   "transer"     },
+  { "XfrRej",          "dns_reject",   "transfer"    },
   { "UpdateRej",       "dns_reject",   "update"      },
   /* Responses */
   { "Response",        "dns_response", "normal"      },
@@ -178,7 +178,7 @@ static const translation_info_t zonestats_translation_table[] = /* {{{ */
   { "NotifyRej",       "dns_notify",   "rejected"    },
   /* SOA/AXFS/IXFS requests */
   { "SOAOutv4",        "dns_opcode",   "SOA-IPv4"    },
-  { "SOAOutv6",        "dns_opcode",   "SOA-IPv4"    },
+  { "SOAOutv6",        "dns_opcode",   "SOA-IPv6"    },
   { "AXFRReqv4",       "dns_opcode",   "AXFR-IPv4"   },
   { "AXFRReqv6",       "dns_opcode",   "AXFR-IPv6"   },
   { "IXFRReqv4",       "dns_opcode",   "IXFR-IPv4"   },
@@ -239,13 +239,13 @@ static int memsummary_translation_table_length =
   STATIC_ARRAY_SIZE (memsummary_translation_table);
 /* }}} */
 
-static void submit_counter(time_t ts, const char *plugin_instance, /* {{{ */
-    const char *type, const char *type_instance, counter_t value)
+static void submit (time_t ts, const char *plugin_instance, /* {{{ */
+    const char *type, const char *type_instance, value_t value)
 {
   value_t values[1];
   value_list_t vl = VALUE_LIST_INIT;
 
-  values[0].counter = value;
+  values[0] = value;
 
   vl.values = values;
   vl.values_len = 1;
@@ -264,7 +264,7 @@ static void submit_counter(time_t ts, const char *plugin_instance, /* {{{ */
     replace_special (vl.plugin_instance, sizeof (vl.plugin_instance));
   }
   plugin_dispatch_values(&vl);
-} /* }}} void submit_counter */
+} /* }}} void submit */
 
 static size_t bind_curl_callback (void *buf, size_t size, /* {{{ */
     size_t nmemb, void __attribute__((unused)) *stream)
@@ -299,7 +299,7 @@ static size_t bind_curl_callback (void *buf, size_t size, /* {{{ */
  * Callback, that's called with a translation table.
  * (Plugin instance is fixed, type and type instance come from lookup table.)
  */
-static int bind_xml_table_callback (const char *name, counter_t value, /* {{{ */
+static int bind_xml_table_callback (const char *name, value_t value, /* {{{ */
     time_t current_time, void *user_data)
 {
   translation_table_ptr_t *table = (translation_table_ptr_t *) user_data;
@@ -313,7 +313,7 @@ static int bind_xml_table_callback (const char *name, counter_t value, /* {{{ */
     if (strcmp (table->table[i].xml_name, name) != 0)
       continue;
 
-    submit_counter (current_time,
+    submit (current_time,
         table->plugin_instance,
         table->table[i].type,
         table->table[i].type_instance,
@@ -329,14 +329,14 @@ static int bind_xml_table_callback (const char *name, counter_t value, /* {{{ */
  * (Plugin instance and type are fixed, xml name is used as type instance.)
  */
 static int bind_xml_list_callback (const char *name, /* {{{ */
-    counter_t value, time_t current_time, void *user_data)
+    value_t value, time_t current_time, void *user_data)
 {
   list_info_ptr_t *list_info = (list_info_ptr_t *) user_data;
 
   if (list_info == NULL)
     return (-1);
 
-  submit_counter (current_time,
+  submit (current_time,
       list_info->plugin_instance,
       list_info->type,
       /* type instance = */ name,
@@ -376,6 +376,37 @@ static int bind_xml_read_counter (xmlDoc *doc, xmlNode *node, /* {{{ */
   return (0);
 } /* }}} int bind_xml_read_counter */
 
+static int bind_xml_read_gauge (xmlDoc *doc, xmlNode *node, /* {{{ */
+    gauge_t *ret_value)
+{
+  char *str_ptr, *end_ptr;
+  double value;
+
+  str_ptr = (char *) xmlNodeListGetString (doc, node->xmlChildrenNode, 1);
+  if (str_ptr == NULL)
+  {
+    ERROR ("bind plugin: bind_xml_read_gauge: xmlNodeListGetString failed.");
+    return (-1);
+  }
+
+  errno = 0;
+  value = strtod (str_ptr, &end_ptr);
+  xmlFree(str_ptr);
+  if (str_ptr == end_ptr || errno)
+  {
+    if (errno && (value < 0))
+      ERROR ("bind plugin: bind_xml_read_gauge: strtod failed with underflow.");
+    else if (errno && (value > 0))
+      ERROR ("bind plugin: bind_xml_read_gauge: strtod failed with overflow.");
+    else
+      ERROR ("bind plugin: bind_xml_read_gauge: strtod failed.");
+    return (-1);
+  }
+
+  *ret_value = (gauge_t) value;
+  return (0);
+} /* }}} int bind_xml_read_gauge */
+
 static int bind_xml_read_timestamp (const char *xpath_expression, /* {{{ */
     xmlDoc *doc, xmlXPathContext *xpathCtx, time_t *ret_value)
 {
@@ -446,7 +477,7 @@ static int bind_xml_read_timestamp (const char *xpath_expression, /* {{{ */
  * Reads statistics in the form:
  * <foo>
  *   <name>QUERY</name>
- *   <value>123</name>
+ *   <counter>123</counter>
  * </foo>
  */
 static int bind_parse_generic_name_value (const char *xpath_expression, /* {{{ */
@@ -473,10 +504,15 @@ static int bind_parse_generic_name_value (const char *xpath_expression, /* {{{ *
   {
     xmlNode *name_node = NULL;
     xmlNode *counter = NULL;
+    xmlNode *parent;
     xmlNode *child;
 
+    parent = xpathObj->nodesetval->nodeTab[i];
+    DEBUG ("bind plugin: bind_parse_generic_name_value: parent->name = %s;",
+        (char *) parent->name);
+
     /* Iterate over all child nodes. */
-    for (child = xpathObj->nodesetval->nodeTab[i]->xmlChildrenNode;
+    for (child = parent->xmlChildrenNode;
         child != NULL;
         child = child->next)
     {
@@ -493,10 +529,10 @@ static int bind_parse_generic_name_value (const char *xpath_expression, /* {{{ *
     {
       char *name = (char *) xmlNodeListGetString (doc,
           name_node->xmlChildrenNode, 1);
-      counter_t value;
+      value_t value;
       int status;
 
-      status = bind_xml_read_counter (doc, counter, &value);
+      status = bind_xml_read_counter (doc, counter, &value.counter);
       if (status != 0)
         continue;
 
@@ -532,7 +568,7 @@ static int bind_parse_generic_value_list (const char *xpath_expression, /* {{{ *
     list_callback_t list_callback,
     void *user_data,
     xmlDoc *doc, xmlXPathContext *xpathCtx,
-    time_t current_time)
+    time_t current_time, int ds_type)
 {
   xmlXPathObject *xpathObj = NULL;
   int num_entries;
@@ -558,14 +594,18 @@ static int bind_parse_generic_value_list (const char *xpath_expression, /* {{{ *
         child = child->next)
     {
       char *node_name;
-      counter_t value;
+      value_t value;
       int status;
 
       if (child->type != XML_ELEMENT_NODE)
         continue;
 
       node_name = (char *) child->name;
-      status = bind_xml_read_counter (doc, child, &value);
+
+      if (ds_type == DS_TYPE_GAUGE)
+        status = bind_xml_read_gauge (doc, child, &value.gauge);
+      else
+        status = bind_xml_read_counter (doc, child, &value.counter);
       if (status != 0)
         continue;
 
@@ -650,7 +690,7 @@ static int bind_xml_stats_handle_zone (int version, xmlDoc *doc, /* {{{ */
     bind_parse_generic_value_list (/* xpath = */ "counters",
         /* callback = */ bind_xml_table_callback,
         /* user_data = */ &table_ptr,
-        doc, path_ctx, current_time);
+        doc, path_ctx, current_time, DS_TYPE_COUNTER);
   } /* }}} */
 
   xmlXPathFreeObject (path_obj);
@@ -959,7 +999,7 @@ static int bind_xml_stats (int version, xmlDoc *doc, /* {{{ */
       bind_parse_generic_value_list ("server/nsstats",
           /* callback = */ bind_xml_table_callback,
           /* user_data = */ &table_ptr,
-          doc, xpathCtx, current_time);
+          doc, xpathCtx, current_time, DS_TYPE_COUNTER);
     }
     else
     {
@@ -1005,7 +1045,7 @@ static int bind_xml_stats (int version, xmlDoc *doc, /* {{{ */
       bind_parse_generic_value_list ("server/zonestats",
           /* callback = */ bind_xml_table_callback,
           /* user_data = */ &table_ptr,
-          doc, xpathCtx, current_time);
+          doc, xpathCtx, current_time, DS_TYPE_COUNTER);
     }
     else
     {
@@ -1052,7 +1092,7 @@ static int bind_xml_stats (int version, xmlDoc *doc, /* {{{ */
       bind_parse_generic_value_list ("server/resstats",
           /* callback = */ bind_xml_table_callback,
           /* user_data = */ &table_ptr,
-          doc, xpathCtx, current_time);
+          doc, xpathCtx, current_time, DS_TYPE_COUNTER);
     }
     else
     {
@@ -1086,7 +1126,7 @@ static int bind_xml_stats (int version, xmlDoc *doc, /* {{{ */
     bind_parse_generic_value_list ("memory/summary",
           /* callback = */ bind_xml_table_callback,
           /* user_data = */ &table_ptr,
-          doc, xpathCtx, current_time);
+          doc, xpathCtx, current_time, DS_TYPE_GAUGE);
   }
 
   if (views_num > 0)
@@ -1302,7 +1342,16 @@ static int bind_config (oconfig_item_t *ci) /* {{{ */
   {
     oconfig_item_t *child = ci->children + i;
 
-    if (strcasecmp ("OpCodes", child->key) == 0)
+    if (strcasecmp ("Url", child->key) == 0) {
+      if ((child->values_num != 1) || (child->values[0].type != OCONFIG_TYPE_STRING))
+      {
+        WARNING ("bind plugin: The `Url' option needs "
+                 "exactly one string argument.");
+        return (-1);
+      }
+
+      url = strdup (child->values[0].value.string);
+    } else if (strcasecmp ("OpCodes", child->key) == 0)
       bind_config_set_bool ("OpCodes", &global_opcodes, child);
     else if (strcasecmp ("QTypes", child->key) == 0)
       bind_config_set_bool ("QTypes", &global_qtypes, child);
@@ -1313,7 +1362,7 @@ static int bind_config (oconfig_item_t *ci) /* {{{ */
     else if (strcasecmp ("ResolverStats", child->key) == 0)
       bind_config_set_bool ("ResolverStats", &global_resolver_stats, child);
     else if (strcasecmp ("MemoryStats", child->key) == 0)
-      bind_config_set_bool ("MemoryStats", &global_resolver_stats, child);
+      bind_config_set_bool ("MemoryStats", &global_memory_stats, child);
     else if (strcasecmp ("View", child->key) == 0)
       bind_config_add_view (child);
     else
index 0b79823..44fae35 100644 (file)
@@ -234,35 +234,54 @@ static int sensor_list_add (ipmi_sensor_t *sensor)
   c_ipmi_sensor_list_t *list_item;
   c_ipmi_sensor_list_t *list_prev;
 
+  char buffer[DATA_MAX_NAME_LEN];
+  const char *entity_id_string;
   char sensor_name[DATA_MAX_NAME_LEN];
   char *sensor_name_ptr;
-  int sensor_type, len;
+  int sensor_type;
   const char *type;
   ipmi_entity_t *ent = ipmi_sensor_get_entity(sensor);
 
   sensor_id = ipmi_sensor_convert_to_id (sensor);
 
-  memset (sensor_name, 0, sizeof (sensor_name));
-  ipmi_sensor_get_name (sensor, sensor_name, sizeof (sensor_name));
-  sensor_name[sizeof (sensor_name) - 1] = 0;
+  memset (buffer, 0, sizeof (buffer));
+  ipmi_sensor_get_name (sensor, buffer, sizeof (buffer));
+  buffer[sizeof (buffer) - 1] = 0;
 
-  len = DATA_MAX_NAME_LEN - strlen(sensor_name);
-  strncat(sensor_name, " ", len--);
-  strncat(sensor_name, ipmi_entity_get_entity_id_string(ent), len);
+  entity_id_string = ipmi_entity_get_entity_id_string (ent);
 
-  sensor_name_ptr = strstr (sensor_name, ").");
-  if (sensor_name_ptr == NULL)
-    sensor_name_ptr = sensor_name;
+  if (entity_id_string == NULL)
+    sstrncpy (sensor_name, buffer, sizeof (sensor_name));
   else
-  {
-    char *sensor_name_ptr_id = strstr (sensor_name, "(");
-
+    ssnprintf (sensor_name, sizeof (sensor_name),
+        "%s %s", buffer, entity_id_string);
+
+  sstrncpy (buffer, sensor_name, sizeof (buffer));
+  sensor_name_ptr = strstr (buffer, ").");
+  if (sensor_name_ptr != NULL)
+  {
+    /* If name is something like "foo (123).bar",
+     * change that to "bar (123)".
+     * Both, sensor_name_ptr and sensor_id_ptr point to memory within the
+     * `buffer' array, which holds a copy of the current `sensor_name'. */
+    char *sensor_id_ptr;
+
+    /* `sensor_name_ptr' points to ").bar". */
+    sensor_name_ptr[1] = 0;
+    /* `buffer' holds "foo (123)\0bar\0". */
     sensor_name_ptr += 2;
-    len = DATA_MAX_NAME_LEN - strlen(sensor_name);
-    strncat(sensor_name, " ", len--);
-    strncat(sensor_name, sensor_name_ptr_id, 
-      MIN(sensor_name_ptr - sensor_name_ptr_id - 1, len));
+    /* `sensor_name_ptr' now points to "bar". */
+
+    sensor_id_ptr = strstr (buffer, "(");
+    if (sensor_id_ptr != NULL)
+    {
+      /* `sensor_id_ptr' now points to "(123)". */
+      ssnprintf (sensor_name, sizeof (sensor_name),
+          "%s %s", sensor_name_ptr, sensor_id_ptr); 
+    }
+    /* else: don't touch sensor_name. */
   }
+  sensor_name_ptr = sensor_name;
 
   /* Both `ignorelist' and `plugin_instance' may be NULL. */
   if (ignorelist_match (ignorelist, sensor_name_ptr) != 0)
index 6d01532..82b5b4f 100644 (file)
@@ -33,6 +33,7 @@ dns_notify            value:COUNTER:0:65535
 dns_transfer           value:COUNTER:0:65535
 dns_query              value:COUNTER:0:65535
 dns_response           value:COUNTER:0:65535
+dns_reject             value:COUNTER:0:65535
 email_check            value:GAUGE:0:U
 email_count            value:GAUGE:0:U
 email_size             value:GAUGE:0:U
index c310059..69e4f9a 100755 (executable)
@@ -1,6 +1,6 @@
 #!/bin/sh
 
-DEFAULT_VERSION="4.6.0.git"
+DEFAULT_VERSION="4.6.1.git"
 
 VERSION="$( git describe 2> /dev/null | sed -e 's/^collectd-//' )"