]> granicus.if.org Git - icinga2/commitdiff
Fix InfluxDB backslash escaping
authorNoah Hilverling <noah.hilverling@icinga.com>
Wed, 4 Apr 2018 11:02:48 +0000 (13:02 +0200)
committerMichael Friedrich <michael.friedrich@icinga.com>
Mon, 16 Apr 2018 13:46:47 +0000 (15:46 +0200)
fixes #6182

refs #6196

lib/perfdata/influxdbwriter.cpp

index ac149e7cba0611acd7480a22bd5f3ccd8fdfab1e..08f27cfb1c0ddb67dbbd36ab422adf63a12fe1b8 100644 (file)
@@ -308,6 +308,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;
 }