[icinga-checkins] icinga.org: icinga2/master: Implement Service::OnCheckResultReceived, rename ServiceStateChangeMessage to CheckResultMessage

git at icinga.org git at icinga.org
Thu Jan 31 16:51:49 CET 2013


Module: icinga2
Branch: master
Commit: 070607a1d10101d0bb6d8ffecc3f371313e8cd97
URL:    https://git.icinga.org/?p=icinga2.git;a=commit;h=070607a1d10101d0bb6d8ffecc3f371313e8cd97

Author: Gunnar Beutner <gunnar.beutner at netways.de>
Date:   Thu Jan 31 16:49:40 2013 +0100

Implement Service::OnCheckResultReceived, rename ServiceStateChangeMessage to CheckResultMessage

Fixes #3597

---

 components/replication/replicationcomponent.cpp    |   47 ++++++++-----------
 components/replication/replicationcomponent.h      |    2 +-
 lib/icinga/Makefile.am                             |    4 +-
 ...atechangemessage.cpp => checkresultmessage.cpp} |   20 +++++++-
 ...cestatechangemessage.h => checkresultmessage.h} |   17 ++++---
 lib/icinga/i2-icinga.h                             |    2 +-
 lib/icinga/icinga.vcxproj                          |    6 +-
 lib/icinga/service.cpp                             |    8 ++-
 lib/icinga/service.h                               |    1 -
 lib/remoting/messagepart.h                         |    2 +-
 10 files changed, 60 insertions(+), 49 deletions(-)

diff --git a/components/replication/replicationcomponent.cpp b/components/replication/replicationcomponent.cpp
index c3e694f..f8cfec8 100644
--- a/components/replication/replicationcomponent.cpp
+++ b/components/replication/replicationcomponent.cpp
@@ -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)
diff --git a/components/replication/replicationcomponent.h b/components/replication/replicationcomponent.h
index 136770d..d3f1bd7 100644
--- a/components/replication/replicationcomponent.h
+++ b/components/replication/replicationcomponent.h
@@ -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);
 
diff --git a/lib/icinga/Makefile.am b/lib/icinga/Makefile.am
index 8ef08fc..3ffcb01 100644
--- a/lib/icinga/Makefile.am
+++ b/lib/icinga/Makefile.am
@@ -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
 
diff --git a/lib/icinga/servicestatechangemessage.cpp b/lib/icinga/checkresultmessage.cpp
similarity index 79%
rename from lib/icinga/servicestatechangemessage.cpp
rename to lib/icinga/checkresultmessage.cpp
index df7a2ee..fff9d96 100644
--- a/lib/icinga/servicestatechangemessage.cpp
+++ b/lib/icinga/checkresultmessage.cpp
@@ -21,13 +21,27 @@
 
 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);
+}
+
diff --git a/lib/icinga/servicestatechangemessage.h b/lib/icinga/checkresultmessage.h
similarity index 79%
rename from lib/icinga/servicestatechangemessage.h
rename to lib/icinga/checkresultmessage.h
index be8733d..4a0ea39 100644
--- a/lib/icinga/servicestatechangemessage.h
+++ b/lib/icinga/checkresultmessage.h
@@ -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 */
diff --git a/lib/icinga/i2-icinga.h b/lib/icinga/i2-icinga.h
index bc11049..c9a5565 100644
--- a/lib/icinga/i2-icinga.h
+++ b/lib/icinga/i2-icinga.h
@@ -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"
 
diff --git a/lib/icinga/icinga.vcxproj b/lib/icinga/icinga.vcxproj
index 6889c6e..b5575f9 100644
--- a/lib/icinga/icinga.vcxproj
+++ b/lib/icinga/icinga.vcxproj
@@ -19,6 +19,7 @@
     </ProjectConfiguration>
   </ItemGroup>
   <ItemGroup>
+    <ClCompile Include="checkresultmessage.cpp" />
     <ClCompile Include="cib.cpp" />
     <ClCompile Include="commentprocessor.cpp" />
     <ClCompile Include="downtimeprocessor.cpp" />
@@ -37,11 +38,11 @@
     <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">
@@ -208,4 +208,4 @@
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
   <ImportGroup Label="ExtensionTargets">
   </ImportGroup>
-</Project>
\ No newline at end of file
+</Project>
diff --git a/lib/icinga/service.cpp b/lib/icinga/service.cpp
index 7d314d9..265879c 100644
--- a/lib/icinga/service.cpp
+++ b/lib/icinga/service.cpp
@@ -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);
 }
+
diff --git a/lib/icinga/service.h b/lib/icinga/service.h
index 69c5c03..d56ccc3 100644
--- a/lib/icinga/service.h
+++ b/lib/icinga/service.h
@@ -49,7 +49,6 @@ enum ServiceStateType
 };
 
 class CheckResultMessage;
-class ServiceStatusMessage;
 
 /**
  * An Icinga service.
diff --git a/lib/remoting/messagepart.h b/lib/remoting/messagepart.h
index f7a4f81..56c1e2f 100644
--- a/lib/remoting/messagepart.h
+++ b/lib/remoting/messagepart.h
@@ -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;





More information about the icinga-checkins mailing list