]> granicus.if.org Git - icinga2/commitdiff
Refactor authority checks a bit.
authorGunnar Beutner <gunnar.beutner@netways.de>
Thu, 12 Sep 2013 08:17:14 +0000 (10:17 +0200)
committerGunnar Beutner <gunnar.beutner@netways.de>
Thu, 12 Sep 2013 08:17:14 +0000 (10:17 +0200)
components/cluster/clustercomponent.cpp
components/cluster/clustercomponent.h

index 8e175ad3b001ef92d90a021f2dc950a07bddb000..fbd4dff59deac7637267c38d9e39db6d7268cb74 100644 (file)
@@ -458,8 +458,8 @@ void ClusterComponent::ClusterTimerHandler(void)
 
        /* Eww. */
        Dictionary::Ptr features = boost::make_shared<Dictionary>();
-       features->Set("checker", DynamicType::GetByName("CheckerComponent") ? 1 : 0);
-       features->Set("notification", DynamicType::GetByName("NotificationComponent") ? 1 : 0);
+       features->Set("checker", SupportsChecks() ? 1 : 0);
+       features->Set("notification", SupportsNotifications() ? 1 : 0);
        params->Set("features", features);
 
        Dictionary::Ptr message = boost::make_shared<Dictionary>();
@@ -1126,14 +1126,14 @@ void ClusterComponent::CheckAuthorityHandler(const DynamicObject::Ptr& object, c
        Array::Ptr authorities = object->GetAuthorities();
        std::vector<String> endpoints;
 
-       if ((type == "checker" && DynamicType::GetByName("CheckerComponent")) ||
-           (type == "notification" && DynamicType::GetByName("NotificationComponent")))
+       if ((type == "checker" && SupportsChecks()) ||
+           (type == "notification" && SupportsNotifications()))
                endpoints.push_back(GetIdentity());
 
        BOOST_FOREACH(const Endpoint::Ptr& endpoint, DynamicType::GetObjects<Endpoint>()) {
                bool match = false;
 
-               if (!endpoint->IsConnected())
+               if (!endpoint->IsConnected() || !endpoint->HasFeature(type))
                        continue;
 
                if (authorities) {
@@ -1163,6 +1163,16 @@ void ClusterComponent::CheckAuthorityHandler(const DynamicObject::Ptr& object, c
        result = (endpoints[index] == GetIdentity());
 }
 
+bool ClusterComponent::SupportsChecks(void)
+{
+       return DynamicType::GetByName("CheckerComponent");
+}
+
+bool ClusterComponent::SupportsNotifications(void)
+{
+       return DynamicType::GetByName("NotificationComponent");
+}
+
 void ClusterComponent::InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const
 {
        DynamicObject::InternalSerialize(bag, attributeTypes);
index 5930441982802d0f48c9cc0a5506f04839d75e58..2af62e34decea6b865ac6d82bf6a5aa25870c64b 100644 (file)
@@ -112,6 +112,9 @@ private:
        void AcknowledgementClearedHandler(const Service::Ptr& service, const String& authority);
        void MessageHandler(const Endpoint::Ptr& sender, const Dictionary::Ptr& message);
        void CheckAuthorityHandler(const DynamicObject::Ptr& object, const String& type, bool& result);
+
+       static bool SupportsChecks(void);
+       static bool SupportsNotifications(void);
 };
 
 }