Module: check_mk
Branch: master
Commit: c18812d4d48a92c063b63d54ac617b00c8f847b1
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=c18812d4d48a92…
Author: Sven Panne <sp(a)mathias-kettner.de>
Date: Wed Nov 2 11:34:52 2016 +0100
Fetched Livestatus from downstream.
---
livestatus/src/MonitoringCore.h | 7 +++++
livestatus/src/TableEventConsole.h | 2 +-
livestatus/src/TableEventConsoleEvents.cc | 44 ++++--------------------------
livestatus/src/TableEventConsoleHistory.cc | 44 ++++--------------------------
livestatus/src/module.cc | 30 +++++++++++++++++++-
5 files changed, 49 insertions(+), 78 deletions(-)
diff --git a/livestatus/src/MonitoringCore.h b/livestatus/src/MonitoringCore.h
index 591e7e7..83637c4 100644
--- a/livestatus/src/MonitoringCore.h
+++ b/livestatus/src/MonitoringCore.h
@@ -32,11 +32,18 @@ class Logger;
/// An abstraction layer for the monitoring core (nagios or cmc)
class MonitoringCore {
public:
+ class Contact;
+ class ContactGroup;
class Host;
virtual ~MonitoringCore() = default;
virtual Host *getHostByDesignation(const std::string &designation) = 0;
+ virtual ContactGroup *find_contactgroup(const std::string &name) = 0;
+
+ virtual bool host_has_contact(Host *host, Contact *contact) = 0;
+ virtual bool is_contact_member_of_contactgroup(ContactGroup *group,
+ Contact *contact) = 0;
virtual std::string mkeventdSocketPath() = 0;
diff --git a/livestatus/src/TableEventConsole.h b/livestatus/src/TableEventConsole.h
index ade3bae..35819d5 100644
--- a/livestatus/src/TableEventConsole.h
+++ b/livestatus/src/TableEventConsole.h
@@ -193,7 +193,7 @@ protected:
}
};
-private:
+protected:
MonitoringCore *_core;
};
diff --git a/livestatus/src/TableEventConsoleEvents.cc
b/livestatus/src/TableEventConsoleEvents.cc
index 5d63fcf..beb7a2d 100644
--- a/livestatus/src/TableEventConsoleEvents.cc
+++ b/livestatus/src/TableEventConsoleEvents.cc
@@ -28,14 +28,6 @@
#include "Table.h"
#include "TableHosts.h"
-#ifdef CMC
-#include "ContactGroup.h"
-#include "Host.h"
-#include "World.h"
-#else
-#include "auth.h"
-#endif
-
using std::string;
#ifdef CMC
@@ -132,38 +124,12 @@ string TableEventConsoleEvents::namePrefix() const {
return "eventconsoleevents_";
}
-// TODO(sp) Move this into some kind of abstraction layer.
-namespace {
-bool hasContact(MonitoringCore::Host *hst, contact *ctc) {
-#ifdef CMC
- return hst != nullptr && reinterpret_cast<Host
*>(hst)->hasContact(ctc);
-#else
- return is_authorized_for(ctc, reinterpret_cast<host *>(hst), nullptr);
-#endif
-}
-
-bool hasContact(contactgroup *cg, contact *ctc) {
-#ifdef CMC
- return cg != nullptr && cg->isMember(ctc);
-#else
- return is_contact_member_of_contactgroup(cg, ctc) != 0;
-#endif
-}
-
-contactgroup *getContactGroup(const string &name) {
-#ifdef CMC
- return g_live_world->getContactGroup(name);
-#else
- // Older Nagios headers are not const-correct... :-P
- return find_contactgroup(const_cast<char *>(name.c_str()));
-#endif
-}
-} // namespace
-
// TODO(sp) This is copy-n-pasted in TableEventConsoleHistory.
+// TODO(sp) Remove evil casts below.
bool TableEventConsoleEvents::isAuthorized(contact *ctc, void *data) {
if (MonitoringCore::Host *hst = static_cast<Row *>(data)->_host) {
- return hasContact(hst, ctc);
+ return _core->host_has_contact(
+ hst, reinterpret_cast<MonitoringCore::Contact *>(ctc));
}
ListEventConsoleColumn *col =
@@ -173,7 +139,9 @@ bool TableEventConsoleEvents::isAuthorized(contact *ctc, void *data)
{
}
for (const auto &name : col->getValue(data)) {
- if (hasContact(getContactGroup(name), ctc)) {
+ if (_core->is_contact_member_of_contactgroup(
+ _core->find_contactgroup(name),
+ reinterpret_cast<MonitoringCore::Contact *>(ctc))) {
return true;
}
}
diff --git a/livestatus/src/TableEventConsoleHistory.cc
b/livestatus/src/TableEventConsoleHistory.cc
index aa52a30..69f0a8a 100644
--- a/livestatus/src/TableEventConsoleHistory.cc
+++ b/livestatus/src/TableEventConsoleHistory.cc
@@ -27,14 +27,6 @@
#include "MonitoringCore.h"
#include "TableEventConsoleEvents.h"
-#ifdef CMC
-#include "ContactGroup.h"
-#include "Host.h"
-#include "World.h"
-#else
-#include "auth.h"
-#endif
-
using std::string;
#ifdef CMC
@@ -79,38 +71,12 @@ string TableEventConsoleHistory::namePrefix() const {
return "eventconsolehistory_";
}
-// TODO(sp) Move this into some kind of abstraction layer.
-namespace {
-bool hasContact(MonitoringCore::Host *hst, contact *ctc) {
-#ifdef CMC
- return hst != nullptr && reinterpret_cast<Host
*>(hst)->hasContact(ctc);
-#else
- return is_authorized_for(ctc, reinterpret_cast<host *>(hst), nullptr);
-#endif
-}
-
-bool hasContact(contactgroup *cg, contact *ctc) {
-#ifdef CMC
- return cg != nullptr && cg->isMember(ctc);
-#else
- return is_contact_member_of_contactgroup(cg, ctc) != 0;
-#endif
-}
-
-contactgroup *getContactGroup(const string &name) {
-#ifdef CMC
- return g_live_world->getContactGroup(name);
-#else
- // Older Nagios headers are not const-correct... :-P
- return find_contactgroup(const_cast<char *>(name.c_str()));
-#endif
-}
-} // namespace
-
// TODO(sp) This is copy-n-pasted in TableEventConsoleEvents.
+// TODO(sp) Remove evil casts below.
bool TableEventConsoleHistory::isAuthorized(contact *ctc, void *data) {
if (MonitoringCore::Host *hst = static_cast<Row *>(data)->_host) {
- return hasContact(hst, ctc);
+ return _core->host_has_contact(
+ hst, reinterpret_cast<MonitoringCore::Contact *>(ctc));
}
ListEventConsoleColumn *col =
@@ -120,7 +86,9 @@ bool TableEventConsoleHistory::isAuthorized(contact *ctc, void *data)
{
}
for (const auto &name : col->getValue(data)) {
- if (hasContact(getContactGroup(name), ctc)) {
+ if (_core->is_contact_member_of_contactgroup(
+ _core->find_contactgroup(name),
+ reinterpret_cast<MonitoringCore::Contact *>(ctc))) {
return true;
}
}
diff --git a/livestatus/src/module.cc b/livestatus/src/module.cc
index 94b7277..a0becd5 100644
--- a/livestatus/src/module.cc
+++ b/livestatus/src/module.cc
@@ -576,17 +576,45 @@ int broker_event(int event_type __attribute__((__unused__)), void
*data) {
class NagiosCore : public MonitoringCore {
public:
- Host *getHostByDesignation(const std::string &designation) override {
+ Host *getHostByDesignation(const string &designation) override {
auto it = fl_hosts_by_designation.find(unsafe_tolower(designation));
return it == fl_hosts_by_designation.end() ? nullptr
: fromImpl(it->second);
}
+ bool host_has_contact(Host *host, Contact *contact) override {
+ return is_authorized_for(toImpl(contact), toImpl(host), nullptr);
+ }
+
+ ContactGroup *find_contactgroup(const std::string &name) override {
+ // Older Nagios headers are not const-correct... :-P
+ return fromImpl(::find_contactgroup(const_cast<char *>(name.c_str())));
+ }
+
+ bool is_contact_member_of_contactgroup(ContactGroup *group,
+ Contact *contact) override {
+ return ::is_contact_member_of_contactgroup(toImpl(group),
+ toImpl(contact)) != 0;
+ }
+
string mkeventdSocketPath() override { return g_mkeventd_socket_path; }
Logger *loggerLivestatus() override { return fl_logger_livestatus; }
private:
+ static contact *toImpl(Contact *c) {
+ return reinterpret_cast<contact *>(c);
+ }
+
+ static contactgroup *toImpl(ContactGroup *g) {
+ return reinterpret_cast<contactgroup *>(g);
+ }
+
+ static ContactGroup *fromImpl(contactgroup *g) {
+ return reinterpret_cast<ContactGroup *>(g);
+ }
+
+ static host *toImpl(Host *h) { return reinterpret_cast<host *>(h); }
static Host *fromImpl(host *h) { return reinterpret_cast<Host *>(h); }
};