Module: check_mk
Branch: master
Commit: fd43b100d02c3e3de93550a41dca39f92895384a
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=fd43b100d02c3e…
Author: Sven Panne <sp(a)mathias-kettner.de>
Date: Thu Nov 2 10:31:38 2017 +0100
Various simplifications.
Change-Id: I4eec71bae9f8bd93cd2bc3642305afa8a6cdbb2e
---
livestatus/src/HostListStateColumn.cc | 42 ++++++++++++--------------
livestatus/src/HostListStateColumn.h | 8 +----
livestatus/src/ServiceListStateColumn.cc | 52 ++++++++++++++++----------------
livestatus/src/ServiceListStateColumn.h | 15 +++++----
4 files changed, 55 insertions(+), 62 deletions(-)
diff --git a/livestatus/src/HostListStateColumn.cc
b/livestatus/src/HostListStateColumn.cc
index a3d5002..b1acd56 100644
--- a/livestatus/src/HostListStateColumn.cc
+++ b/livestatus/src/HostListStateColumn.cc
@@ -26,7 +26,22 @@
#include "Row.h"
#include "auth.h"
-static inline bool hst_state_is_worse(int32_t state1, int32_t state2) {
+int32_t HostListStateColumn::getValue(Row row, const contact *auth_user) const {
+ int32_t result = 0;
+ if (auto p = columnData<hostsmember *>(row)) {
+ for (hostsmember *mem = *p; mem != nullptr; mem = mem->next) {
+ host *hst = mem->host_ptr;
+ if (auth_user == nullptr ||
+ is_authorized_for(_mc, auth_user, hst, nullptr)) {
+ update(hst, auth_user, result);
+ }
+ }
+ }
+ return result;
+}
+
+namespace {
+bool hst_state_is_worse(int32_t state1, int32_t state2) {
if (state1 == 0) {
return false; // UP is worse than nothing
}
@@ -41,27 +56,8 @@ static inline bool hst_state_is_worse(int32_t state1, int32_t state2)
{
}
return false; // both are UNREACHABLE
}
+} // namespace
-hostsmember *HostListStateColumn::getMembers(Row row) const {
- if (auto p = columnData<hostsmember *>(row)) {
- return *p;
- }
- return nullptr;
-}
-
-int32_t HostListStateColumn::getValue(Row row, const contact *auth_user) const {
- int32_t result = 0;
- for (hostsmember *mem = getMembers(row); mem != nullptr; mem = mem->next) {
- host *hst = mem->host_ptr;
- if (auth_user == nullptr ||
- is_authorized_for(_mc, auth_user, hst, nullptr)) {
- update(hst, auth_user, result);
- }
- }
- return result;
-}
-
-// static
void HostListStateColumn::update(host *hst, const contact *auth_user,
int32_t &result) const {
switch (_logictype) {
@@ -71,13 +67,13 @@ void HostListStateColumn::update(host *hst, const contact *auth_user,
case Type::num_svc_crit:
case Type::num_svc_unknown:
case Type::num_svc:
- result += ServiceListStateColumn::getValue(
+ result += ServiceListStateColumn::getValueFromServices(
_mc, static_cast<ServiceListStateColumn::Type>(_logictype),
hst->services, auth_user);
break;
case Type::worst_svc_state: {
- int state = ServiceListStateColumn::getValue(
+ int state = ServiceListStateColumn::getValueFromServices(
_mc, static_cast<ServiceListStateColumn::Type>(_logictype),
hst->services, auth_user);
if (ServiceListStateColumn::svcStateIsWorse(state, result)) {
diff --git a/livestatus/src/HostListStateColumn.h b/livestatus/src/HostListStateColumn.h
index dfa17a5..187c094 100644
--- a/livestatus/src/HostListStateColumn.h
+++ b/livestatus/src/HostListStateColumn.h
@@ -34,9 +34,7 @@ class MonitoringCore;
class Row;
#ifdef CMC
-#include <unordered_set>
#include "cmc.h"
-class Host;
#else
#include "nagios.h"
#endif
@@ -81,12 +79,8 @@ public:
extra_extra_offset, offset)
, _mc(mc)
, _logictype(logictype) {}
+
int32_t getValue(Row row, const contact *auth_user) const override;
-#ifdef CMC
- const std::unordered_set<Host *> *getMembers(Row row) const;
-#else
- hostsmember *getMembers(Row row) const;
-#endif
private:
MonitoringCore *_mc;
diff --git a/livestatus/src/ServiceListStateColumn.cc
b/livestatus/src/ServiceListStateColumn.cc
index fa1f368..0b04681 100644
--- a/livestatus/src/ServiceListStateColumn.cc
+++ b/livestatus/src/ServiceListStateColumn.cc
@@ -26,34 +26,20 @@
#include "Row.h"
#include "auth.h"
-// return true if state1 is worse than state2
-bool ServiceListStateColumn::svcStateIsWorse(int32_t state1, int32_t state2) {
- if (state1 == 0) {
- return false; // OK is worse than nothing
- }
- if (state2 == 0) {
- return true; // everything else is worse then OK
- }
- if (state2 == 2) {
- return false; // nothing is worse than CRIT
- }
- if (state1 == 2) {
- return true; // state1 is CRIT, state2 not
- }
- return (state1 > state2); // both or WARN or UNKNOWN
-}
-
-servicesmember *ServiceListStateColumn::getMembers(Row row) const {
+int32_t ServiceListStateColumn::getValue(Row row,
+ const contact *auth_user) const {
+ servicesmember *mem = nullptr;
if (auto p = columnData<servicesmember *>(row)) {
- return *p;
+ mem = *p;
}
- return nullptr;
+ return getValueFromServices(_mc, _logictype, mem, auth_user);
}
// static
-int32_t ServiceListStateColumn::getValue(MonitoringCore *mc, Type logictype,
- servicesmember *mem,
- const contact *auth_user) {
+int32_t ServiceListStateColumn::getValueFromServices(MonitoringCore *mc,
+ Type logictype,
+ servicesmember *mem,
+ const contact *auth_user) {
int32_t result = 0;
for (; mem != nullptr; mem = mem->next) {
service *svc = mem->service_ptr;
@@ -65,9 +51,23 @@ int32_t ServiceListStateColumn::getValue(MonitoringCore *mc, Type
logictype,
return result;
}
-int32_t ServiceListStateColumn::getValue(Row row,
- const contact *auth_user) const {
- return getValue(_mc, _logictype, getMembers(row), auth_user);
+// return true if state1 is worse than state2
+
+// static
+bool ServiceListStateColumn::svcStateIsWorse(int32_t state1, int32_t state2) {
+ if (state1 == 0) {
+ return false; // OK is worse than nothing
+ }
+ if (state2 == 0) {
+ return true; // everything else is worse then OK
+ }
+ if (state2 == 2) {
+ return false; // nothing is worse than CRIT
+ }
+ if (state1 == 2) {
+ return true; // state1 is CRIT, state2 not
+ }
+ return (state1 > state2); // both or WARN or UNKNOWN
}
// static
diff --git a/livestatus/src/ServiceListStateColumn.h
b/livestatus/src/ServiceListStateColumn.h
index 21d98a6..41cb199 100644
--- a/livestatus/src/ServiceListStateColumn.h
+++ b/livestatus/src/ServiceListStateColumn.h
@@ -65,16 +65,19 @@ public:
extra_extra_offset, offset)
, _mc(mc)
, _logictype(logictype) {}
+
int32_t getValue(Row row, const contact *auth_user) const override;
+
#ifdef CMC
- static int32_t getValue(MonitoringCore *mc, Type logictype,
- const Host::services_t *mem,
- const contact *auth_user);
+ using service_list = const Host::services_t *;
#else
- static int32_t getValue(MonitoringCore *mc, Type logictype,
- servicesmember *mem, const contact *auth_user);
- servicesmember *getMembers(Row row) const;
+ using service_list = servicesmember *;
#endif
+
+ static int32_t getValueFromServices(MonitoringCore *mc, Type logictype,
+ service_list mem,
+ const contact *auth_user);
+
static bool svcStateIsWorse(int32_t state1, int32_t state2);
private: