mirror of https://github.com/Icinga/icinga2.git
Merge pull request #8492 from Icinga/bugfix/perfdata-scientific-notation
Fix perfdata parser not recognize scientific notation
This commit is contained in:
commit
62cbe72cdb
|
@ -244,7 +244,7 @@ PerfdataValue::Ptr PerfdataValue::Parse(const String& perfdata)
|
|||
|
||||
String valueStr = perfdata.SubStr(eqp + 1, spq - eqp - 1);
|
||||
|
||||
size_t pos = valueStr.FindFirstNotOf("+-0123456789.e");
|
||||
size_t pos = valueStr.FindFirstNotOf("+-0123456789.eE");
|
||||
|
||||
if (pos != String::NPos && valueStr[pos] == ',') {
|
||||
BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid performance data value: " + perfdata));
|
||||
|
@ -379,7 +379,7 @@ String PerfdataValue::Format() const
|
|||
|
||||
Value PerfdataValue::ParseWarnCritMinMaxToken(const std::vector<String>& tokens, std::vector<String>::size_type index, const String& description)
|
||||
{
|
||||
if (tokens.size() > index && tokens[index] != "U" && tokens[index] != "" && tokens[index].FindFirstNotOf("+-0123456789.e") == String::NPos)
|
||||
if (tokens.size() > index && tokens[index] != "U" && tokens[index] != "" && tokens[index].FindFirstNotOf("+-0123456789.eE") == String::NPos)
|
||||
return Convert::ToDouble(tokens[index]);
|
||||
else {
|
||||
if (tokens.size() > index && tokens[index] != "")
|
||||
|
|
|
@ -146,6 +146,7 @@ add_boost_test(base
|
|||
icinga_perfdata/ignore_invalid_warn_crit_min_max
|
||||
icinga_perfdata/invalid
|
||||
icinga_perfdata/multi
|
||||
icinga_perfdata/scientificnotation
|
||||
remote_url/id_and_path
|
||||
remote_url/parameters
|
||||
remote_url/get_and_set
|
||||
|
|
|
@ -305,4 +305,53 @@ BOOST_AUTO_TEST_CASE(multi)
|
|||
BOOST_CHECK(pd->Get(1) == "test::b=4");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(scientificnotation)
|
||||
{
|
||||
PerfdataValue::Ptr pdv = PerfdataValue::Parse("test=1.1e+1");
|
||||
BOOST_CHECK(pdv->GetLabel() == "test");
|
||||
BOOST_CHECK(pdv->GetValue() == 11);
|
||||
|
||||
String str = pdv->Format();
|
||||
BOOST_CHECK(str == "test=11");
|
||||
|
||||
pdv = PerfdataValue::Parse("test=1.1e1");
|
||||
BOOST_CHECK(pdv->GetLabel() == "test");
|
||||
BOOST_CHECK(pdv->GetValue() == 11);
|
||||
|
||||
str = pdv->Format();
|
||||
BOOST_CHECK(str == "test=11");
|
||||
|
||||
pdv = PerfdataValue::Parse("test=1.1e-1");
|
||||
BOOST_CHECK(pdv->GetLabel() == "test");
|
||||
BOOST_CHECK(pdv->GetValue() == 0.11);
|
||||
|
||||
str = pdv->Format();
|
||||
BOOST_CHECK(str == "test=0.110000");
|
||||
|
||||
pdv = PerfdataValue::Parse("test=1.1E1");
|
||||
BOOST_CHECK(pdv->GetLabel() == "test");
|
||||
BOOST_CHECK(pdv->GetValue() == 11);
|
||||
|
||||
str = pdv->Format();
|
||||
BOOST_CHECK(str == "test=11");
|
||||
|
||||
pdv = PerfdataValue::Parse("test=1.1E-1");
|
||||
BOOST_CHECK(pdv->GetLabel() == "test");
|
||||
BOOST_CHECK(pdv->GetValue() == 0.11);
|
||||
|
||||
str = pdv->Format();
|
||||
BOOST_CHECK(str == "test=0.110000");
|
||||
|
||||
pdv = PerfdataValue::Parse("test=1.1E-1;1.2e+1;1.3E-1;1.4e-2;1.5E2");
|
||||
BOOST_CHECK(pdv->GetLabel() == "test");
|
||||
BOOST_CHECK(pdv->GetValue() == 0.11);
|
||||
BOOST_CHECK(pdv->GetWarn() == 12);
|
||||
BOOST_CHECK(pdv->GetCrit() == 0.13);
|
||||
BOOST_CHECK(pdv->GetMin() == 0.014);
|
||||
BOOST_CHECK(pdv->GetMax() == 150);
|
||||
|
||||
str = pdv->Format();
|
||||
BOOST_CHECK(str == "test=0.110000;12;0.130000;0.014000;150");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
|
Loading…
Reference in New Issue