Module: check_mk
Branch: master
Commit: d2e0cd34a66f99a6d872a4f6171b59571ac6b178
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=d2e0cd34a66f99…
Author: Sven Panne <sp(a)mathias-kettner.de>
Date: Tue Feb 21 09:39:26 2017 +0100
Refactoring: Pull up method.
https://refactoring.com/catalog/pullUpMethod.html
Change-Id: Icfde6cd56dc294e7adc21aeb6898f293a7c74da5
---
livestatus/src/TableEventConsole.cc | 25 +++++++++++++++++++++++++
livestatus/src/TableEventConsole.h | 4 +++-
livestatus/src/TableEventConsoleEvents.cc | 23 +----------------------
livestatus/src/TableEventConsoleHistory.cc | 23 +----------------------
4 files changed, 30 insertions(+), 45 deletions(-)
diff --git a/livestatus/src/TableEventConsole.cc b/livestatus/src/TableEventConsole.cc
index 45afa9e..172ece1 100644
--- a/livestatus/src/TableEventConsole.cc
+++ b/livestatus/src/TableEventConsole.cc
@@ -26,6 +26,7 @@
#include "TableEventConsole.h"
#include <iosfwd>
#include <iostream>
+#include <memory>
#include <utility>
#include "Column.h"
#include "EventConsoleConnection.h"
@@ -33,6 +34,7 @@
#include "Query.h"
using std::ostream;
+using std::static_pointer_cast;
using std::string;
using std::vector;
@@ -109,3 +111,26 @@ void TableEventConsole::answerQuery(Query *query) {
}
}
}
+
+// TODO(sp) Remove evil casts below.
+bool TableEventConsole::isAuthorizedForEvent(contact *ctc, void *data) {
+ if (MonitoringCore::Host *hst = static_cast<Row *>(data)->_host) {
+ return _core->host_has_contact(
+ hst, reinterpret_cast<MonitoringCore::Contact *>(ctc));
+ }
+
+ auto col = static_pointer_cast<ListEventConsoleColumn>(
+ column("event_contact_groups"));
+ if (col->isNone(data)) {
+ return true;
+ }
+
+ for (const auto &name : col->getValue(data)) {
+ if (_core->is_contact_member_of_contactgroup(
+ _core->find_contactgroup(name),
+ reinterpret_cast<MonitoringCore::Contact *>(ctc))) {
+ return true;
+ }
+ }
+ return false;
+}
diff --git a/livestatus/src/TableEventConsole.h b/livestatus/src/TableEventConsole.h
index a7370ad..c9c6dac 100644
--- a/livestatus/src/TableEventConsole.h
+++ b/livestatus/src/TableEventConsole.h
@@ -193,7 +193,9 @@ protected:
}
};
-protected:
+ bool isAuthorizedForEvent(contact *ctc, void *data);
+
+private:
MonitoringCore *_core;
};
diff --git a/livestatus/src/TableEventConsoleEvents.cc
b/livestatus/src/TableEventConsoleEvents.cc
index 2076e59..80098cc 100644
--- a/livestatus/src/TableEventConsoleEvents.cc
+++ b/livestatus/src/TableEventConsoleEvents.cc
@@ -27,7 +27,6 @@
#include "TableEventConsoleEvents.h"
#include <memory>
#include "Column.h"
-#include "MonitoringCore.h"
#include "Table.h"
#include "TableHosts.h"
@@ -129,26 +128,6 @@ string TableEventConsoleEvents::namePrefix() const {
return "eventconsoleevents_";
}
-// 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 _core->host_has_contact(
- hst, reinterpret_cast<MonitoringCore::Contact *>(ctc));
- }
-
- auto col = static_pointer_cast<ListEventConsoleColumn>(
- column("event_contact_groups"));
- if (col->isNone(data)) {
- return true;
- }
-
- for (const auto &name : col->getValue(data)) {
- if (_core->is_contact_member_of_contactgroup(
- _core->find_contactgroup(name),
- reinterpret_cast<MonitoringCore::Contact *>(ctc))) {
- return true;
- }
- }
- return false;
+ return isAuthorizedForEvent(ctc, data);
}
diff --git a/livestatus/src/TableEventConsoleHistory.cc
b/livestatus/src/TableEventConsoleHistory.cc
index d62d889..3b185b4 100644
--- a/livestatus/src/TableEventConsoleHistory.cc
+++ b/livestatus/src/TableEventConsoleHistory.cc
@@ -27,7 +27,6 @@
#include "TableEventConsoleHistory.h"
#include <memory>
#include "Column.h"
-#include "MonitoringCore.h"
#include "TableEventConsoleEvents.h"
using std::make_unique;
@@ -75,26 +74,6 @@ string TableEventConsoleHistory::namePrefix() const {
return "eventconsolehistory_";
}
-// 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 _core->host_has_contact(
- hst, reinterpret_cast<MonitoringCore::Contact *>(ctc));
- }
-
- auto col = static_pointer_cast<ListEventConsoleColumn>(
- column("event_contact_groups"));
- if (col->isNone(data)) {
- return true;
- }
-
- for (const auto &name : col->getValue(data)) {
- if (_core->is_contact_member_of_contactgroup(
- _core->find_contactgroup(name),
- reinterpret_cast<MonitoringCore::Contact *>(ctc))) {
- return true;
- }
- }
- return false;
+ return isAuthorizedForEvent(ctc, data);
}