MCPcopy Create free account
hub / github.com/Icinga/icinga2 / EscapeKeyOrTagValue

Method EscapeKeyOrTagValue

lib/perfdata/influxdbcommonwriter.cpp:314–334  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

312}
313
314String InfluxdbCommonWriter::EscapeKeyOrTagValue(const String& str)
315{
316 // Iterate over the key name and escape commas and spaces with a backslash
317 String result = str;
318 boost::algorithm::replace_all(result, "\"", "\\\"");
319 boost::algorithm::replace_all(result, "=", "\\=");
320 boost::algorithm::replace_all(result, ",", "\\,");
321 boost::algorithm::replace_all(result, " ", "\\ ");
322
323 // InfluxDB 'feature': although backslashes are allowed in keys they also act
324 // as escape sequences when followed by ',' or ' '. When your tag is like
325 // 'metric=C:\' bad things happen. Backslashes themselves cannot be escaped
326 // and through experimentation they also escape '='. To be safe we replace
327 // trailing backslashes with and underscore.
328 // See https://github.com/influxdata/influxdb/issues/8587 for more info
329 size_t length = result.GetLength();
330 if (result[length - 1] == '\\')
331 result[length - 1] = '_';
332
333 return result;
334}
335
336String InfluxdbCommonWriter::EscapeValue(const Value& value)
337{

Callers

nothing calls this directly

Calls 1

GetLengthMethod · 0.45

Tested by

no test coverage detected