Code

Prefix is no longer a required directive
authorScott Sanders <scott@jssjr.com>
Sun, 9 Oct 2011 23:08:27 +0000 (19:08 -0400)
committerScott Sanders <scott@jssjr.com>
Sun, 9 Oct 2011 23:08:27 +0000 (19:08 -0400)
While useful, the user should not be required to provide a prefix.
Having the hosts as the top level containers may make sense in some
environments. The current format is "${prefix}${hostname}${postfix}" so
be careful to add dots where needed.

Also updated docs to reflect this change.

src/write_graphite.c

index 4fc38fb31df94aae02e478266c2f55c112348ce9..57933e8dc3c518f77fa5f1aa72b6ba82f12b8436 100644 (file)
@@ -378,20 +378,20 @@ static int wg_format_name (char *ret, int ret_len,
         if ((n_type_instance == NULL) || (n_type_instance[0] == '\0'))
         {
             if ((ds_name == NULL) || (ds_name[0] == '\0'))
-                status = ssnprintf (ret, ret_len, "%s.%s%s.%s.%s",
+                status = ssnprintf (ret, ret_len, "%s%s%s.%s.%s",
                         prefix, n_hostname, postfix, plugin, type);
             else
-                status = ssnprintf (ret, ret_len, "%s.%s%s.%s.%s.%s",
+                status = ssnprintf (ret, ret_len, "%s%s%s.%s.%s.%s",
                         prefix, n_hostname, postfix, plugin, type, ds_name);
         }
         else
         {
             if ((ds_name == NULL) || (ds_name[0] == '\0'))
-                status = ssnprintf (ret, ret_len, "%s.%s%s.%s.%s-%s",
+                status = ssnprintf (ret, ret_len, "%s%s%s.%s.%s-%s",
                         prefix, n_hostname, postfix, plugin, type,
                         n_type_instance);
             else
-                status = ssnprintf (ret, ret_len, "%s.%s%s.%s.%s-%s.%s",
+                status = ssnprintf (ret, ret_len, "%s%s%s.%s.%s-%s.%s",
                         prefix, n_hostname, postfix, plugin, type,
                         n_type_instance, ds_name);
         }
@@ -401,22 +401,22 @@ static int wg_format_name (char *ret, int ret_len,
         if ((n_type_instance == NULL) || (n_type_instance[0] == '\0'))
         {
             if ((ds_name == NULL) || (ds_name[0] == '\0'))
-                status = ssnprintf (ret, ret_len, "%s.%s%s.%s.%s.%s",
+                status = ssnprintf (ret, ret_len, "%s%s%s.%s.%s.%s",
                         prefix, n_hostname, postfix, plugin,
                         plugin_instance, type);
             else
-                status = ssnprintf (ret, ret_len, "%s.%s%s.%s.%s.%s.%s",
+                status = ssnprintf (ret, ret_len, "%s%s%s.%s.%s.%s.%s",
                         prefix, n_hostname, postfix, plugin,
                         plugin_instance, type, ds_name);
         }
         else
         {
             if ((ds_name == NULL) || (ds_name[0] == '\0'))
-                status = ssnprintf (ret, ret_len, "%s.%s%s.%s.%s.%s-%s",
+                status = ssnprintf (ret, ret_len, "%s%s%s.%s.%s.%s-%s",
                         prefix, n_hostname, postfix, plugin,
                         plugin_instance, type, n_type_instance);
             else
-                status = ssnprintf (ret, ret_len, "%s.%s%s.%s.%s.%s-%s.%s",
+                status = ssnprintf (ret, ret_len, "%s%s%s.%s.%s.%s-%s.%s",
                         prefix, n_hostname, postfix, plugin,
                         plugin_instance, type, n_type_instance, ds_name);
         }
@@ -692,10 +692,19 @@ static int wg_config_carbon (oconfig_item_t *ci)
         }
     }
 
+    if (cb->prefix == NULL) {
+        if ((cb->prefix = malloc((int)sizeof(char))) == NULL)
+        {
+            ERROR ("Unable to allocate memory for hostname prefix buffer");
+            return (-1);
+        }
+        cb->postfix[0] = '\0';
+    }
+
     if (cb->postfix == NULL) {
         if ((cb->postfix = malloc((int)sizeof(char))) == NULL)
         {
-            ERROR ("Unable to allocate memory for normalized hostname buffer");
+            ERROR ("Unable to allocate memory for hostname postfix buffer");
             return (-1);
         }
         cb->postfix[0] = '\0';