Module: check_mk
Branch: master
Commit: dcdb151e5e9e945650a943dd6e3e5ecbb887206c
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=dcdb151e5e9e94…
Author: Sven Panne <sp(a)mathias-kettner.de>
Date: Thu Nov 2 10:12:32 2017 +0100
Extract update logic, separating it from filtering logic.
Change-Id: I5a4832b109da1e99bbcf8834cfb8fbee2cd1484f
---
livestatus/src/HostListStateColumn.cc | 113 ++++++++++++++++---------------
livestatus/src/HostListStateColumn.h | 2 +
livestatus/src/ServiceListStateColumn.cc | 67 ++++++++++--------
livestatus/src/ServiceListStateColumn.h | 2 +
4 files changed, 99 insertions(+), 85 deletions(-)
diff --git a/livestatus/src/HostListStateColumn.cc
b/livestatus/src/HostListStateColumn.cc
index 9f43fc5..a3d5002 100644
--- a/livestatus/src/HostListStateColumn.cc
+++ b/livestatus/src/HostListStateColumn.cc
@@ -55,66 +55,69 @@ int32_t HostListStateColumn::getValue(Row row, const contact
*auth_user) const {
host *hst = mem->host_ptr;
if (auth_user == nullptr ||
is_authorized_for(_mc, auth_user, hst, nullptr)) {
- switch (_logictype) {
- case Type::num_svc_pending:
- case Type::num_svc_ok:
- case Type::num_svc_warn:
- case Type::num_svc_crit:
- case Type::num_svc_unknown:
- case Type::num_svc:
- result += ServiceListStateColumn::getValue(
- _mc,
- static_cast<ServiceListStateColumn::Type>(_logictype),
- hst->services, auth_user);
- break;
+ update(hst, auth_user, result);
+ }
+ }
+ return result;
+}
- case Type::worst_svc_state: {
- int state = ServiceListStateColumn::getValue(
- _mc,
- static_cast<ServiceListStateColumn::Type>(_logictype),
- hst->services, auth_user);
- if (ServiceListStateColumn::svcStateIsWorse(state,
- result)) {
- result = state;
- }
- break;
- }
+// static
+void HostListStateColumn::update(host *hst, const contact *auth_user,
+ int32_t &result) const {
+ switch (_logictype) {
+ case Type::num_svc_pending:
+ case Type::num_svc_ok:
+ case Type::num_svc_warn:
+ case Type::num_svc_crit:
+ case Type::num_svc_unknown:
+ case Type::num_svc:
+ result += ServiceListStateColumn::getValue(
+ _mc, static_cast<ServiceListStateColumn::Type>(_logictype),
+ hst->services, auth_user);
+ break;
- case Type::num_hst_up:
- case Type::num_hst_down:
- case Type::num_hst_unreach:
- if (hst->has_been_checked != 0 &&
- hst->current_state ==
- static_cast<int>(_logictype) -
- static_cast<int>(Type::num_hst_up)) {
- result++;
- }
- break;
+ case Type::worst_svc_state: {
+ int state = ServiceListStateColumn::getValue(
+ _mc, static_cast<ServiceListStateColumn::Type>(_logictype),
+ hst->services, auth_user);
+ if (ServiceListStateColumn::svcStateIsWorse(state, result)) {
+ result = state;
+ }
+ break;
+ }
- case Type::num_hst_pending:
- if (hst->has_been_checked == 0) {
- result++;
- }
- break;
+ case Type::num_hst_up:
+ case Type::num_hst_down:
+ case Type::num_hst_unreach:
+ if (hst->has_been_checked != 0 &&
+ hst->current_state ==
+ static_cast<int>(_logictype) -
+ static_cast<int>(Type::num_hst_up)) {
+ result++;
+ }
+ break;
+
+ case Type::num_hst_pending:
+ if (hst->has_been_checked == 0) {
+ result++;
+ }
+ break;
- case Type::num_hst:
- result++;
- break;
+ case Type::num_hst:
+ result++;
+ break;
- case Type::worst_hst_state:
- if (hst_state_is_worse(hst->current_state, result)) {
- result = hst->current_state;
- }
- break;
- case Type::num_svc_hard_ok:
- case Type::num_svc_hard_warn:
- case Type::num_svc_hard_crit:
- case Type::num_svc_hard_unknown:
- case Type::worst_svc_hard_state:
- // TODO(sp) Why are these not handled?
- break;
+ case Type::worst_hst_state:
+ if (hst_state_is_worse(hst->current_state, result)) {
+ result = hst->current_state;
}
- }
+ break;
+ case Type::num_svc_hard_ok:
+ case Type::num_svc_hard_warn:
+ case Type::num_svc_hard_crit:
+ case Type::num_svc_hard_unknown:
+ case Type::worst_svc_hard_state:
+ // TODO(sp) Why are these not handled?
+ break;
}
- return result;
}
diff --git a/livestatus/src/HostListStateColumn.h b/livestatus/src/HostListStateColumn.h
index 15e7350..dfa17a5 100644
--- a/livestatus/src/HostListStateColumn.h
+++ b/livestatus/src/HostListStateColumn.h
@@ -91,6 +91,8 @@ public:
private:
MonitoringCore *_mc;
const Type _logictype;
+
+ void update(host *hst, const contact *auth_user, int32_t &result) const;
};
#endif // HostListStateColumn_h
diff --git a/livestatus/src/ServiceListStateColumn.cc
b/livestatus/src/ServiceListStateColumn.cc
index 0c3da04..fa1f368 100644
--- a/livestatus/src/ServiceListStateColumn.cc
+++ b/livestatus/src/ServiceListStateColumn.cc
@@ -50,6 +50,7 @@ servicesmember *ServiceListStateColumn::getMembers(Row row) const {
return nullptr;
}
+// static
int32_t ServiceListStateColumn::getValue(MonitoringCore *mc, Type logictype,
servicesmember *mem,
const contact *auth_user) {
@@ -58,36 +59,7 @@ int32_t ServiceListStateColumn::getValue(MonitoringCore *mc, Type
logictype,
service *svc = mem->service_ptr;
if (auth_user == nullptr ||
is_authorized_for(mc, auth_user, svc->host_ptr, svc)) {
- int service_state;
- Type lt;
- if (static_cast<int>(logictype) >= 60) {
- service_state = svc->last_hard_state;
- lt = static_cast<Type>(static_cast<int>(logictype) - 64);
- } else {
- service_state = svc->current_state;
- lt = logictype;
- }
- switch (lt) {
- case Type::worst_state:
- if (svcStateIsWorse(service_state, result)) {
- result = service_state;
- }
- break;
- case Type::num:
- result++;
- break;
- case Type::num_pending:
- if (svc->has_been_checked == 0) {
- result++;
- }
- break;
- default:
- if (svc->has_been_checked != 0 &&
- service_state == static_cast<int>(lt)) {
- result++;
- }
- break;
- }
+ update(logictype, svc, result);
}
}
return result;
@@ -97,3 +69,38 @@ int32_t ServiceListStateColumn::getValue(Row row,
const contact *auth_user) const {
return getValue(_mc, _logictype, getMembers(row), auth_user);
}
+
+// static
+void ServiceListStateColumn::update(Type logictype, service *svc,
+ int32_t &result) {
+ int service_state;
+ Type lt;
+ if (static_cast<int>(logictype) >= 60) {
+ service_state = svc->last_hard_state;
+ lt = static_cast<Type>(static_cast<int>(logictype) - 64);
+ } else {
+ service_state = svc->current_state;
+ lt = logictype;
+ }
+ switch (lt) {
+ case Type::worst_state:
+ if (svcStateIsWorse(service_state, result)) {
+ result = service_state;
+ }
+ break;
+ case Type::num:
+ result++;
+ break;
+ case Type::num_pending:
+ if (svc->has_been_checked == 0) {
+ result++;
+ }
+ break;
+ default:
+ if (svc->has_been_checked != 0 &&
+ service_state == static_cast<int>(lt)) {
+ result++;
+ }
+ break;
+ }
+}
diff --git a/livestatus/src/ServiceListStateColumn.h
b/livestatus/src/ServiceListStateColumn.h
index 29ca063..21d98a6 100644
--- a/livestatus/src/ServiceListStateColumn.h
+++ b/livestatus/src/ServiceListStateColumn.h
@@ -80,6 +80,8 @@ public:
private:
MonitoringCore *_mc;
const Type _logictype;
+
+ static void update(Type logictype, service *svc, int32_t &result);
};
#endif // ServiceListStateColumn_h