]> granicus.if.org Git - icinga2/commitdiff
Fix wrong vars changed handler in api events
authorMichael Friedrich <michael.friedrich@netways.de>
Thu, 2 Jul 2015 12:51:47 +0000 (14:51 +0200)
committerMichael Friedrich <michael.friedrich@netways.de>
Thu, 2 Jul 2015 12:51:47 +0000 (14:51 +0200)
fixes #9547

lib/icinga/apievents.cpp

index fb6904af8e3ea94ef2bbbd7c98a57ca782cde620..d56592477279132c2c11ede5d81db9d904e0b050 100644 (file)
@@ -1239,6 +1239,14 @@ void ApiEvents::VarsChangedHandler(const CustomVarObject::Ptr& object, const Dic
 
        Dictionary::Ptr params = new Dictionary();
        params->Set("object", object->GetName());
+
+       DynamicType::Ptr dtype = object->GetType();
+       ASSERT(dtype);
+
+       params->Set("object_type", dtype->GetName());
+       Log(LogDebug, "ApiEvents")
+           << "Changed vars handler for object name: '" << object->GetName() << "' type: '" << dtype->GetName() << "'.";
+
        params->Set("vars", Serialize(vars));
 
        Dictionary::Ptr message = new Dictionary();
@@ -1263,27 +1271,43 @@ Value ApiEvents::VarsChangedAPIHandler(const MessageOrigin& origin, const Dictio
                return Empty;
 
        String objectName = params->Get("object");
+       String objectType = params->Get("object_type");
 
        if (objectName.IsEmpty())
                return Empty;
 
-       /* ugly, but there is no other way currently */
-       CustomVarObject::Ptr object = Host::GetByName(objectName);
-       if (!object)
-               object = Service::GetByName(objectName);
-       if (!object)
-               object = User::GetByName(objectName);
-       if (!object)
-               object = Service::GetByName(objectName);
-       if (!object)
-               object = EventCommand::GetByName(objectName);
-       if (!object)
-               object = CheckCommand::GetByName(objectName);
-       if (!object)
-               object = NotificationCommand::GetByName(objectName);
+       CustomVarObject::Ptr object;
+
+       if (objectType.IsEmpty()) {
+               /* keep the old broken way for compatibility reasons for <= v2.3.5 */
+               object = Host::GetByName(objectName);
+               if (!object)
+                       object = Service::GetByName(objectName);
+               if (!object)
+                       object = User::GetByName(objectName);
+               if (!object)
+                       object = Service::GetByName(objectName);
+               if (!object)
+                       object = EventCommand::GetByName(objectName);
+               if (!object)
+                       object = CheckCommand::GetByName(objectName);
+               if (!object)
+                       object = NotificationCommand::GetByName(objectName);
+       } else {
+               DynamicType::Ptr dtype = DynamicType::GetByName(objectType);
+
+               if (!dtype)
+                       return Empty;
+
+               object = dynamic_pointer_cast<CustomVarObject>(dtype->GetObject(objectName));
+       }
+
        if (!object)
                return Empty;
 
+       Log(LogDebug, "ApiEvents")
+           << "Processing 'vars changed' for object: '" << object->GetName() << "' type: '" << object->GetType()->GetName() << "'.";
+
        if (origin.FromZone && !origin.FromZone->CanAccessObject(object)) {
                Log(LogNotice, "ApiEvents")
                    << "Discarding 'vars changed' message from '" << origin.FromClient->GetIdentity() << "': Unauthorized access.";