diff --git a/base/application.cpp b/base/application.cpp index 4ffe0e4f0..070d0b40a 100644 --- a/base/application.cpp +++ b/base/application.cpp @@ -248,7 +248,7 @@ Component::Ptr Application::LoadComponent(const string& path, * * @param component The component. */ -void Application::RegisterComponent(Component::Ptr component) +void Application::RegisterComponent(const Component::Ptr& component) { m_Components[component->GetName()] = component; @@ -260,7 +260,7 @@ void Application::RegisterComponent(Component::Ptr component) * * @param component The component. */ -void Application::UnregisterComponent(Component::Ptr component) +void Application::UnregisterComponent(const Component::Ptr& component) { string name = component->GetName(); diff --git a/base/application.h b/base/application.h index 56383b049..47ff8465a 100644 --- a/base/application.h +++ b/base/application.h @@ -57,8 +57,8 @@ public: shared_ptr LoadComponent(const string& path, const ConfigObject::Ptr& componentConfig); - void RegisterComponent(shared_ptr component); - void UnregisterComponent(shared_ptr component); + void RegisterComponent(const shared_ptr& component); + void UnregisterComponent(const shared_ptr& component); shared_ptr GetComponent(const string& name) const; void AddComponentSearchDir(const string& componentDirectory); diff --git a/components/checker/checkercomponent.cpp b/components/checker/checkercomponent.cpp index 97b8f4883..6b6ae3529 100644 --- a/components/checker/checkercomponent.cpp +++ b/components/checker/checkercomponent.cpp @@ -48,7 +48,7 @@ void CheckerComponent::Start(void) 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(); } diff --git a/components/delegation/delegationcomponent.cpp b/components/delegation/delegationcomponent.cpp index 0a27018c3..f2a9de172 100644 --- a/components/delegation/delegationcomponent.cpp +++ b/components/delegation/delegationcomponent.cpp @@ -53,47 +53,47 @@ void DelegationComponent::Stop(void) 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) { } @@ -101,13 +101,13 @@ void DelegationComponent::DelegationTimerHandler(void) { 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); } } diff --git a/components/delegation/delegationcomponent.h b/components/delegation/delegationcomponent.h index d665fac73..d2559538b 100644 --- a/components/delegation/delegationcomponent.h +++ b/components/delegation/delegationcomponent.h @@ -38,16 +38,16 @@ private: 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); }; } diff --git a/icinga/configobjectadapter.h b/icinga/configobjectadapter.h index 4ad327ddd..b3cb41a93 100644 --- a/icinga/configobjectadapter.h +++ b/icinga/configobjectadapter.h @@ -16,7 +16,6 @@ public: bool IsLocal(void) const; -protected: ConfigObject::Ptr GetConfigObject() const; private: diff --git a/icinga/macroprocessor.cpp b/icinga/macroprocessor.cpp index e5dca2506..291161e78 100644 --- a/icinga/macroprocessor.cpp +++ b/icinga/macroprocessor.cpp @@ -2,27 +2,28 @@ 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; } diff --git a/icinga/macroprocessor.h b/icinga/macroprocessor.h index 3af0c1555..2bf5bc7f9 100644 --- a/icinga/macroprocessor.h +++ b/icinga/macroprocessor.h @@ -7,7 +7,7 @@ namespace icinga class I2_ICINGA_API MacroProcessor { public: - static string ResolveMacros(string str, Dictionary::Ptr macros); + static string ResolveMacros(const string& str, const Dictionary::Ptr& macros); }; } diff --git a/icinga/service.cpp b/icinga/service.cpp index 6e8b606d7..e60198673 100644 --- a/icinga/service.cpp +++ b/icinga/service.cpp @@ -74,3 +74,15 @@ time_t Service::GetNextCheck(void) const 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; +} diff --git a/icinga/service.h b/icinga/service.h index 4257ec764..a2680dea4 100644 --- a/icinga/service.h +++ b/icinga/service.h @@ -22,8 +22,10 @@ public: 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 */