[icinga-checkins] icinga.org: icinga2/master: Improve validation for the command_endpoint attribute

git at icinga.org git at icinga.org
Sun Aug 14 22:11:47 CEST 2016


Module: icinga2
Branch: master
Commit: 39ded04e1a57aca894da97bcc70d110a779158c0
URL:    https://git.icinga.org/?p=icinga2.git;a=commit;h=39ded04e1a57aca894da97bcc70d110a779158c0

Author: Gunnar Beutner <gunnar.beutner at netways.de>
Date:   Sun Aug 14 22:10:30 2016 +0200

Improve validation for the command_endpoint attribute

fixes #12432

---

 lib/icinga/checkable.cpp |   21 +++++++++++++++++++++
 lib/icinga/checkable.hpp |    1 +
 lib/icinga/checkable.ti  |    4 ++++
 lib/remote/endpoint.cpp  |    2 +-
 lib/remote/zone.cpp      |    2 ++
 5 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/lib/icinga/checkable.cpp b/lib/icinga/checkable.cpp
index 73bf6af..9e13c17 100644
--- a/lib/icinga/checkable.cpp
+++ b/lib/icinga/checkable.cpp
@@ -51,6 +51,27 @@ Checkable::Checkable(void)
 	SetSchedulingOffset(Utility::Random());
 }
 
+void Checkable::OnAllConfigLoaded(void)
+{
+	ObjectImpl<Checkable>::OnAllConfigLoaded();
+
+	Endpoint::Ptr endpoint = GetCommandEndpoint();
+
+	if (endpoint) {
+		Zone::Ptr checkableZone = static_pointer_cast<Zone>(GetZone());
+
+		if (!checkableZone)
+			checkableZone = Zone::GetLocalZone();
+
+		Zone::Ptr cmdZone = endpoint->GetZone();
+
+		if (cmdZone != checkableZone && cmdZone->GetParent() != checkableZone) {
+			BOOST_THROW_EXCEPTION(ValidationError(this, boost::assign::list_of("command_endpoint"),
+			    "Command endpoint must be in zone '" + checkableZone->GetName() + "' or in a direct child zone thereof."));
+		}
+	}
+}
+
 void Checkable::Start(bool runtimeCreated)
 {
 	double now = Utility::GetTime();
diff --git a/lib/icinga/checkable.hpp b/lib/icinga/checkable.hpp
index d40e1b7..db15fca 100644
--- a/lib/icinga/checkable.hpp
+++ b/lib/icinga/checkable.hpp
@@ -185,6 +185,7 @@ public:
 
 protected:
 	virtual void Start(bool runtimeCreated) override;
+	virtual void OnAllConfigLoaded(void) override;
 
 private:
 	mutable boost::mutex m_CheckableMutex;
diff --git a/lib/icinga/checkable.ti b/lib/icinga/checkable.ti
index 27a158d..81571f9 100644
--- a/lib/icinga/checkable.ti
+++ b/lib/icinga/checkable.ti
@@ -44,6 +44,10 @@ enum AcknowledgementType
 
 abstract class Checkable : CustomVarObject
 {
+	load_after ApiListener;
+	load_after Endpoint;
+	load_after Zone;
+
 	[config, required, navigation] name(CheckCommand) check_command (CheckCommandRaw) {
 		navigate {{{
 			return CheckCommand::GetByName(GetCheckCommandRaw());
diff --git a/lib/remote/endpoint.cpp b/lib/remote/endpoint.cpp
index 4430308..1cfe9ed 100644
--- a/lib/remote/endpoint.cpp
+++ b/lib/remote/endpoint.cpp
@@ -37,7 +37,7 @@ boost::signals2::signal<void(const Endpoint::Ptr&, const JsonRpcConnection::Ptr&
 
 void Endpoint::OnAllConfigLoaded(void)
 {
-	ConfigObject::OnConfigLoaded();
+	ObjectImpl<Endpoint>::OnAllConfigLoaded();
 
 	BOOST_FOREACH(const Zone::Ptr& zone, ConfigType::GetObjectsByType<Zone>()) {
 		const std::set<Endpoint::Ptr> members = zone->GetEndpoints();
diff --git a/lib/remote/zone.cpp b/lib/remote/zone.cpp
index 31286b8..594fc6c 100644
--- a/lib/remote/zone.cpp
+++ b/lib/remote/zone.cpp
@@ -30,6 +30,8 @@ REGISTER_TYPE(Zone);
 
 void Zone::OnAllConfigLoaded(void)
 {
+	ObjectImpl<Zone>::OnAllConfigLoaded();
+
 	m_Parent = Zone::GetByName(GetParentRaw());
 
 	Zone::Ptr zone = m_Parent;



More information about the icinga-checkins mailing list