diff --git a/cib/Makefile.am b/cib/Makefile.am index 2be3dae88..3990fea46 100644 --- a/cib/Makefile.am +++ b/cib/Makefile.am @@ -6,6 +6,8 @@ pkglib_LTLIBRARIES = \ libcib_la_SOURCES = \ checkresult.cpp \ checkresult.h \ + checkresultmessage.cpp \ + checkresultmessage.h \ cib.cpp \ cib.h \ configobjectadapter.cpp \ @@ -24,9 +26,7 @@ libcib_la_SOURCES = \ service.cpp \ service.h \ servicegroup.cpp \ - servicegroup.h \ - servicestatusmessage.cpp \ - servicestatusmessage.h + servicegroup.h libcib_la_CPPFLAGS = \ -DI2_CIB_BUILD \ diff --git a/cib/servicestatusmessage.cpp b/cib/checkresultmessage.cpp similarity index 66% rename from cib/servicestatusmessage.cpp rename to cib/checkresultmessage.cpp index 3b0e95adb..d48b9dc6d 100644 --- a/cib/servicestatusmessage.cpp +++ b/cib/checkresultmessage.cpp @@ -21,47 +21,17 @@ using namespace icinga; -bool ServiceStatusMessage::GetService(string *service) const +bool CheckResultMessage::GetService(string *service) const { return Get("service", service); } -void ServiceStatusMessage::SetService(const string& service) +void CheckResultMessage::SetService(const string& service) { Set("service", service); } -bool ServiceStatusMessage::GetState(ServiceState *state) const -{ - long value; - if (Get("state", &value)) { - *state = static_cast(value); - return true; - } - return false; -} - -void ServiceStatusMessage::SetState(ServiceState state) -{ - Set("state", static_cast(state)); -} - -bool ServiceStatusMessage::GetStateType(ServiceStateType *type) const -{ - long value; - if (Get("state_type", &value)) { - *type = static_cast(value); - return true; - } - return false; -} - -void ServiceStatusMessage::SetStateType(ServiceStateType type) -{ - Set("state_type", static_cast(type)); -} - -bool ServiceStatusMessage::GetCheckResult(CheckResult *cr) const +bool CheckResultMessage::GetCheckResult(CheckResult *cr) const { Dictionary::Ptr obj; if (Get("result", &obj)) { @@ -71,7 +41,7 @@ bool ServiceStatusMessage::GetCheckResult(CheckResult *cr) const return false; } -void ServiceStatusMessage::SetCheckResult(CheckResult cr) +void CheckResultMessage::SetCheckResult(CheckResult cr) { Set("result", cr.GetDictionary()); } diff --git a/cib/servicestatusmessage.h b/cib/checkresultmessage.h similarity index 84% rename from cib/servicestatusmessage.h rename to cib/checkresultmessage.h index 6d67d1d3b..9dfd7041e 100644 --- a/cib/servicestatusmessage.h +++ b/cib/checkresultmessage.h @@ -17,13 +17,13 @@ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * ******************************************************************************/ -#ifndef SERVICESTATUSMESSAGE_H -#define SERVICESTATUSMESSAGE_H +#ifndef CHECKRESULTMESSAGE_H +#define CHECKRESULTMESSAGE_H namespace icinga { -class I2_CIB_API ServiceStatusMessage : public MessagePart +class I2_CIB_API CheckResultMessage : public MessagePart { public: ServiceStatusMessage(void) : MessagePart() { } @@ -32,16 +32,10 @@ public: bool GetService(string *service) const; void SetService(const string& service); - bool GetState(ServiceState *state) const; - void SetState(ServiceState state); - - bool GetStateType(ServiceStateType *type) const; - void SetStateType(ServiceStateType type); - bool GetCheckResult(CheckResult *cr) const; void SetCheckResult(CheckResult cr); }; } -#endif /* SERVICESTATUSMESSAGE_H */ +#endif /* CHECKRESULTMESSAGE_H */ diff --git a/cib/cib.cpp b/cib/cib.cpp index 7c668ce32..c4ee26f2b 100644 --- a/cib/cib.cpp +++ b/cib/cib.cpp @@ -22,7 +22,7 @@ using namespace icinga; RingBuffer CIB::m_TaskStatistics(15 * 60); -boost::signal CIB::OnServiceStatusUpdate; +boost::signal CIB::OnCheckResultReceived; void CIB::UpdateTaskStatistics(long tv, int num) { diff --git a/cib/cib.h b/cib/cib.h index 98a5db52d..f371153d8 100644 --- a/cib/cib.h +++ b/cib/cib.h @@ -29,7 +29,7 @@ public: static void UpdateTaskStatistics(long tv, int num); static int GetTaskStatistics(long timespan); - static boost::signal OnServiceStatusUpdate; + static boost::signal OnCheckResultReceived; private: static RingBuffer m_TaskStatistics; diff --git a/cib/cib.vcxproj b/cib/cib.vcxproj index 3b5f858f8..962c26a6a 100644 --- a/cib/cib.vcxproj +++ b/cib/cib.vcxproj @@ -93,7 +93,7 @@ - + @@ -110,9 +110,9 @@ - + - \ No newline at end of file + diff --git a/cib/cib.vcxproj.filters b/cib/cib.vcxproj.filters index 81e391f32..bd8105397 100644 --- a/cib/cib.vcxproj.filters +++ b/cib/cib.vcxproj.filters @@ -41,7 +41,7 @@ Headerdateien - + Headerdateien @@ -76,7 +76,7 @@ Quelldateien - + Quelldateien @@ -86,4 +86,4 @@ Quelldateien - \ No newline at end of file + diff --git a/cib/i2-cib.h b/cib/i2-cib.h index 60525b9fb..956694d98 100644 --- a/cib/i2-cib.h +++ b/cib/i2-cib.h @@ -47,7 +47,7 @@ #include "nagioschecktask.h" #include "nullchecktask.h" -#include "servicestatusmessage.h" +#include "checkresultmessage.h" #include "cib.h" diff --git a/components/checker/checkercomponent.cpp b/components/checker/checkercomponent.cpp index 24a437231..2e17707b7 100644 --- a/components/checker/checkercomponent.cpp +++ b/components/checker/checkercomponent.cpp @@ -110,7 +110,7 @@ void CheckerComponent::CheckCompletedHandler(Service service, const ScriptTask:: RequestMessage rm; rm.SetMethod("checker::CheckResult"); - ServiceStatusMessage params; + CheckResultMessage params; params.SetService(service.GetName()); params.SetCheckResult(result); diff --git a/components/cibsync/cibsynccomponent.cpp b/components/cibsync/cibsynccomponent.cpp index a3df2adea..59b550957 100644 --- a/components/cibsync/cibsynccomponent.cpp +++ b/components/cibsync/cibsynccomponent.cpp @@ -60,8 +60,8 @@ void CIBSyncComponent::Start(void) boost::bind(&CIBSyncComponent::RemoteObjectRemovedHandler, this, _3)); /* service status */ - m_Endpoint->RegisterTopicHandler("delegation::ServiceStatus", - boost::bind(&CIBSyncComponent::ServiceStatusRequestHandler, _2, _3)); + m_Endpoint->RegisterTopicHandler("checker::CheckResult", + boost::bind(&CIBSyncComponent::CheckResultRequestHandler, _2, _3)); EndpointManager::GetInstance()->RegisterEndpoint(m_Endpoint); } @@ -77,14 +77,12 @@ void CIBSyncComponent::Stop(void) endpointManager->UnregisterEndpoint(m_Endpoint); } -void CIBSyncComponent::ServiceStatusRequestHandler(const Endpoint::Ptr& sender, const RequestMessage& request) +void CIBSyncComponent::CheckResultRequestHandler(const Endpoint::Ptr& sender, const RequestMessage& request) { - ServiceStatusMessage params; + CheckResultMessage params; if (!request.GetParams(¶ms)) return; - CIB::OnServiceStatusUpdate(params); - string svcname; if (!params.GetService(&svcname)) return; @@ -92,8 +90,11 @@ void CIBSyncComponent::ServiceStatusRequestHandler(const Endpoint::Ptr& sender, Service service = Service::GetByName(svcname); CheckResult cr; - if (params.GetCheckResult(&cr)) - service.ApplyCheckResult(cr); + if (!params.GetCheckResult(&cr)) + return; + + CIB::OnCheckResultReceived(params); + service.ApplyCheckResult(cr); time_t now; time(&now); diff --git a/components/cibsync/cibsynccomponent.h b/components/cibsync/cibsynccomponent.h index 93a95a657..9590b2ac4 100644 --- a/components/cibsync/cibsynccomponent.h +++ b/components/cibsync/cibsynccomponent.h @@ -37,7 +37,7 @@ private: VirtualEndpoint::Ptr m_Endpoint; bool m_SyncingConfig; - static void ServiceStatusRequestHandler(const Endpoint::Ptr& sender, const RequestMessage& request); + static void CheckResultRequestHandler(const Endpoint::Ptr& sender, const RequestMessage& request); void NewEndpointHandler(const Endpoint::Ptr& endpoint); void SessionEstablishedHandler(const Endpoint::Ptr& endpoint); diff --git a/components/delegation/delegationcomponent.cpp b/components/delegation/delegationcomponent.cpp index bb34a24af..f227b0d8d 100644 --- a/components/delegation/delegationcomponent.cpp +++ b/components/delegation/delegationcomponent.cpp @@ -43,8 +43,6 @@ void DelegationComponent::Start(void) m_Endpoint = boost::make_shared(); m_Endpoint->RegisterPublication("checker::AssignService"); m_Endpoint->RegisterPublication("checker::ClearServices"); - m_Endpoint->RegisterTopicHandler("checker::CheckResult", - boost::bind(&DelegationComponent::CheckResultRequestHandler, this, _2, _3)); m_Endpoint->RegisterPublication("delegation::ServiceStatus"); EndpointManager::GetInstance()->RegisterEndpoint(m_Endpoint); @@ -295,27 +293,4 @@ void DelegationComponent::DelegationTimerHandler(void) Logger::Write(LogInformation, "delegation", msgbuf.str()); } -void DelegationComponent::CheckResultRequestHandler(const Endpoint::Ptr& sender, const RequestMessage& request) -{ - ServiceStatusMessage params; - if (!request.GetParams(¶ms)) - return; - - string svcname; - if (!params.GetService(&svcname)) - return; - - Service service = Service::GetByName(svcname); - - /* validate that this is an authentic check result */ - if (!service.IsAllowedChecker(sender->GetIdentity())) - return; - - /* send state update */ - RequestMessage rm; - rm.SetMethod("delegation::ServiceStatus"); - rm.SetParams(params); - EndpointManager::GetInstance()->SendMulticastMessage(m_Endpoint, rm); -} - EXPORT_COMPONENT(delegation, DelegationComponent);