summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: f2106c1)
raw | patch | inline | side by side (parent: f2106c1)
author | Pierre-Yves Ritschard <pyr@spootnik.org> | |
Fri, 24 Jan 2014 15:49:22 +0000 (16:49 +0100) | ||
committer | Pierre-Yves Ritschard <pyr@spootnik.org> | |
Fri, 24 Jan 2014 15:49:22 +0000 (16:49 +0100) |
Sanitize graphite metrics with our own escaping function,
better suited for this use-case than the one in `utils_parse_option`
better suited for this use-case than the one in `utils_parse_option`
src/utils_format_graphite.c | patch | blob | history |
index 83512015898e22b27c527b431aa03bdcda5f2865..c9516b49386ae7d8c99cb8b62fad405de5b7a5ba 100644 (file)
#include "utils_cache.h"
#include "utils_parse_option.h"
+#define GRAPHITE_FORBIDDEN " \t\"\\:!/\n\r"
+
/* Utils functions to format data sets in graphite format.
* Largely taken from write_graphite.c as it remains the same formatting */
return (0);
}
+static void escape_graphite_string (char *buffer, char escape_char)
+{
+ char *head;
+
+ assert (strchr(GRAPHITE_FORBIDDEN, escape_char) == NULL);
+
+ for (head = buffer + strcspn(buffer, GRAPHITE_FORBIDDEN);
+ *head != '\0';
+ head += strcspn(head, GRAPHITE_FORBIDDEN))
+ *head = escape_char;
+}
+
int format_graphite (char *buffer, size_t buffer_size,
data_set_t const *ds, value_list_t const *vl,
char const *prefix, char const *postfix, char const escape_char,
return (status);
}
- escape_string (key, sizeof (key));
+ escape_graphite_string (key, escape_char);
/* Convert the values to an ASCII representation and put that into
* `values'. */
status = gr_format_values (values, sizeof (values), i, ds, vl, rates);