Module: check_mk
Branch: master
Commit: 0e686d7ff54b9f6350bfad304b797b1dd6ee86e5
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=0e686d7ff54b9f…
Author: Sven Panne <sp(a)mathias-kettner.de>
Date: Mon Feb 25 14:41:03 2019 +0100
Move find_service into MonitoringCore abstraction.
Change-Id: Ie88a271feb12a53be088730b37d9748685803d18
---
livestatus/src/DowntimeOrComment.cc | 6 +++---
livestatus/src/LogEntry.cc | 7 +++----
livestatus/src/MonitoringCore.h | 2 ++
livestatus/src/TableServices.cc | 5 +----
livestatus/src/module.cc | 25 +++++++++++++++++--------
5 files changed, 26 insertions(+), 19 deletions(-)
diff --git a/livestatus/src/DowntimeOrComment.cc b/livestatus/src/DowntimeOrComment.cc
index 1d3bdcc..273322a 100644
--- a/livestatus/src/DowntimeOrComment.cc
+++ b/livestatus/src/DowntimeOrComment.cc
@@ -32,9 +32,9 @@ DowntimeOrComment::DowntimeOrComment(MonitoringCore *mc,
: _type(dt->downtime_type)
, _is_service(dt->service_description != nullptr)
, _host(reinterpret_cast<host *>(mc->find_host(dt->host_name)))
- , _service(_is_service
- ? find_service(dt->host_name, dt->service_description)
- : nullptr)
+ , _service(_is_service ? reinterpret_cast<service *>(mc->find_service(
+ dt->host_name, dt->service_description))
+ : nullptr)
, _entry_time(dt->entry_time)
, _author_name(dt->author_name)
, _comment(dt->comment_data)
diff --git a/livestatus/src/LogEntry.cc b/livestatus/src/LogEntry.cc
index ee9f01f..585aa9f 100644
--- a/livestatus/src/LogEntry.cc
+++ b/livestatus/src/LogEntry.cc
@@ -408,10 +408,9 @@ unsigned LogEntry::updateReferences(MonitoringCore *mc) {
updated++;
}
if (!_service_description.empty()) {
- // Older Nagios headers are not const-correct... :-P
- _service =
- find_service(const_cast<char *>(_host_name.c_str()),
- const_cast<char *>(_service_description.c_str()));
+ // TODO(sp): Remove ugly cast.
+ _service = reinterpret_cast<service *>(
+ mc->find_service(_host_name, _service_description));
updated++;
}
if (!_contact_name.empty()) {
diff --git a/livestatus/src/MonitoringCore.h b/livestatus/src/MonitoringCore.h
index 45b24a2..033ba0b 100644
--- a/livestatus/src/MonitoringCore.h
+++ b/livestatus/src/MonitoringCore.h
@@ -74,6 +74,8 @@ public:
virtual Host *find_host(const std::string &name) = 0;
virtual Host *getHostByDesignation(const std::string &designation) = 0;
+ virtual Service *find_service(const std::string &host_name,
+ const std::string &service_description) = 0;
virtual ContactGroup *find_contactgroup(const std::string &name) = 0;
virtual const Contact *find_contact(const std::string &name) = 0;
diff --git a/livestatus/src/TableServices.cc b/livestatus/src/TableServices.cc
index 7491a7a..3ee8d87 100644
--- a/livestatus/src/TableServices.cc
+++ b/livestatus/src/TableServices.cc
@@ -548,8 +548,5 @@ Row TableServices::findObject(const std::string &objectspec) const
{
? mk::nextField(objectspec)
: make_pair(mk::rstrip(objectspec.substr(0, semicolon)),
mk::rstrip(objectspec.substr(semicolon + 1)));
- auto foo = find_service(const_cast<char *>(host_and_desc.first.c_str()),
- const_cast<char *>(host_and_desc.second.c_str()));
-
- return Row(foo);
+ return Row(core()->find_service(host_and_desc.first, host_and_desc.second));
}
diff --git a/livestatus/src/module.cc b/livestatus/src/module.cc
index ae5f5c0..1ce093d 100644
--- a/livestatus/src/module.cc
+++ b/livestatus/src/module.cc
@@ -577,6 +577,14 @@ public:
: fromImpl(it->second);
}
+ Service *find_service(const std::string &host_name,
+ const std::string &service_description) override {
+ // Older Nagios headers are not const-correct... :-P
+ return fromImpl(
+ ::find_service(const_cast<char *>(host_name.c_str()),
+ const_cast<char *>(service_description.c_str())));
+ }
+
bool host_has_contact(const Host *host, const Contact *contact) override {
return is_authorized_for(this, toImpl(contact), toImpl(host), nullptr);
}
@@ -698,26 +706,27 @@ private:
static const Contact *fromImpl(const contact *c) {
return reinterpret_cast<const Contact *>(c);
}
-
static const contact *toImpl(const Contact *c) {
return reinterpret_cast<const contact *>(c);
}
- static const contactgroup *toImpl(const ContactGroup *g) {
- return reinterpret_cast<const contactgroup *>(g);
- }
-
static ContactGroup *fromImpl(contactgroup *g) {
return reinterpret_cast<ContactGroup *>(g);
}
+ static const contactgroup *toImpl(const ContactGroup *g) {
+ return reinterpret_cast<const contactgroup *>(g);
+ }
+ static Host *fromImpl(host *h) { return reinterpret_cast<Host *>(h); }
static const host *toImpl(const Host *h) {
return reinterpret_cast<const host *>(h);
}
- static Host *fromImpl(host *h) { return reinterpret_cast<Host *>(h); }
- static const service *toImpl(const Service *h) {
- return reinterpret_cast<const service *>(h);
+ static Service *fromImpl(service *s) {
+ return reinterpret_cast<Service *>(s);
+ }
+ static const service *toImpl(const Service *s) {
+ return reinterpret_cast<const service *>(s);
}
std::vector<DowntimeData> downtimes_for_object(const ::host *h,