*
* @param component The component.
*/
-void Application::RegisterComponent(Component::Ptr component)
+void Application::RegisterComponent(const Component::Ptr& component)
{
m_Components[component->GetName()] = component;
*
* @param component The component.
*/
-void Application::UnregisterComponent(Component::Ptr component)
+void Application::UnregisterComponent(const Component::Ptr& component)
{
string name = component->GetName();
shared_ptr<Component> LoadComponent(const string& path,
const ConfigObject::Ptr& componentConfig);
- void RegisterComponent(shared_ptr<Component> component);
- void UnregisterComponent(shared_ptr<Component> component);
+ void RegisterComponent(const shared_ptr<Component>& component);
+ void UnregisterComponent(const shared_ptr<Component>& component);
shared_ptr<Component> GetComponent(const string& name) const;
void AddComponentSearchDir(const string& componentDirectory);
ConfigObject::TMap::Range range = ConfigObject::GetObjects("service");
for (ConfigObject::TMap::Iterator it = range.first; it != range.second; it++) {
- Service svc(it->second);
+ Service svc = it->second;
CheckTask::Ptr ct = CheckTask::CreateTask(svc);
CheckResult cr = ct->Execute();
}
mgr->UnregisterEndpoint(m_DelegationEndpoint);
}
-void DelegationComponent::NewServiceHandler(const ConfigObject::Ptr& object)
+void DelegationComponent::NewServiceHandler(const Service& object)
{
AssignService(object);
}
-void DelegationComponent::RemovedServiceHandler(const ConfigObject::Ptr& object)
+void DelegationComponent::RemovedServiceHandler(const Service& object)
{
RevokeService(object);
}
-void DelegationComponent::AssignService(const ConfigObject::Ptr& service)
+void DelegationComponent::AssignService(const Service& service)
{
RequestMessage request;
request.SetMethod("checker::AssignService");
MessagePart params;
- params.SetProperty("service", service->GetProperties());
+ params.SetProperty("service", service.GetConfigObject()->GetProperties());
request.SetParams(params);
- Application::Log(LogInformation, "delegation", "Trying to delegate service '" + service->GetName() + "'");
+ Application::Log(LogInformation, "delegation", "Trying to delegate service '" + service.GetName() + "'");
GetEndpointManager()->SendAPIMessage(m_DelegationEndpoint, request,
boost::bind(&DelegationComponent::AssignServiceResponseHandler, this, service, _2, _5));
}
-void DelegationComponent::AssignServiceResponseHandler(const ConfigObject::Ptr& service, const Endpoint::Ptr& sender, bool timedOut)
+void DelegationComponent::AssignServiceResponseHandler(Service& service, const Endpoint::Ptr& sender, bool timedOut)
{
if (timedOut) {
- Application::Log(LogInformation, "delegation", "Service delegation for service '" + service->GetName() + "' timed out.");
+ Application::Log(LogInformation, "delegation", "Service delegation for service '" + service.GetName() + "' timed out.");
} else {
- service->SetTag("checker", sender->GetIdentity());
- Application::Log(LogInformation, "delegation", "Service delegation for service '" + service->GetName() + "' was successful.");
+ service.SetChecker(sender->GetIdentity());
+ Application::Log(LogInformation, "delegation", "Service delegation for service '" + service.GetName() + "' was successful.");
}
}
-void DelegationComponent::RevokeService(const ConfigObject::Ptr& service)
+void DelegationComponent::RevokeService(const Service& service)
{
}
-void DelegationComponent::RevokeServiceResponseHandler(const ConfigObject::Ptr& service, const Endpoint::Ptr& sender, bool timedOut)
+void DelegationComponent::RevokeServiceResponseHandler(Service& service, const Endpoint::Ptr& sender, bool timedOut)
{
}
{
ConfigObject::Set::Iterator it;
for (it = m_AllServices->Begin(); it != m_AllServices->End(); it++) {
- ConfigObject::Ptr object = *it;
+ Service service = *it;
- string checker;
- if (object->GetTag("checker", &checker) && GetEndpointManager()->GetEndpointByIdentity(checker))
+ string checker = service.GetChecker();
+ if (!checker.empty() && GetEndpointManager()->GetEndpointByIdentity(checker))
continue;
- AssignService(object);
+ AssignService(service);
}
}
ConfigObject::Set::Ptr m_AllServices;
Timer::Ptr m_DelegationTimer;
- void NewServiceHandler(const ConfigObject::Ptr& object);
- void RemovedServiceHandler(const ConfigObject::Ptr& object);
+ void NewServiceHandler(const Service& object);
+ void RemovedServiceHandler(const Service& object);
- void AssignServiceResponseHandler(const ConfigObject::Ptr& service, const Endpoint::Ptr& sender, bool timedOut);
- void RevokeServiceResponseHandler(const ConfigObject::Ptr& service, const Endpoint::Ptr& sender, bool timedOut);
+ void AssignServiceResponseHandler(Service& service, const Endpoint::Ptr& sender, bool timedOut);
+ void RevokeServiceResponseHandler(Service& service, const Endpoint::Ptr& sender, bool timedOut);
void DelegationTimerHandler(void);
- void AssignService(const ConfigObject::Ptr& service);
- void RevokeService(const ConfigObject::Ptr& service);
+ void AssignService(const Service& service);
+ void RevokeService(const Service& service);
};
}
bool IsLocal(void) const;
-protected:
ConfigObject::Ptr GetConfigObject() const;
private:
using namespace icinga;
-string MacroProcessor::ResolveMacros(string str, Dictionary::Ptr macros)
+string MacroProcessor::ResolveMacros(const string& str, const Dictionary::Ptr& macros)
{
string::size_type offset, pos_first, pos_second;
offset = 0;
- while ((pos_first = str.find_first_of('$', offset)) != string::npos) {
- pos_second = str.find_first_of('$', pos_first + 1);
+ string result = str;
+ while ((pos_first = result.find_first_of('$', offset)) != string::npos) {
+ pos_second = result.find_first_of('$', pos_first + 1);
if (pos_second == string::npos)
throw runtime_error("Closing $ not found in macro format string.");
- string name = str.substr(pos_first + 1, pos_second - pos_first - 1);
+ string name = result.substr(pos_first + 1, pos_second - pos_first - 1);
string value;
if (!macros || !macros->GetProperty(name, &value))
throw runtime_error("Macro '" + name + "' is not defined.");
- str.replace(pos_first, pos_second - pos_first + 1, value);
+ result.replace(pos_first, pos_second - pos_first + 1, value);
offset = pos_first + value.size();
}
- return str;
+ return result;
}
class I2_ICINGA_API MacroProcessor
{
public:
- static string ResolveMacros(string str, Dictionary::Ptr macros);
+ static string ResolveMacros(const string& str, const Dictionary::Ptr& macros);
};
}
GetConfigObject()->GetTag("next_check", &value);
return value;
}
+
+void Service::SetChecker(string checker)
+{
+ GetConfigObject()->SetTag("checker", checker);
+}
+
+string Service::GetChecker(void) const
+{
+ string value;
+ GetConfigObject()->GetTag("checker", &value);
+ return value;
+}
void SetNextCheck(time_t nextCheck);
time_t GetNextCheck(void) const;
+ void SetChecker(string checker);
+ string GetChecker(void) const;
};
}
-#endif /* SERVICE_H */
\ No newline at end of file
+#endif /* SERVICE_H */