[checkmk-commits] Fetched livestatus from downstream.

Sven Panne sp at mathias-kettner.de
Wed Dec 21 14:50:32 CET 2016


Module: check_mk
Branch: master
Commit: ddd0042c27e29cc83b1e8fd0b0280a38d4b5018f
URL:    http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=ddd0042c27e29cc83b1e8fd0b0280a38d4b5018f

Author: Sven Panne <sp at mathias-kettner.de>
Date:   Wed Dec 21 14:50:19 2016 +0100

Fetched livestatus from downstream.

Change-Id: I82068bb9716889cf592458974cefc48f6f8dee6d

---

 livestatus/src/ServiceListColumn.cc  |  3 ++-
 livestatus/src/ServiceListColumn.h   | 14 ++++++++------
 livestatus/src/ServiceListFilter.cc  | 37 ++++++++++++++++++++----------------
 livestatus/src/ServiceListFilter.h   |  5 +++--
 livestatus/src/TableHosts.cc         | 14 +++++++-------
 livestatus/src/TableServiceGroups.cc |  8 ++++----
 6 files changed, 45 insertions(+), 36 deletions(-)

diff --git a/livestatus/src/ServiceListColumn.cc b/livestatus/src/ServiceListColumn.cc
index 5877544..50876e4 100644
--- a/livestatus/src/ServiceListColumn.cc
+++ b/livestatus/src/ServiceListColumn.cc
@@ -86,7 +86,8 @@ void ServiceListColumn::output(void *row, RowRenderer &r, contact *auth_user) {
 
 unique_ptr<Filter> ServiceListColumn::createFilter(RelationalOperator relOp,
                                                    const string &value) {
-    return make_unique<ServiceListFilter>(this, relOp, value);
+    return make_unique<ServiceListFilter>(this, _hostname_required, relOp,
+                                          value);
 }
 
 int ServiceListColumn::inCustomTimeperiod(service *svc, const char *varname) {
diff --git a/livestatus/src/ServiceListColumn.h b/livestatus/src/ServiceListColumn.h
index 5aaaee3..5398281 100644
--- a/livestatus/src/ServiceListColumn.h
+++ b/livestatus/src/ServiceListColumn.h
@@ -35,15 +35,12 @@ class Filter;
 class RowRenderer;
 
 class ServiceListColumn : public Column {
-    int _offset;
-    bool _show_host;
-    int _info_depth;
-
 public:
     ServiceListColumn(const std::string &name, const std::string &description,
-                      int offset, int indirect_offset, bool show_host,
-                      int info_depth, int extra_offset = -1)
+                      bool hostname_required, int offset, int indirect_offset,
+                      bool show_host, int info_depth, int extra_offset)
         : Column(name, description, indirect_offset, extra_offset)
+        , _hostname_required(hostname_required)
         , _offset(offset)
         , _show_host(show_host)
         , _info_depth(info_depth) {}
@@ -54,6 +51,11 @@ public:
     servicesmember *getMembers(void *data);
 
 private:
+    bool _hostname_required;
+    int _offset;
+    bool _show_host;
+    int _info_depth;
+
     int inCustomTimeperiod(service *svc, const char *varname);
 };
 
diff --git a/livestatus/src/ServiceListFilter.cc b/livestatus/src/ServiceListFilter.cc
index 6d37865..0de7775 100644
--- a/livestatus/src/ServiceListFilter.cc
+++ b/livestatus/src/ServiceListFilter.cc
@@ -24,37 +24,41 @@
 
 // IWYU pragma: no_include <ext/alloc_traits.h>
 #include "ServiceListFilter.h"
-#include <cstring>
 #include <ostream>
 #include "Logger.h"
 
 using std::string;
 
-#define HOSTSERVICE_SEPARATOR '|'
+namespace {
+constexpr char hostservice_separator = '|';
+}  // namespace
 
 ServiceListFilter::ServiceListFilter(ServiceListColumn *column,
+                                     bool hostname_required,
                                      RelationalOperator relOp,
                                      const string &value)
-    : _column(column), _relOp(relOp) {
+    : _column(column), _hostname_required(hostname_required), _relOp(relOp) {
     if ((_relOp == RelationalOperator::equal ||
          _relOp == RelationalOperator::not_equal) &&
         value.empty()) {
         return;  // test for emptiness is allowed
     }
 
-    // ref_value must be of from hostname HOSTSERVICE_SEPARATOR
-    // service_description
-    const char *sep = index(value.c_str(), HOSTSERVICE_SEPARATOR);
-    if (sep == nullptr) {
-        Informational(logger()) << "Invalid reference value for service list "
-                                   "membership. Must be 'hostname"
-                                << string(1, HOSTSERVICE_SEPARATOR)
-                                << "servicename'";
-        _ref_host = "";
-        _ref_service = "";
+    // ref_value must be of the form
+    //    hostname hostservice_separator service_description
+    auto pos = value.find(hostservice_separator);
+    if (pos == string::npos) {
+        if (_hostname_required) {
+            Informational(logger()) << "Invalid reference value for service "
+                                       "list membership. Must be 'hostname"
+                                    << string(1, hostservice_separator)
+                                    << "servicename'";
+        } else {
+            _ref_service = value;
+        }
     } else {
-        _ref_host = string(&value[0], sep - &value[0]);
-        _ref_service = sep + 1;
+        _ref_host = value.substr(0, pos);
+        _ref_service = value.substr(pos + 1);
     }
 }
 
@@ -77,7 +81,8 @@ bool ServiceListFilter::accepts(void *row, contact * /* auth_user */,
     bool is_member = false;
     for (; mem != nullptr; mem = mem->next) {
         service *svc = mem->service_ptr;
-        if (svc->host_name == _ref_host && svc->description == _ref_service) {
+        if ((!_hostname_required || svc->host_name == _ref_host) &&
+            svc->description == _ref_service) {
             is_member = true;
             break;
         }
diff --git a/livestatus/src/ServiceListFilter.h b/livestatus/src/ServiceListFilter.h
index 5a01ab6..2fdf755 100644
--- a/livestatus/src/ServiceListFilter.h
+++ b/livestatus/src/ServiceListFilter.h
@@ -39,13 +39,14 @@
 
 class ServiceListFilter : public ColumnFilter {
 public:
-    ServiceListFilter(ServiceListColumn *column, RelationalOperator relOp,
-                      const std::string &value);
+    ServiceListFilter(ServiceListColumn *column, bool hostname_required,
+                      RelationalOperator relOp, const std::string &value);
     bool accepts(void *row, contact *auth_user, int timezone_offset) override;
     ServiceListColumn *column() const override;
 
 private:
     ServiceListColumn *_column;
+    bool _hostname_required;
     RelationalOperator _relOp;
     std::string _ref_host;
     std::string _ref_service;
diff --git a/livestatus/src/TableHosts.cc b/livestatus/src/TableHosts.cc
index 960b58d..de3f277 100644
--- a/livestatus/src/TableHosts.cc
+++ b/livestatus/src/TableHosts.cc
@@ -678,27 +678,27 @@ void TableHosts::addColumns(Table *table, const string &prefix,
         extra_offset, core));
 
     table->addColumn(make_unique<ServiceListColumn>(
-        prefix + "services", "A list of all services of the host",
+        prefix + "services", "A list of all services of the host", false,
         reinterpret_cast<char *>(&hst.services) - ref, indirect_offset, false,
         0, extra_offset));
     table->addColumn(make_unique<ServiceListColumn>(
         prefix + "services_with_state",
         "A list of all services of the host together with state and "
         "has_been_checked",
-        reinterpret_cast<char *>(&hst.services) - ref, indirect_offset, false,
-        1, extra_offset));
+        false, reinterpret_cast<char *>(&hst.services) - ref, indirect_offset,
+        false, 1, extra_offset));
     table->addColumn(make_unique<ServiceListColumn>(
         prefix + "services_with_info",
         "A list of all services including detailed information about each "
         "service",
-        reinterpret_cast<char *>(&hst.services) - ref, indirect_offset, false,
-        2, extra_offset));
+        false, reinterpret_cast<char *>(&hst.services) - ref, indirect_offset,
+        false, 2, extra_offset));
     table->addColumn(make_unique<ServiceListColumn>(
         prefix + "services_with_fullstate",
         "A list of all services including full state information. The list of "
         "entries can grow in future versions.",
-        reinterpret_cast<char *>(&hst.services) - ref, indirect_offset, false,
-        3, extra_offset));
+        false, reinterpret_cast<char *>(&hst.services) - ref, indirect_offset,
+        false, 3, extra_offset));
 
     table->addColumn(make_unique<MetricsColumn>(
         prefix + "metrics",
diff --git a/livestatus/src/TableServiceGroups.cc b/livestatus/src/TableServiceGroups.cc
index af2edc3..3bbf764 100644
--- a/livestatus/src/TableServiceGroups.cc
+++ b/livestatus/src/TableServiceGroups.cc
@@ -72,14 +72,14 @@ void TableServiceGroups::addColumns(Table *table, const string &prefix,
     table->addColumn(make_unique<ServiceListColumn>(
         prefix + "members",
         "A list of all members of the service group as host/service pairs",
-        reinterpret_cast<char *>(&sgr.members) - ref, indirect_offset, true,
-        0));
+        true, reinterpret_cast<char *>(&sgr.members) - ref, indirect_offset,
+        true, 0, -1));
     table->addColumn(make_unique<ServiceListColumn>(
         prefix + "members_with_state",
         "A list of all members of the service group with state and "
         "has_been_checked",
-        reinterpret_cast<char *>(&sgr.members) - ref, indirect_offset, true,
-        1));
+        true, reinterpret_cast<char *>(&sgr.members) - ref, indirect_offset,
+        true, 1, -1));
 
     table->addColumn(make_unique<ServiceListStateColumn>(
         prefix + "worst_service_state",



More information about the checkmk-commits mailing list