return msg;
}
+bool ConfigRpcComponent::ShouldReplicateObject(const ConfigObject::Ptr& object)
+{
+ long replicate;
+ if (!object->GetPropertyInteger("replicate", &replicate))
+ return false;
+ return (replicate != 0);
+}
+
int ConfigRpcComponent::FetchObjectsHandler(const NewRequestEventArgs& ea)
{
Endpoint::Ptr client = ea.Sender;
ConfigCollection::Ptr collection = ci->second;
for (ConfigCollection::ObjectIterator oi = collection->Objects.begin(); oi != collection->Objects.end(); oi++) {
- client->ProcessRequest(m_ConfigRpcEndpoint, MakeObjectMessage(oi->second, "config::ObjectCreated", true));
+ ConfigObject::Ptr object = oi->second;
+
+ if (!ShouldReplicateObject(object))
+ continue;
+
+ client->ProcessRequest(m_ConfigRpcEndpoint, MakeObjectMessage(object, "config::ObjectCreated", true));
}
}
{
ConfigObject::Ptr object = static_pointer_cast<ConfigObject>(ea.Source);
- long replicate = 0;
- object->GetPropertyInteger("replicate", &replicate);
+ if (!ShouldReplicateObject(object))
+ return 0;
- if (replicate) {
- EndpointManager::Ptr mgr = GetIcingaApplication()->GetEndpointManager();
- mgr->SendMulticastRequest(m_ConfigRpcEndpoint, MakeObjectMessage(object, "config::ObjectCreated", true));
- }
+ EndpointManager::Ptr mgr = GetIcingaApplication()->GetEndpointManager();
+ mgr->SendMulticastRequest(m_ConfigRpcEndpoint, MakeObjectMessage(object, "config::ObjectCreated", true));
return 0;
}
{
ConfigObject::Ptr object = static_pointer_cast<ConfigObject>(ea.Source);
- long replicate = 0;
- object->GetPropertyInteger("replicate", &replicate);
+ if (!ShouldReplicateObject(object))
+ return 0;
- if (replicate) {
- EndpointManager::Ptr mgr = GetIcingaApplication()->GetEndpointManager();
- mgr->SendMulticastRequest(m_ConfigRpcEndpoint, MakeObjectMessage(object, "config::ObjectRemoved", false));
- }
+ EndpointManager::Ptr mgr = GetIcingaApplication()->GetEndpointManager();
+ mgr->SendMulticastRequest(m_ConfigRpcEndpoint, MakeObjectMessage(object, "config::ObjectRemoved", false));
return 0;
}
{
ConfigObject::Ptr object = static_pointer_cast<ConfigObject>(ea.Source);
- long replicate = 0;
- object->GetPropertyInteger("replicate", &replicate);
+ if (!ShouldReplicateObject(object))
+ return 0;
- if (replicate) {
- JsonRpcRequest msg = MakeObjectMessage(object, "config::PropertyChanged", false);
- Message params;
- msg.SetParams(params);
+ JsonRpcRequest msg = MakeObjectMessage(object, "config::PropertyChanged", false);
+ Message params;
+ msg.SetParams(params);
- Message properties;
- params.GetDictionary()->SetPropertyDictionary("properties", properties.GetDictionary());
+ Message properties;
+ params.GetDictionary()->SetPropertyDictionary("properties", properties.GetDictionary());
- string value;
- if (!object->GetPropertyString(ea.Property, &value))
- return 0;
+ string value;
+ if (!object->GetPropertyString(ea.Property, &value))
+ return 0;
- properties.GetDictionary()->SetPropertyString(ea.Property, value);
+ properties.GetDictionary()->SetPropertyString(ea.Property, value);
- EndpointManager::Ptr mgr = GetIcingaApplication()->GetEndpointManager();
- mgr->SendMulticastRequest(m_ConfigRpcEndpoint, msg);
- }
+ EndpointManager::Ptr mgr = GetIcingaApplication()->GetEndpointManager();
+ mgr->SendMulticastRequest(m_ConfigRpcEndpoint, msg);
return 0;
}
object->SetPropertyString(i->first, i->second);
}
- if (was_null)
+ if (was_null) {
+ object->SetReplicated(true);
configHive->AddObject(object);
+ }
return 0;
}
if (!object)
return 0;
- configHive->RemoveObject(object);
+ if (object->GetReplicated())
+ configHive->RemoveObject(object);
return 0;
}
string path;
ConfigObject::Ptr object = static_pointer_cast<ConfigObject>(ea.Source);
+ /* don't allow replicated config objects */
+ if (object->GetReplicated())
+ return 0;
+
if (!object->GetPropertyString("path", &path)) {
#ifdef _WIN32
path = object->GetName() + ".dll";
#else /* _WIN32 */
path = object->GetName() + ".la";
#endif /* _WIN32 */
-
- // TODO: try to figure out where the component is located */
}
LoadComponent(path, object);
int IcingaApplication::DeletedComponentHandler(const EventArgs& ea)
{
ConfigObject::Ptr object = static_pointer_cast<ConfigObject>(ea.Source);
+
Component::Ptr component = GetComponent(object->GetName());
UnregisterComponent(component);
long portValue;
unsigned short port;
+ /* don't allow replicated config objects */
+ if (object->GetReplicated())
+ return 0;
+
if (!object->GetPropertyInteger("port", &portValue))
throw InvalidArgumentException("Parameter 'port' is required for 'rpclistener' objects.");
long portValue;
unsigned short port;
+ /* don't allow replicated config objects */
+ if (object->GetReplicated())
+ return 0;
+
if (!object->GetPropertyString("hostname", &hostname))
throw InvalidArgumentException("Parameter 'hostname' is required for 'rpcconnection' objects.");