Module: check_mk
Branch: master
Commit: 715b35bc6ce090b1cc38d41b966dfc1737b4bb32
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=715b35bc6ce090…
Author: Sven Panne <sp(a)mathias-kettner.de>
Date: Fri Nov 3 12:05:35 2017 +0100
Moved bit fiddling to the right class.
Change-Id: I934d2530072f20819ff603fa096ce1b53d47f186
---
livestatus/src/AttributeListAsIntColumn.cc | 66 +++++++++++++++++++++++++++---
livestatus/src/AttributeListAsIntColumn.h | 6 ++-
livestatus/src/AttributeListColumn.cc | 62 ++--------------------------
livestatus/src/AttributeListColumn.h | 3 --
4 files changed, 69 insertions(+), 68 deletions(-)
diff --git a/livestatus/src/AttributeListAsIntColumn.cc
b/livestatus/src/AttributeListAsIntColumn.cc
index 2c87b42..583d346 100644
--- a/livestatus/src/AttributeListAsIntColumn.cc
+++ b/livestatus/src/AttributeListAsIntColumn.cc
@@ -23,22 +23,78 @@
// Boston, MA 02110-1301 USA.
#include "AttributeListAsIntColumn.h"
+#include <bitset>
+#include <cctype>
+#include <map>
#include <memory>
-#include "AttributeListColumn.h"
+#include <ostream>
+#include <utility>
#include "Filter.h"
#include "IntFilter.h"
+#include "Logger.h"
#include "Row.h"
+#include "strutil.h"
+
+namespace {
+// see MODATTR_FOO in nagios/common.h
+std::map<std::string, unsigned long> known_attributes = {
+ {"notifications_enabled", 0}, {"active_checks_enabled", 1},
+ {"passive_checks_enabled", 2}, {"event_handler_enabled", 3},
+ {"flap_detection_enabled", 4}, {"failure_prediction_enabled",
5},
+ {"performance_data_enabled", 6}, {"obsessive_handler_enabled",
7},
+ {"event_handler_command", 8}, {"check_command", 9},
+ {"normal_check_interval", 10}, {"retry_check_interval", 11},
+ {"max_check_attempts", 12}, {"freshness_checks_enabled",
13},
+ {"check_timeperiod", 14}, {"custom_variable", 15},
+ {"notification_timeperiod", 16}};
+
+using modified_atttibutes = std::bitset<32>;
+
+std::string refValueFor(const std::string &value, Logger *logger) {
+ if (isdigit(value[0]) != 0) {
+ return value;
+ }
+
+ std::vector<char> value_vec(value.begin(), value.end());
+ value_vec.push_back('\0');
+ char *scan = &value_vec[0];
+
+ modified_atttibutes values;
+ for (const char *t; (t = next_token(&scan, ',')) != nullptr;) {
+ auto it = known_attributes.find(t);
+ if (it == known_attributes.end()) {
+ Informational(logger)
+ << "Ignoring invalid value '" << t <<
"' for attribute list";
+ continue;
+ }
+ values[it->second] = true;
+ }
+ return std::to_string(values.to_ulong());
+}
+} // namespace
std::unique_ptr<Filter> AttributeListAsIntColumn::createFilter(
RelationalOperator relOp, const std::string &value) const {
- return std::make_unique<IntFilter>(
- *this, relOp, AttributeListColumn::refValueFor(value, logger()));
+ return std::make_unique<IntFilter>(*this, relOp,
+ refValueFor(value, logger()));
}
-int32_t AttributeListAsIntColumn::getValue(Row row,
- const contact * /*unused*/) const {
+int32_t AttributeListAsIntColumn::getValue(
+ Row row, const contact * /*auth_user*/) const {
if (auto p = columnData<unsigned long>(row)) {
return static_cast<int32_t>(*p);
}
return 0;
}
+
+std::vector<std::string> AttributeListAsIntColumn::getAttributes(
+ Row row, const contact *auth_user) const {
+ modified_atttibutes values(getValue(row, auth_user));
+ std::vector<std::string> attributes;
+ for (const auto &entry : known_attributes) {
+ if (values[entry.second]) {
+ attributes.push_back(entry.first);
+ }
+ }
+ return attributes;
+}
diff --git a/livestatus/src/AttributeListAsIntColumn.h
b/livestatus/src/AttributeListAsIntColumn.h
index 7c43835..80be7ba 100644
--- a/livestatus/src/AttributeListAsIntColumn.h
+++ b/livestatus/src/AttributeListAsIntColumn.h
@@ -29,6 +29,7 @@
#include <cstdint>
#include <memory>
#include <string>
+#include <vector>
#include "IntColumn.h"
#include "contact_fwd.h"
#include "opids.h"
@@ -44,12 +45,13 @@ public:
: IntColumn(name, description, indirect_offset, extra_offset,
extra_extra_offset, offset) {}
- /// API of Column
std::unique_ptr<Filter> createFilter(RelationalOperator,
const std::string &) const override;
- // API of IntColumn
int32_t getValue(Row row, const contact *auth_user) const override;
+
+ std::vector<std::string> getAttributes(Row row,
+ const contact *auth_user) const;
};
#endif // AttributeListAsIntColumn_h
diff --git a/livestatus/src/AttributeListColumn.cc
b/livestatus/src/AttributeListColumn.cc
index 30494a9..60c0d7d 100644
--- a/livestatus/src/AttributeListColumn.cc
+++ b/livestatus/src/AttributeListColumn.cc
@@ -23,72 +23,18 @@
// Boston, MA 02110-1301 USA.
#include "AttributeListColumn.h"
-#include <bitset>
-#include <cctype>
-#include <map>
#include <memory>
-#include <ostream>
-#include <utility>
#include <vector>
#include "Filter.h"
-#include "Logger.h"
#include "Row.h"
-#include "strutil.h"
-
-namespace {
-// see MODATTR_FOO in nagios/common.h
-std::map<std::string, unsigned long> known_attributes = {
- {"notifications_enabled", 0}, {"active_checks_enabled", 1},
- {"passive_checks_enabled", 2}, {"event_handler_enabled", 3},
- {"flap_detection_enabled", 4}, {"failure_prediction_enabled",
5},
- {"performance_data_enabled", 6}, {"obsessive_handler_enabled",
7},
- {"event_handler_command", 8}, {"check_command", 9},
- {"normal_check_interval", 10}, {"retry_check_interval", 11},
- {"max_check_attempts", 12}, {"freshness_checks_enabled",
13},
- {"check_timeperiod", 14}, {"custom_variable", 15},
- {"notification_timeperiod", 16}};
-
-using modified_atttibutes = std::bitset<32>;
-} // namespace
-
-std::vector<std::string> AttributeListColumn::getValue(
- Row row, const contact *auth_user,
- std::chrono::seconds /*timezone_offset*/) const {
- modified_atttibutes values(_int_view_column.getValue(row, auth_user));
- std::vector<std::string> attributes;
- for (const auto &entry : known_attributes) {
- if (values[entry.second]) {
- attributes.push_back(entry.first);
- }
- }
- return attributes;
-}
std::unique_ptr<Filter> AttributeListColumn::createFilter(
RelationalOperator relOp, const std::string &value) const {
return _int_view_column.createFilter(relOp, value);
}
-// static
-std::string AttributeListColumn::refValueFor(const std::string &value,
- Logger *logger) {
- if (isdigit(value[0]) != 0) {
- return value;
- }
-
- std::vector<char> value_vec(value.begin(), value.end());
- value_vec.push_back('\0');
- char *scan = &value_vec[0];
-
- modified_atttibutes values;
- for (const char *t; (t = next_token(&scan, ',')) != nullptr;) {
- auto it = known_attributes.find(t);
- if (it == known_attributes.end()) {
- Informational(logger)
- << "Ignoring invalid value '" << t <<
"' for attribute list";
- continue;
- }
- values[it->second] = true;
- }
- return std::to_string(values.to_ulong());
+std::vector<std::string> AttributeListColumn::getValue(
+ Row row, const contact *auth_user,
+ std::chrono::seconds /*timezone_offset*/) const {
+ return _int_view_column.getAttributes(row, auth_user);
}
diff --git a/livestatus/src/AttributeListColumn.h b/livestatus/src/AttributeListColumn.h
index 984900b..1ad2855 100644
--- a/livestatus/src/AttributeListColumn.h
+++ b/livestatus/src/AttributeListColumn.h
@@ -35,7 +35,6 @@
#include "contact_fwd.h"
#include "opids.h"
class Filter;
-class Logger;
class Row;
class AttributeListColumn : public ListColumn {
@@ -55,8 +54,6 @@ public:
Row row, const contact *auth_user,
std::chrono::seconds timezone_offset) const override;
- static std::string refValueFor(const std::string &value, Logger *logger);
-
private:
AttributeListAsIntColumn _int_view_column;
};