]> granicus.if.org Git - icinga2/commitdiff
Implement Service::OnCheckResultReceived, rename ServiceStateChangeMessage to CheckRe...
authorGunnar Beutner <gunnar.beutner@netways.de>
Thu, 31 Jan 2013 15:49:40 +0000 (16:49 +0100)
committerGunnar Beutner <gunnar.beutner@netways.de>
Thu, 31 Jan 2013 15:51:50 +0000 (16:51 +0100)
Fixes #3597

components/replication/replicationcomponent.cpp
components/replication/replicationcomponent.h
lib/icinga/Makefile.am
lib/icinga/checkresultmessage.cpp [moved from lib/icinga/servicestatechangemessage.cpp with 79% similarity]
lib/icinga/checkresultmessage.h [moved from lib/icinga/servicestatechangemessage.h with 79% similarity]
lib/icinga/i2-icinga.h
lib/icinga/icinga.vcxproj
lib/icinga/service.cpp
lib/icinga/service.h
lib/remoting/messagepart.h

index c3e694fae04ac5346a39d38b3bd49d4dfca044c0..f8cfec823adde9f589d74517e0136c0a7d615151 100644 (file)
@@ -40,8 +40,8 @@ void ReplicationComponent::Start(void)
            boost::bind(&ReplicationComponent::RemoteObjectRemovedHandler, this, _3));
 
        /* service status */
