Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PluginUtility: Fix PerfData parsing for values separated with multiple spaces #8969

Merged
merged 2 commits into from May 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/icinga/pluginutility.cpp
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions test/icinga-perfdata.cpp
Expand Up @@ -43,6 +43,21 @@ BOOST_AUTO_TEST_CASE(multiple)
BOOST_CHECK(str == "testA=123456 testB=123456");
}

BOOST_AUTO_TEST_CASE(multiline)
yhabteab marked this conversation as resolved.
Show resolved Hide resolved
{
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");
Expand Down