Fix: Missing warn/crit/min/max values are incorrectly set to 0.

Fixes #5358
This commit is contained in:
Gunnar Beutner 2013-12-17 14:47:19 +01:00
parent b2ec194a82
commit 9bf44b9b1d
2 changed files with 37 additions and 4 deletions

View File

@ -65,7 +65,7 @@ Value PerfdataValue::Parse(const String& perfdata)
double base = 1.0; double base = 1.0;
if (unit == "us") { if (unit == "us") {
base /= (1000.0 * 1000.0); base /= 1000.0 * 1000.0;
unit = "seconds"; unit = "seconds";
} else if (unit == "ms") { } else if (unit == "ms") {
base /= 1000.0; base /= 1000.0;
@ -107,13 +107,19 @@ Value PerfdataValue::Parse(const String& perfdata)
if (tokens.size() > 4 && tokens[4] != "U" && tokens[4] != "") if (tokens.size() > 4 && tokens[4] != "U" && tokens[4] != "")
max = Convert::ToDouble(tokens[4]); max = Convert::ToDouble(tokens[4]);
if (base != 1.0) {
value = value * base; value = value * base;
if (!warn.IsEmpty())
warn = warn * base; warn = warn * base;
if (!crit.IsEmpty())
crit = crit * base; crit = crit * base;
if (!min.IsEmpty())
min = min * base; min = min * base;
if (!max.IsEmpty())
max = max * base; max = max * base;
}
return make_shared<PerfdataValue>(value, counter, unit, warn, crit, min, max); return make_shared<PerfdataValue>(value, counter, unit, warn, crit, min, max);
} }

View File

@ -72,6 +72,33 @@ BOOST_AUTO_TEST_CASE(uom)
String str = PluginUtility::FormatPerfdata(pd); String str = PluginUtility::FormatPerfdata(pd);
BOOST_CHECK(str == "test=123456B"); BOOST_CHECK(str == "test=123456B");
pd = PluginUtility::ParsePerfdata("test=1000ms;200;500");
BOOST_CHECK(pd);
pv = pd->Get("test");
BOOST_CHECK(pv);
BOOST_CHECK(pv->GetValue() == 1);
BOOST_CHECK(pv->GetUnit() == "seconds");
BOOST_CHECK(pv->GetWarn() == 0.2);
BOOST_CHECK(pv->GetCrit() == 0.5);
pd = PluginUtility::ParsePerfdata("test=1000ms");
BOOST_CHECK(pd);
pv = pd->Get("test");
BOOST_CHECK(pv);
BOOST_CHECK(pv->GetValue() == 1);
BOOST_CHECK(pv->GetUnit() == "seconds");
BOOST_CHECK(pv->GetCrit() == Empty);
BOOST_CHECK(pv->GetWarn() == Empty);
BOOST_CHECK(pv->GetMin() == Empty);
BOOST_CHECK(pv->GetMax() == Empty);
str = PluginUtility::FormatPerfdata(pd);
BOOST_CHECK(str == "test=1s");
} }
BOOST_AUTO_TEST_CASE(warncritminmax) BOOST_AUTO_TEST_CASE(warncritminmax)