network plugin: Add the DERIVE and ABSOLUTE data source types.
[collectd.git] / src / network.c
index cc48215..d88f503 100644 (file)
@@ -19,6 +19,8 @@
  *   Florian octo Forster <octo at verplant.org>
  **/
 
+#define _BSD_SOURCE /* For struct ip_mreq */
+
 #include "collectd.h"
 #include "plugin.h"
 #include "common.h"
@@ -525,17 +527,34 @@ static int write_part_values (char **ret_buffer, int *ret_buffer_len,
 
        for (i = 0; i < num_values; i++)
        {
-               if (ds->ds[i].type == DS_TYPE_COUNTER)
-               {
-                       pkg_values_types[i] = DS_TYPE_COUNTER;
-                       pkg_values[i].counter = htonll (vl->values[i].counter);
-               }
-               else
+               pkg_values_types[i] = (uint8_t) ds->ds[i].type;
+               switch (ds->ds[i].type)
                {
-                       pkg_values_types[i] = DS_TYPE_GAUGE;
-                       pkg_values[i].gauge = htond (vl->values[i].gauge);
-               }
-       }
+                       case DS_TYPE_COUNTER:
+                               pkg_values[i].counter = htonll (vl->values[i].counter);
+                               break;
+
+                       case DS_TYPE_GAUGE:
+                               pkg_values[i].gauge = htond (vl->values[i].gauge);
+                               break;
+
+                       case DS_TYPE_DERIVE:
+                               pkg_values[i].derive = htonll (vl->values[i].derive);
+                               break;
+
+                       case DS_TYPE_ABSOLUTE:
+                               pkg_values[i].absolute = htonll (vl->values[i].absolute);
+                               break;
+
+                       default:
+                               free (pkg_values_types);
+                               free (pkg_values);
+                               ERROR ("network plugin: write_part_values: "
+                                               "Unknown data source type: %i",
+                                               ds->ds[i].type);
+                               return (-1);
+               } /* switch (ds->ds[i].type) */
+       } /* for (num_values) */
 
        /*
         * Use `memcpy' to write everything to the buffer, because the pointer
@@ -711,6 +730,33 @@ static int parse_part_values (void **ret_buffer, size_t *ret_buffer_len,
 
        for (i = 0; i < pkg_numval; i++)
        {
+               switch (pkg_types[i])
+               {
+                 case DS_TYPE_COUNTER:
+                   pkg_values[i].counter = ntohll (pkg_values[i].counter);
+                   break;
+
+                 case DS_TYPE_GAUGE:
+                   pkg_values[i].gauge = ntohd (pkg_values[i].gauge);
+                   break;
+
+                 case DS_TYPE_DERIVE:
+                   pkg_values[i].derive = ntohll (pkg_values[i].derive);
+                   break;
+
+                 case DS_TYPE_ABSOLUTE:
+                   pkg_values[i].absolute = ntohll (pkg_values[i].absolute);
+                   break;
+
+                 default:
+                   sfree (pkg_types);
+                   sfree (pkg_values);
+                   NOTICE ("network plugin: parse_part_values: "
+                       "Don't know how to handle data source type %"PRIu8,
+                       pkg_types[i]);
+                   return (-1);
+               } /* switch (pkg_types[i]) */
+
                if (pkg_types[i] == DS_TYPE_COUNTER)
                        pkg_values[i].counter = ntohll (pkg_values[i].counter);
                else if (pkg_types[i] == DS_TYPE_GAUGE)
@@ -2259,9 +2305,6 @@ static void networt_send_buffer_encrypted (sockent_t *se, /* {{{ */
   gcry_error_t err;
   gcry_cipher_hd_t cypher;
 
-  DEBUG ("network plugin: networt_send_buffer_encrypted: "
-      "buffer_size = %zu;", buffer_size);
-
   /* Initialize the header fields */
   memset (&pea, 0, sizeof (pea));
   pea.head.type = htons (TYPE_ENCR_AES256);
@@ -2280,6 +2323,8 @@ static void networt_send_buffer_encrypted (sockent_t *se, /* {{{ */
     - sizeof (pea.hash);
 
   assert (buffer_size <= sizeof (buffer));
+  DEBUG ("network plugin: networt_send_buffer_encrypted: "
+      "buffer_size = %zu;", buffer_size);
 
   pea.head.length = htons ((uint16_t) (PART_ENCRYPTION_AES256_SIZE
         + username_len + in_buffer_size));
@@ -2545,6 +2590,7 @@ static int network_config_set_ttl (const oconfig_item_t *ci) /* {{{ */
   return (0);
 } /* }}} int network_config_set_ttl */
 
+#if HAVE_LIBGCRYPT
 static int network_config_set_string (const oconfig_item_t *ci, /* {{{ */
     char **ret_string)
 {
@@ -2566,6 +2612,7 @@ static int network_config_set_string (const oconfig_item_t *ci, /* {{{ */
 
   return (0);
 } /* }}} int network_config_set_string */
+#endif /* HAVE_LIBGCRYPT */
 
 #if HAVE_LIBGCRYPT
 static int network_config_set_security_level (oconfig_item_t *ci, /* {{{ */
@@ -2642,6 +2689,7 @@ static int network_config_add_listen (const oconfig_item_t *ci) /* {{{ */
     }
   }
 
+#if HAVE_LIBGCRYPT
   if ((se->data.server.security_level > SECURITY_LEVEL_NONE)
       && (se->data.server.auth_file == NULL))
   {
@@ -2651,6 +2699,7 @@ static int network_config_add_listen (const oconfig_item_t *ci) /* {{{ */
     sockent_destroy (se);
     return (-1);
   }
+#endif /* HAVE_LIBGCRYPT */
 
   status = sockent_open (se);
   if (status != 0)
@@ -2718,6 +2767,7 @@ static int network_config_add_server (const oconfig_item_t *ci) /* {{{ */
     }
   }
 
+#if HAVE_LIBGCRYPT
   if ((se->data.client.security_level > SECURITY_LEVEL_NONE)
       && ((se->data.client.username == NULL)
         || (se->data.client.password == NULL)))
@@ -2728,6 +2778,7 @@ static int network_config_add_server (const oconfig_item_t *ci) /* {{{ */
     sockent_destroy (se);
     return (-1);
   }
+#endif /* HAVE_LIBGCRYPT */
 
   status = sockent_open (se);
   if (status != 0)