-       m_Endpoint->RegisterTopicHandler("checker::ServiceStateChange",
-           boost::bind(&ReplicationComponent::ServiceStateChangeRequestHandler, _3));
+       m_Endpoint->RegisterTopicHandler("checker::CheckResult",
+           boost::bind(&ReplicationComponent::CheckResultRequestHandler, _3));
 }
 
 /**
@@ -52,42 +52,35 @@ void ReplicationComponent::Stop(void)
        m_Endpoint->Unregister();
 }
 
-void ReplicationComponent::ServiceStateChangeRequestHandler(const RequestMessage& request)
+void ReplicationComponent::CheckResultRequestHandler(const RequestMessage& request)
 {
-       ServiceStateChangeMessage params;
+       CheckResultMessage params;
        if (!request.GetParams(&params))
                return;
 
-       String svcname;
-       if (!params.GetService(&svcname))
-               return;
-
+       String svcname = params.GetService();
        Service::Ptr service = Service::GetByName(svcname);
 
-       //CheckResult cr;
-       //if (!params.GetCheckResult(&cr))
-       //      return;
+       Service::OnCheckResultReceived(service, params);
 
-       //Service::OnCheckResultReceived(service, params);
-       //service->ApplyCheckResult(cr);
+       Dictionary::Ptr cr = params.GetCheckResult();
+       if (!cr)
+               return;
 
-       Dictionary::Ptr cr = service->GetLastCheckResult();
-       if (cr) {
-               Value active = cr->Get("active");
+       Value active = cr->Get("active");
 
-               time_t ts;
-               Value schedule_end = cr->Get("schedule_end");
+       time_t ts;
+       Value schedule_end = cr->Get("schedule_end");
 
-               if (!schedule_end.IsEmpty())
-                       ts = static_cast<time_t>(schedule_end);
-               else
-                       ts = static_cast<time_t>(Utility::GetTime());
+       if (!schedule_end.IsEmpty())
+               ts = static_cast<time_t>(schedule_end);
+       else
+               ts = static_cast<time_t>(Utility::GetTime());
 
-               if (active.IsEmpty() || static_cast<long>(active))
-                       CIB::UpdateActiveChecksStatistics(ts, 1);
-               else
-                       CIB::UpdatePassiveChecksStatistics(ts, 1);
-       }
+       if (active.IsEmpty() || static_cast<long>(active))
+               CIB::UpdateActiveChecksStatistics(ts, 1);
+       else
+               CIB::UpdatePassiveChecksStatistics(ts, 1);
 }
 
 void ReplicationComponent::EndpointConnectedHandler(const Endpoint::Ptr& endpoint)
index 136770d5d0078b66137476e19bd839a9a230d481..d3f1bd712686e3da351abda1676c4955487e907f 100644 (file)
@@ -35,7 +35,7 @@ public:
 private:
        Endpoint::Ptr m_Endpoint;
 
-       static void ServiceStateChangeRequestHandler(const RequestMessage& request);
+       static void CheckResultRequestHandler(const RequestMessage& request);
 
        void EndpointConnectedHandler(const Endpoint::Ptr& endpoint);
 
index 8ef08fc17feb19778e23bf6b65b3157a557ed0c0..3ffcb01430b2e42ee92f55a6d1132dab2c79e7f9 100644 (file)
@@ -6,6 +6,8 @@ pkglib_LTLIBRARIES =  \
 
 libicinga_la_SOURCES =  \
        acknowledgement.h \
+       checkresultmessage.cpp \
+       checkresultmessage.h \
        cib.cpp \
        cib.h \
        commentprocessor.cpp \
@@ -31,8 +33,6 @@ libicinga_la_SOURCES =  \
        servicegroup.cpp \
        servicegroup.h \
        service.h \
-       servicestatechangemessage.cpp \
-       servicestatechangemessage.h \
        timeperiod.cpp \
        timeperiod.h
 
similarity index 79%
rename from lib/icinga/servicestatechangemessage.cpp
rename to lib/icinga/checkresultmessage.cpp
index df7a2ee835de7166cb18ce9ea04094badc1bfafc..fff9d96982494aa9808593c3971d168ab2b790ea 100644 (file)
 
 using namespace icinga;
 
-bool ServiceStateChangeMessage::GetService(String *service) const
+String CheckResultMessage::GetService(void) const
 {
-       return Get("service", service);
+       String service;
+       Get("service", &service);
+       return service;
 }
 
-void ServiceStateChangeMessage::SetService(const String& service)
+void CheckResultMessage::SetService(const String& service)
 {
        Set("service", service);
 }
 
+Dictionary::Ptr CheckResultMessage::GetCheckResult(void) const
+{
+       Dictionary::Ptr cr;
+       Get("check_result", &cr);
+       return cr;
+}
+
+void CheckResultMessage::SetCheckResult(const Dictionary::Ptr& result)
+{
+       Set("check_result", result);
+}
+
similarity index 79%
rename from lib/icinga/servicestatechangemessage.h
rename to lib/icinga/checkresultmessage.h
index be8733db29dd36accd1a1ce9a31a9862c51b18da..4a0ea39547ce5c31e3e7ac9e05df7a782ddee65c 100644 (file)
@@ -17,8 +17,8 @@
  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.             *
  ******************************************************************************/
 
-#ifndef SERVICESTATECHANGEMESSAGE_H
-#define SERVICESTATECHANGEMESSAGE_H
+#ifndef CHECKRESULTMESSAGE_H
+#define CHECKRESULTMESSAGE_H
 
 namespace icinga
 {
@@ -28,16 +28,19 @@ namespace icinga
  *
  * @ingroup icinga
  */
-class I2_ICINGA_API ServiceStateChangeMessage : public MessagePart
+class I2_ICINGA_API CheckResultMessage : public MessagePart
 {
 public:
-       ServiceStateChangeMessage(void) : MessagePart() { }
-       ServiceStateChangeMessage(const MessagePart& message) : MessagePart(message) { }
+       CheckResultMessage(void) : MessagePart() { }
+       CheckResultMessage(const MessagePart& message) : MessagePart(message) { }
 
-       bool GetService(String *service) const;
+       String GetService(void) const;
        void SetService(const String& service);
+
+       Dictionary::Ptr GetCheckResult(void) const;
+       void SetCheckResult(const Dictionary::Ptr& result);
 };
 
 }
 
