mirror of https://github.com/Icinga/icinga2.git
Use adapters in the checker/delegation components.
This commit is contained in:
parent
7d630249cc
commit
728f72dcce
|
@ -248,7 +248,7 @@ Component::Ptr Application::LoadComponent(const string& path,
|
||||||
*
|
*
|
||||||
* @param component The component.
|
* @param component The component.
|
||||||
*/
|
*/
|
||||||
void Application::RegisterComponent(Component::Ptr component)
|
void Application::RegisterComponent(const Component::Ptr& component)
|
||||||
{
|
{
|
||||||
m_Components[component->GetName()] = component;
|
m_Components[component->GetName()] = component;
|
||||||
|
|
||||||
|
@ -260,7 +260,7 @@ void Application::RegisterComponent(Component::Ptr component)
|
||||||
*
|
*
|
||||||
* @param component The component.
|
* @param component The component.
|
||||||
*/
|
*/
|
||||||
void Application::UnregisterComponent(Component::Ptr component)
|
void Application::UnregisterComponent(const Component::Ptr& component)
|
||||||
{
|
{
|
||||||
string name = component->GetName();
|
string name = component->GetName();
|
||||||
|
|
||||||
|
|
|
@ -57,8 +57,8 @@ public:
|
||||||
|
|
||||||
shared_ptr<Component> LoadComponent(const string& path,
|
shared_ptr<Component> LoadComponent(const string& path,
|
||||||
const ConfigObject::Ptr& componentConfig);
|
const ConfigObject::Ptr& componentConfig);
|
||||||
void RegisterComponent(shared_ptr<Component> component);
|
void RegisterComponent(const shared_ptr<Component>& component);
|
||||||
void UnregisterComponent(shared_ptr<Component> component);
|
void UnregisterComponent(const shared_ptr<Component>& component);
|
||||||
shared_ptr<Component> GetComponent(const string& name) const;
|
shared_ptr<Component> GetComponent(const string& name) const;
|
||||||
void AddComponentSearchDir(const string& componentDirectory);
|
void AddComponentSearchDir(const string& componentDirectory);
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,7 @@ void CheckerComponent::Start(void)
|
||||||
ConfigObject::TMap::Range range = ConfigObject::GetObjects("service");
|
ConfigObject::TMap::Range range = ConfigObject::GetObjects("service");
|
||||||
|
|
||||||
for (ConfigObject::TMap::Iterator it = range.first; it != range.second; it++) {
|
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);
|
CheckTask::Ptr ct = CheckTask::CreateTask(svc);
|
||||||
CheckResult cr = ct->Execute();
|
CheckResult cr = ct->Execute();
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,47 +53,47 @@ void DelegationComponent::Stop(void)
|
||||||
mgr->UnregisterEndpoint(m_DelegationEndpoint);
|
mgr->UnregisterEndpoint(m_DelegationEndpoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DelegationComponent::NewServiceHandler(const ConfigObject::Ptr& object)
|
void DelegationComponent::NewServiceHandler(const Service& object)
|
||||||
{
|
{
|
||||||
AssignService(object);
|
AssignService(object);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DelegationComponent::RemovedServiceHandler(const ConfigObject::Ptr& object)
|
void DelegationComponent::RemovedServiceHandler(const Service& object)
|
||||||
{
|
{
|
||||||
RevokeService(object);
|
RevokeService(object);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DelegationComponent::AssignService(const ConfigObject::Ptr& service)
|
void DelegationComponent::AssignService(const Service& service)
|
||||||
{
|
{
|
||||||
RequestMessage request;
|
RequestMessage request;
|
||||||
request.SetMethod("checker::AssignService");
|
request.SetMethod("checker::AssignService");
|
||||||
|
|
||||||
MessagePart params;
|
MessagePart params;
|
||||||
params.SetProperty("service", service->GetProperties());
|
params.SetProperty("service", service.GetConfigObject()->GetProperties());
|
||||||
request.SetParams(params);
|
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,
|
GetEndpointManager()->SendAPIMessage(m_DelegationEndpoint, request,
|
||||||
boost::bind(&DelegationComponent::AssignServiceResponseHandler, this, service, _2, _5));
|
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) {
|
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 {
|
} else {
|
||||||
service->SetTag("checker", sender->GetIdentity());
|
service.SetChecker(sender->GetIdentity());
|
||||||
Application::Log(LogInformation, "delegation", "Service delegation for service '" + service->GetName() + "' was successful.");
|
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;
|
ConfigObject::Set::Iterator it;
|
||||||
for (it = m_AllServices->Begin(); it != m_AllServices->End(); it++) {
|
for (it = m_AllServices->Begin(); it != m_AllServices->End(); it++) {
|
||||||
ConfigObject::Ptr object = *it;
|
Service service = *it;
|
||||||
|
|
||||||
string checker;
|
string checker = service.GetChecker();
|
||||||
if (object->GetTag("checker", &checker) && GetEndpointManager()->GetEndpointByIdentity(checker))
|
if (!checker.empty() && GetEndpointManager()->GetEndpointByIdentity(checker))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
AssignService(object);
|
AssignService(service);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,16 +38,16 @@ private:
|
||||||
ConfigObject::Set::Ptr m_AllServices;
|
ConfigObject::Set::Ptr m_AllServices;
|
||||||
Timer::Ptr m_DelegationTimer;
|
Timer::Ptr m_DelegationTimer;
|
||||||
|
|
||||||
void NewServiceHandler(const ConfigObject::Ptr& object);
|
void NewServiceHandler(const Service& object);
|
||||||
void RemovedServiceHandler(const ConfigObject::Ptr& object);
|
void RemovedServiceHandler(const Service& object);
|
||||||
|
|
||||||
void AssignServiceResponseHandler(const ConfigObject::Ptr& service, const Endpoint::Ptr& sender, bool timedOut);
|
void AssignServiceResponseHandler(Service& service, const Endpoint::Ptr& sender, bool timedOut);
|
||||||
void RevokeServiceResponseHandler(const ConfigObject::Ptr& service, const Endpoint::Ptr& sender, bool timedOut);
|
void RevokeServiceResponseHandler(Service& service, const Endpoint::Ptr& sender, bool timedOut);
|
||||||
|
|
||||||
void DelegationTimerHandler(void);
|
void DelegationTimerHandler(void);
|
||||||
|
|
||||||
void AssignService(const ConfigObject::Ptr& service);
|
void AssignService(const Service& service);
|
||||||
void RevokeService(const ConfigObject::Ptr& service);
|
void RevokeService(const Service& service);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,6 @@ public:
|
||||||
|
|
||||||
bool IsLocal(void) const;
|
bool IsLocal(void) const;
|
||||||
|
|
||||||
protected:
|
|
||||||
ConfigObject::Ptr GetConfigObject() const;
|
ConfigObject::Ptr GetConfigObject() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -2,27 +2,28 @@
|
||||||
|
|
||||||
using namespace icinga;
|
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;
|
string::size_type offset, pos_first, pos_second;
|
||||||
|
|
||||||
offset = 0;
|
offset = 0;
|
||||||
|
|
||||||
while ((pos_first = str.find_first_of('$', offset)) != string::npos) {
|
string result = str;
|
||||||
pos_second = str.find_first_of('$', pos_first + 1);
|
while ((pos_first = result.find_first_of('$', offset)) != string::npos) {
|
||||||
|
pos_second = result.find_first_of('$', pos_first + 1);
|
||||||
|
|
||||||
if (pos_second == string::npos)
|
if (pos_second == string::npos)
|
||||||
throw runtime_error("Closing $ not found in macro format string.");
|
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;
|
string value;
|
||||||
if (!macros || !macros->GetProperty(name, &value))
|
if (!macros || !macros->GetProperty(name, &value))
|
||||||
throw runtime_error("Macro '" + name + "' is not defined.");
|
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();
|
offset = pos_first + value.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
return str;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ namespace icinga
|
||||||
class I2_ICINGA_API MacroProcessor
|
class I2_ICINGA_API MacroProcessor
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static string ResolveMacros(string str, Dictionary::Ptr macros);
|
static string ResolveMacros(const string& str, const Dictionary::Ptr& macros);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,3 +74,15 @@ time_t Service::GetNextCheck(void) const
|
||||||
GetConfigObject()->GetTag("next_check", &value);
|
GetConfigObject()->GetTag("next_check", &value);
|
||||||
return 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;
|
||||||
|
}
|
||||||
|
|
|
@ -22,6 +22,8 @@ public:
|
||||||
|
|
||||||
void SetNextCheck(time_t nextCheck);
|
void SetNextCheck(time_t nextCheck);
|
||||||
time_t GetNextCheck(void) const;
|
time_t GetNextCheck(void) const;
|
||||||
|
void SetChecker(string checker);
|
||||||
|
string GetChecker(void) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue