From ff0b45eca00ea5b320145ac1f458c4cd72946634 Mon Sep 17 00:00:00 2001 From: Yonas Habteab Date: Tue, 10 Aug 2021 16:42:12 +0200 Subject: [PATCH 1/2] PluginUtility: Fix PerfData don't get parsed correctly The problem was that some PerfData labels contained several whitespace characters, not just one, and therefore it was parsed incorrectly in `SplitPerfdata()`. I.e. the condition in line 144 checks whether the first and last character is a normal quote, but since the label can contain spaces at the beginning and at the end respectively, this caused the problems. This PR fixes the problem by removing all occurring whitespace from the beginning and end, before starting to parse the actual label. --- lib/icinga/pluginutility.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/icinga/pluginutility.cpp b/lib/icinga/pluginutility.cpp index 2197d1693..4dc46f754 100644 --- a/lib/icinga/pluginutility.cpp +++ b/lib/icinga/pluginutility.cpp @@ -140,6 +140,7 @@ Array::Ptr PluginUtility::SplitPerfdata(const String& perfdata) break; String label = perfdata.SubStr(begin, eqp - begin); + boost::algorithm::trim_left(label); if (label.GetLength() > 2 && label[0] == '\'' && label[label.GetLength() - 1] == '\'') label = label.SubStr(1, label.GetLength() - 2); From b6ba09e47936ea0b68cb08a271f402c1540da1ff Mon Sep 17 00:00:00 2001 From: Yonas Habteab Date: Fri, 13 Aug 2021 10:18:08 +0200 Subject: [PATCH 2/2] Test: Add multiline PerfData test case --- test/CMakeLists.txt | 1 + test/icinga-perfdata.cpp | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 8b800d914..8919de304 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -147,6 +147,7 @@ add_boost_test(base icinga_perfdata/simple icinga_perfdata/quotes icinga_perfdata/multiple + icinga_perfdata/multiline icinga_perfdata/normalize icinga_perfdata/uom icinga_perfdata/warncritminmax diff --git a/test/icinga-perfdata.cpp b/test/icinga-perfdata.cpp index f763ac043..12e1c28f8 100644 --- a/test/icinga-perfdata.cpp +++ b/test/icinga-perfdata.cpp @@ -43,6 +43,21 @@ BOOST_AUTO_TEST_CASE(multiple) BOOST_CHECK(str == "testA=123456 testB=123456"); } +BOOST_AUTO_TEST_CASE(multiline) +{ + Array::Ptr pd = PluginUtility::SplitPerfdata(" 'testA'=123456 'testB'=123456"); + BOOST_CHECK(pd->GetLength() == 2); + + String str = PluginUtility::FormatPerfdata(pd); + BOOST_CHECK(str == "testA=123456 testB=123456"); + + pd = PluginUtility::SplitPerfdata(" 'testA'=123456 \n'testB'=123456"); + BOOST_CHECK(pd->GetLength() == 2); + + str = PluginUtility::FormatPerfdata(pd); + BOOST_CHECK(str == "testA=123456 testB=123456"); +} + BOOST_AUTO_TEST_CASE(normalize) { Array::Ptr pd = PluginUtility::SplitPerfdata("testA=2m;3;4;1;5 testB=2foobar");