Module: check_mk
Branch: master
Commit: ea120ba878019945f3d354f0e4f3bb7573079a75
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=ea120ba8780199…
Author: Sven Panne <sp(a)mathias-kettner.de>
Date: Mon Nov 6 13:57:17 2017 +0100
Unify special int column implementations.
Note that this commit adds a missing "hard_state" column to the
"services"
table, which in turn fixes a somehow obscure BI bug.
Change-Id: Ia263cececd806e8383041550f65886dbe7afe0a1
---
livestatus/src/HostSpecialIntColumn.cc | 45 ++++++++++++++++++++++++++++---
livestatus/src/HostSpecialIntColumn.h | 11 ++++----
livestatus/src/ServiceSpecialIntColumn.cc | 45 +++++++++++++++++++++++++++++++
livestatus/src/ServiceSpecialIntColumn.h | 15 ++++++-----
livestatus/src/TableServices.cc | 5 ++++
5 files changed, 105 insertions(+), 16 deletions(-)
diff --git a/livestatus/src/HostSpecialIntColumn.cc
b/livestatus/src/HostSpecialIntColumn.cc
index b883aad..127aa1e 100644
--- a/livestatus/src/HostSpecialIntColumn.cc
+++ b/livestatus/src/HostSpecialIntColumn.cc
@@ -26,21 +26,57 @@
#include "MonitoringCore.h"
#include "Row.h"
#include "mk_inventory.h"
+
+#ifdef CMC
+#include "Core.h"
+#include "Host.h"
+#include "Object.h"
+#include "RRDBackend.h"
+#include "RRDInfoCache.h"
+#include "State.h"
+#include "cmc.h"
+#else
#include "nagios.h"
#include "pnp4nagios.h"
+#endif
int32_t HostSpecialIntColumn::getValue(Row row,
const contact* /* auth_user */) const {
+#ifdef CMC
+ if (auto object = columnData<Object>(row)) {
+ switch (_type) {
+ case Type::real_hard_state: {
+ auto state = object->state();
+ if (state->_current_state == 0) {
+ return 0;
+ }
+ if (state->_state_type == StateType::hard) {
+ return state->_current_state;
+ }
+ return state->_last_hard_state;
+ }
+ case Type::pnp_graph_present:
+ return _mc->impl<Core>()
+ ->_rrd_backend.infoFor(object)
+ ._names.empty()
+ ? 0
+ : 1;
+ case Type::mk_inventory_last:
+ return static_cast<int32_t>(mk_inventory_last(
+ _mc->mkInventoryPath() + "/" +
object->host()->name()));
+ }
+ }
+#else
if (auto hst = columnData<host>(row)) {
switch (_type) {
case Type::real_hard_state:
if (hst->current_state == 0) {
return 0;
- } else if (hst->state_type == 1) {
- return hst->current_state; // we have reached a hard state
- } else {
- return hst->last_hard_state;
}
+ if (hst->state_type == HARD_STATE) {
+ return hst->current_state;
+ }
+ return hst->last_hard_state;
case Type::pnp_graph_present:
return pnpgraph_present(_mc, hst->name,
@@ -52,5 +88,6 @@ int32_t HostSpecialIntColumn::getValue(Row row,
}
}
}
+#endif
return 0;
}
diff --git a/livestatus/src/HostSpecialIntColumn.h
b/livestatus/src/HostSpecialIntColumn.h
index 034367f..f9f4b1d 100644
--- a/livestatus/src/HostSpecialIntColumn.h
+++ b/livestatus/src/HostSpecialIntColumn.h
@@ -37,18 +37,19 @@ class HostSpecialIntColumn : public IntColumn {
public:
enum class Type { real_hard_state, pnp_graph_present, mk_inventory_last };
- HostSpecialIntColumn(const std::string& name,
- const std::string& description, int indirect_offset,
+ HostSpecialIntColumn(const std::string &name,
+ const std::string &description, int indirect_offset,
int extra_offset, int extra_extra_offset, int offset,
- MonitoringCore* mc, Type hsic_type)
+ MonitoringCore *mc, Type hsic_type)
: IntColumn(name, description, indirect_offset, extra_offset,
extra_extra_offset, offset)
, _mc(mc)
, _type(hsic_type) {}
- int32_t getValue(Row row, const contact* auth_user) const override;
+
+ int32_t getValue(Row row, const contact *auth_user) const override;
private:
- MonitoringCore* _mc;
+ MonitoringCore *_mc;
const Type _type;
};
diff --git a/livestatus/src/ServiceSpecialIntColumn.cc
b/livestatus/src/ServiceSpecialIntColumn.cc
index 7fed2ee..40ddb99 100644
--- a/livestatus/src/ServiceSpecialIntColumn.cc
+++ b/livestatus/src/ServiceSpecialIntColumn.cc
@@ -24,17 +24,62 @@
#include "ServiceSpecialIntColumn.h"
#include "Row.h"
+
+#ifdef CMC
+#include "Core.h"
+#include "Host.h"
+#include "MonitoringCore.h"
+#include "Object.h"
+#include "RRDBackend.h"
+#include "RRDInfoCache.h"
+#include "State.h"
+#include "cmc.h"
+#include "mk_inventory.h"
+#else
#include "nagios.h"
#include "pnp4nagios.h"
+#endif
int32_t ServiceSpecialIntColumn::getValue(
Row row, const contact* /* auth_user */) const {
+#ifdef CMC
+ if (auto object = columnData<Object>(row)) {
+ switch (_type) {
+ case Type::real_hard_state: {
+ auto state = object->state();
+ if (state->_current_state == 0) {
+ return 0;
+ }
+ if (state->_state_type == StateType::hard) {
+ return state->_current_state;
+ }
+ return state->_last_hard_state;
+ }
+ case Type::pnp_graph_present:
+ return _mc->impl<Core>()
+ ->_rrd_backend.infoFor(object)
+ ._names.empty()
+ ? 0
+ : 1;
+ }
+ }
+#else
if (auto svc = columnData<service>(row)) {
switch (_type) {
+ case Type::real_hard_state:
+ if (svc->current_state == 0) {
+ return 0;
+ }
+ if (svc->state_type == HARD_STATE) {
+ return svc->current_state;
+ }
+ return svc->last_hard_state;
+
case Type::pnp_graph_present:
return pnpgraph_present(_mc, svc->host_ptr->name,
svc->description);
}
}
+#endif
return 0;
}
diff --git a/livestatus/src/ServiceSpecialIntColumn.h
b/livestatus/src/ServiceSpecialIntColumn.h
index 37008b3..82c028d 100644
--- a/livestatus/src/ServiceSpecialIntColumn.h
+++ b/livestatus/src/ServiceSpecialIntColumn.h
@@ -35,21 +35,22 @@ class Row;
class ServiceSpecialIntColumn : public IntColumn {
public:
- enum class Type { pnp_graph_present };
+ enum class Type { real_hard_state, pnp_graph_present };
- ServiceSpecialIntColumn(const std::string& name,
- const std::string& description, int indirect_offset,
+ ServiceSpecialIntColumn(const std::string &name,
+ const std::string &description, int indirect_offset,
int extra_offset, int extra_extra_offset,
- int offset, MonitoringCore* mc, Type ssic_type)
+ int offset, MonitoringCore *mc, Type ssic_type)
: IntColumn(name, description, indirect_offset, extra_offset,
extra_extra_offset, offset)
, _mc(mc)
, _type(ssic_type) {}
- int32_t getValue(Row row, const contact* auth_user) const override;
+
+ int32_t getValue(Row row, const contact *auth_user) const override;
private:
- MonitoringCore* _mc;
- Type _type;
+ MonitoringCore *_mc;
+ const Type _type;
};
#endif // ServiceSpecialIntColumn_h
diff --git a/livestatus/src/TableServices.cc b/livestatus/src/TableServices.cc
index 8c167d5..f0fdc83 100644
--- a/livestatus/src/TableServices.cc
+++ b/livestatus/src/TableServices.cc
@@ -333,6 +333,11 @@ void TableServices::addColumns(Table *table, const std::string
&prefix,
"A list of all modified attributes", indirect_offset, -1, -1,
DANGEROUS_OFFSETOF(service, modified_attributes)));
table->addColumn(std::make_unique<ServiceSpecialIntColumn>(
+ prefix + "hard_state",
+ "The effective hard state of the service (eliminates a problem in
hard_state)",
+ indirect_offset, -1, -1, 0, table->core(),
+ ServiceSpecialIntColumn::Type::real_hard_state));
+ table->addColumn(std::make_unique<ServiceSpecialIntColumn>(
prefix + "pnpgraph_present",
"Whether there is a PNP4Nagios graph present for this service (0/1)",
indirect_offset, -1, -1, 0, table->core(),