-#endif /* SERVICESTATECHANGEMESSAGE_H */
+#endif /* CHECKRESULTMESSAGE_H */
index bc11049b9552ac909355cd6b7d0895a05c68620b..c9a55652eb65d4c7c121ba3acc6e1b951bfd7c1a 100644 (file)
@@ -61,7 +61,7 @@ using boost::algorithm::is_any_of;
 #include "pluginchecktask.h"
 #include "nullchecktask.h"
 
-#include "servicestatechangemessage.h"
+#include "checkresultmessage.h"
 
 #include "cib.h"
 
index 6889c6ed4229ae3ec6ec3b1fc0095f6fb160626b..b5575f9ca84ea6566295243adfe93e1a425fb97b 100644 (file)
@@ -19,6 +19,7 @@
     </ProjectConfiguration>
   </ItemGroup>
   <ItemGroup>
+    <ClCompile Include="checkresultmessage.cpp" />
     <ClCompile Include="cib.cpp" />
     <ClCompile Include="commentprocessor.cpp" />
     <ClCompile Include="downtimeprocessor.cpp" />
     <ClCompile Include="nullchecktask.cpp" />
     <ClCompile Include="service.cpp" />
     <ClCompile Include="servicegroup.cpp" />
-    <ClCompile Include="servicestatechangemessage.cpp" />
     <ClCompile Include="timeperiod.cpp" />
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="acknowledgement.h" />
+    <ClInclude Include="checkresultmessage.h" />
     <ClInclude Include="cib.h" />
     <ClInclude Include="commentprocessor.h" />
     <ClInclude Include="downtimeprocessor.h" />
@@ -55,7 +56,6 @@
     <ClInclude Include="nullchecktask.h" />
     <ClInclude Include="service.h" />
     <ClInclude Include="servicegroup.h" />
-    <ClInclude Include="servicestatechangemessage.h" />
     <ClInclude Include="timeperiod.h" />
   </ItemGroup>
   <PropertyGroup Label="Globals">
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
   <ImportGroup Label="ExtensionTargets">
   </ImportGroup>
-</Project>
\ No newline at end of file
+</Project>
index 7d314d931fb1385ea05d9391fddac133717725af..265879c441be78ff0be72254ae66ca75dd436132 100644 (file)
@@ -742,17 +742,19 @@ void Service::ProcessCheckResult(const Dictionary::Ptr& cr)
        ApplyCheckResult(cr);
 
        /* flush the current transaction so other instances see the service's
-        * new state when they receive the ServiceStateChange message */
+        * new state when they receive the CheckResult message */
        DynamicObject::FlushTx();
 
        RequestMessage rm;
-       rm.SetMethod("checker::ServiceStateChange");
+       rm.SetMethod("checker::CheckResult");
 
        /* TODO: add _old_ state to message */
-       ServiceStateChangeMessage params;
+       CheckResultMessage params;
        params.SetService(GetName());
+       params.SetCheckResult(cr);
 
        rm.SetParams(params);
 
        EndpointManager::GetInstance()->SendMulticastMessage(rm);
 }
+
index 69c5c034826e3e4cd9356ee4173a1dbfa9ba00df..d56ccc340efc211381fa9a060325c77189b2c454 100644 (file)
@@ -49,7 +49,6 @@ enum ServiceStateType
 };
 
 class CheckResultMessage;
-class ServiceStatusMessage;
 
 /**
  * An Icinga service.
index f7a4f819df0d634a8f1cded269f37c679882a813..56c1e2f7f9a240e694202f7a937d058b8d51e508 100644 (file)
@@ -51,7 +51,7 @@ public:
        template<typename T>
        bool Get(String key, T *value) const
        {
-               Value v =GetDictionary()->Get(key);
+               Value v = GetDictionary()->Get(key);
 
                if (v.IsEmpty())
                        return false;