From 146880c110c391c2ee0a72b3509d1752b42133ad Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Thu, 14 Jun 2012 16:31:38 +0200 Subject: [PATCH] Added log messages, fixed config. --- components/checker/checkercomponent.cpp | 1 + components/delegation/delegationcomponent.cpp | 21 +++++++++++++++++++ components/delegation/delegationcomponent.h | 3 +++ icinga-app/icinga2.conf | 4 ++-- icinga-app/icinga3.conf | 2 +- icinga/nagioschecktask.cpp | 4 ++++ 6 files changed, 32 insertions(+), 3 deletions(-) diff --git a/components/checker/checkercomponent.cpp b/components/checker/checkercomponent.cpp index 3b451efca..c65cb6ba7 100644 --- a/components/checker/checkercomponent.cpp +++ b/components/checker/checkercomponent.cpp @@ -87,6 +87,7 @@ int CheckerComponent::CheckTimerHandler(const TimerEventArgs& ea) break; CheckTask::Ptr ct = CheckTask::CreateTask(service); + Application::Log("Executing service check for '" + service.GetName() + "'"); CheckResult cr = ct->Execute(); m_Services.pop(); diff --git a/components/delegation/delegationcomponent.cpp b/components/delegation/delegationcomponent.cpp index 4bb7cf2ab..cbce44c3f 100644 --- a/components/delegation/delegationcomponent.cpp +++ b/components/delegation/delegationcomponent.cpp @@ -34,6 +34,11 @@ void DelegationComponent::Start(void) m_AllServices->OnObjectRemoved.connect(bind(&DelegationComponent::RemovedServiceHandler, this, _1)); m_AllServices->Start(); + m_DelegationTimer = make_shared(); + m_DelegationTimer->SetInterval(30); + m_DelegationTimer->OnTimerExpired.connect(bind(&DelegationComponent::DelegationTimerHandler, this, _1)); + m_DelegationTimer->Start(); + m_DelegationEndpoint = make_shared(); m_DelegationEndpoint->RegisterPublication("checker::AssignService"); m_DelegationEndpoint->RegisterPublication("checker::RevokeService"); @@ -95,6 +100,22 @@ int DelegationComponent::RevokeServiceResponseHandler(const NewResponseEventArgs return 0; } +int DelegationComponent::DelegationTimerHandler(const TimerEventArgs& ea) +{ + ConfigObject::Set::Iterator it; + for (it = m_AllServices->Begin(); it != m_AllServices->End(); it++) { + ConfigObject::Ptr object = *it; + + string checker; + if (object->GetTag("checker", &checker) && GetEndpointManager()->GetEndpointByIdentity(checker)) + continue; + + AssignService(object); + } + + return 0; +} + int DelegationComponent::TestResponseHandler(const NewResponseEventArgs& ea) { Application::Log("Response handler called."); diff --git a/components/delegation/delegationcomponent.h b/components/delegation/delegationcomponent.h index ade9183b3..b4221b28e 100644 --- a/components/delegation/delegationcomponent.h +++ b/components/delegation/delegationcomponent.h @@ -36,6 +36,7 @@ public: private: VirtualEndpoint::Ptr m_DelegationEndpoint; ConfigObject::Set::Ptr m_AllServices; + Timer::Ptr m_DelegationTimer; int NewServiceHandler(const ObjectSetEventArgs& ea); int RemovedServiceHandler(const ObjectSetEventArgs& ea); @@ -43,6 +44,8 @@ private: int AssignServiceResponseHandler(const ConfigObject::Ptr& service, const NewResponseEventArgs& nrea); int RevokeServiceResponseHandler(const NewResponseEventArgs& nrea); + int DelegationTimerHandler(const TimerEventArgs& ea); + void AssignService(const ConfigObject::Ptr& service); void RevokeService(const ConfigObject::Ptr& service); diff --git a/icinga-app/icinga2.conf b/icinga-app/icinga2.conf index 88871008d..979764daf 100644 --- a/icinga-app/icinga2.conf +++ b/icinga-app/icinga2.conf @@ -4,7 +4,7 @@ local object application "icinga" { cakey = "ca.crt", node = "192.168.2.235", - service = 8888 + service = 7777 } local object component "configrpc" { @@ -19,7 +19,7 @@ local object component "discovery" { local object endpoint "icinga-c3" { node = "192.168.5.46", - service = 7777, + service = 9999, roles = { "all" } } diff --git a/icinga-app/icinga3.conf b/icinga-app/icinga3.conf index 0611a73af..26042a03f 100644 --- a/icinga-app/icinga3.conf +++ b/icinga-app/icinga3.conf @@ -1,5 +1,5 @@ local object application "icinga" { - privkey = "icinga-c3".key", + privkey = "icinga-c3.key", pubkey = "icinga-c3.crt", cakey = "ca.crt", diff --git a/icinga/nagioschecktask.cpp b/icinga/nagioschecktask.cpp index dc2f3a08a..f6adac5b1 100644 --- a/icinga/nagioschecktask.cpp +++ b/icinga/nagioschecktask.cpp @@ -17,6 +17,8 @@ CheckResult NagiosCheckTask::Execute(void) const string command = m_Command + " 2>&1"; + Application::Log("Nagios check command: " + command); + #ifdef _MSC_VER fp = _popen(command.c_str(), "r"); #else /* _MSC_VER */ @@ -37,6 +39,8 @@ CheckResult NagiosCheckTask::Execute(void) const cr.Output = output.str(); + Application::Log("Nagios plugin output: " + cr.Output); + int status, exitcode; #ifdef _MSC_VER status = _pclose(fp);