Module: check_mk
Branch: master
Commit: 2af9ea5eca961831084847c5cc937d0318d04f65
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=2af9ea5eca9618…
Author: Sven Panne <sp(a)mathias-kettner.de>
Date: Tue Nov 21 10:32:08 2017 +0100
5462 FIX Fixed aggregation of performance data
Aggregating performance data via Stats: headers only handled a very
restricted form of values, e.g. negative values were simply ignored, as
were numbers in exponential notation. This has been fixed.
Change-Id: I0c91fef2b9d84b4b51f73d79e6a0393fdb8472d9
---
.werks/5462 | 12 ++++++++++
livestatus/src/PerfdataAggregator.cc | 43 +++++++++++-------------------------
2 files changed, 25 insertions(+), 30 deletions(-)
diff --git a/.werks/5462 b/.werks/5462
new file mode 100644
index 0000000..fc67203
--- /dev/null
+++ b/.werks/5462
@@ -0,0 +1,12 @@
+Title: Fixed aggregation of performance data
+Level: 1
+Component: livestatus
+Compatible: compat
+Edition: cre
+Version: 1.5.0i2
+Date: 1511256586
+Class: fix
+
+Aggregating performance data via Stats: headers only handled a very
+restricted form of values, e.g. negative values were simply ignored, as
+were numbers in exponential notation. This has been fixed.
diff --git a/livestatus/src/PerfdataAggregator.cc b/livestatus/src/PerfdataAggregator.cc
index ae562c7..3653477 100644
--- a/livestatus/src/PerfdataAggregator.cc
+++ b/livestatus/src/PerfdataAggregator.cc
@@ -23,46 +23,29 @@
// Boston, MA 02110-1301 USA.
#include "PerfdataAggregator.h"
-#include <cctype>
#include <cmath>
-#include <cstdlib>
+#include <iterator>
+#include <sstream>
+#include <stdexcept>
#include <utility>
-#include <vector>
#include "Renderer.h"
#include "Row.h"
#include "StringColumn.h"
#include "contact_fwd.h"
-#include "strutil.h"
void PerfdataAggregator::consume(Row row, const contact * /* auth_user */,
std::chrono::seconds /* timezone_offset */) {
- std::string perf_data = _column->getValue(row);
- std::vector<char> perf_data_vec(perf_data.begin(), perf_data.end());
- perf_data_vec.push_back('\0');
- char *scan = &perf_data_vec[0];
-
- while (char *entry = next_field(&scan)) {
- char *start_of_varname = entry;
- char *place_of_equal = entry;
- while ((*place_of_equal != 0) && *place_of_equal != '=') {
- place_of_equal++;
+ std::istringstream iss(_column->getValue(row));
+ std::istream_iterator<std::string> end;
+ for (auto it = std::istream_iterator<std::string>(iss); it != end; ++it) {
+ auto pos = it->find('=');
+ if (pos != std::string::npos) {
+ try {
+ consumeVariable(it->substr(0, pos),
+ std::stod(it->substr(pos + 1)));
+ } catch (const std::logic_error &e) {
+ }
}
- if (*place_of_equal == 0) {
- continue; // ignore invalid perfdata
- }
- *place_of_equal = 0; // terminate varname
- char *start_of_number = place_of_equal + 1;
- char *end_of_number = start_of_number;
- while ((*end_of_number != 0) &&
- ((isdigit(*end_of_number) != 0) || *end_of_number == '.')) {
- end_of_number++;
- }
- if (start_of_number == end_of_number) {
- continue; // empty number
- }
- *end_of_number = 0; // terminate number
- double value = strtod(start_of_number, nullptr);
- consumeVariable(start_of_varname, value);
}
}