Merge pull request #10432 from Icinga/perfdata-parse-counter-value

Fix PerfdataValue Counter Parsing
This commit is contained in:
Yonas Habteab 2025-05-12 18:42:59 +02:00 committed by GitHub
commit 79e5462072
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 4 deletions

View File

@ -270,6 +270,11 @@ PerfdataValue::Ptr PerfdataValue::Parse(const String& perfdata)
if (pos != String::NPos)
unit = tokens[0].SubStr(pos, String::NPos);
// UoM.Out is an empty string for "c". So set counter before parsing.
if (unit == "c") {
counter = true;
}
double base;
{
@ -295,10 +300,6 @@ PerfdataValue::Ptr PerfdataValue::Parse(const String& perfdata)
}
}
if (unit == "c") {
counter = true;
}
warn = ParseWarnCritMinMaxToken(tokens, 1, "warning");
crit = ParseWarnCritMinMaxToken(tokens, 2, "critical");
min = ParseWarnCritMinMaxToken(tokens, 3, "minimum");

View File

@ -285,6 +285,19 @@ BOOST_AUTO_TEST_CASE(uom)
str = pv->Format();
BOOST_CHECK_EQUAL(str, "test=1W");
pv = PerfdataValue::Parse("test=42c");
BOOST_CHECK(pv);
BOOST_CHECK_EQUAL(pv->GetValue(), 42);
BOOST_CHECK(pv->GetCounter());
BOOST_CHECK_EQUAL(pv->GetUnit(), "");
BOOST_CHECK_EQUAL(pv->GetCrit(), Empty);
BOOST_CHECK_EQUAL(pv->GetWarn(), Empty);
BOOST_CHECK_EQUAL(pv->GetMin(), Empty);
BOOST_CHECK_EQUAL(pv->GetMax(), Empty);
str = pv->Format();
BOOST_CHECK_EQUAL(str, "test=42c");
}
BOOST_AUTO_TEST_CASE(warncritminmax)