From 0e17632bc45a2d979d271b959a6ac05f11cca351 Mon Sep 17 00:00:00 2001 From: Noah Hilverling Date: Wed, 4 Apr 2018 13:02:48 +0200 Subject: [PATCH] Fix InfluxDB backslash escaping fixes #6182 --- lib/perfdata/influxdbwriter.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/perfdata/influxdbwriter.cpp b/lib/perfdata/influxdbwriter.cpp index 04153c3e8..8a3fe97b1 100644 --- a/lib/perfdata/influxdbwriter.cpp +++ b/lib/perfdata/influxdbwriter.cpp @@ -305,6 +305,17 @@ String InfluxdbWriter::EscapeKeyOrTagValue(const String& str) boost::algorithm::replace_all(result, "=", "\\="); boost::algorithm::replace_all(result, ",", "\\,"); boost::algorithm::replace_all(result, " ", "\\ "); + + // InfluxDB 'feature': although backslashes are allowed in keys they also act + // as escape sequences when followed by ',' or ' '. When your tag is like + // 'metric=C:\' bad things happen. Backslashes themselves cannot be escaped + // and through experimentation they also escape '='. To be safe we replace + // trailing backslashes with and underscore. + // See https://github.com/influxdata/influxdb/issues/8587 for more info + size_t length = result.GetLength(); + if (result[length - 1] == '\\') + result[length - 1] = '_'; + return result; } -- 2.40.0