From a840dc86943e585199dda9e6d6bed9f1c72333f4 Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Mon, 16 Dec 2013 16:36:54 +0100 Subject: [PATCH] Apply UOM base to warn/crit/min/max to perfdata values. Fixes #5280 --- lib/icinga/perfdatavalue.cpp | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/lib/icinga/perfdatavalue.cpp b/lib/icinga/perfdatavalue.cpp index d9a7a6a67..4f090d494 100644 --- a/lib/icinga/perfdatavalue.cpp +++ b/lib/icinga/perfdatavalue.cpp @@ -62,25 +62,27 @@ Value PerfdataValue::Parse(const String& perfdata) boost::algorithm::to_lower(unit); + double base = 1.0; + if (unit == "us") { - value /= 1000.0 * 1000.0; + base /= (1000.0 * 1000.0); unit = "seconds"; } else if (unit == "ms") { - value /= 1000.0; + base /= 1000.0; unit = "seconds"; } else if (unit == "s") { unit = "seconds"; } else if (unit == "tb") { - value *= 1024.0 * 1024.0 * 1024.0 * 1024.0; + base *= 1024.0 * 1024.0 * 1024.0 * 1024.0; unit = "bytes"; } else if (unit == "gb") { - value *= 1024.0 * 1024.0 * 1024.0; + base *= 1024.0 * 1024.0 * 1024.0; unit = "bytes"; } else if (unit == "mb") { - value *= 1024.0 * 1024.0; + base *= 1024.0 * 1024.0; unit = "bytes"; } else if (unit == "kb") { - value *= 1024.0; + base *= 1024.0; unit = "bytes"; } else if (unit == "b") { unit = "bytes"; @@ -105,6 +107,14 @@ Value PerfdataValue::Parse(const String& perfdata) if (tokens.size() > 4 && tokens[4] != "U" && tokens[4] != "") max = Convert::ToDouble(tokens[4]); + if (base != 1.0) { + value = value * base; + warn = warn * base; + crit = crit * base; + min = min * base; + max = max * base; + } + return make_shared(value, counter, unit, warn, crit, min, max); } -- 2.40.0