]> granicus.if.org Git - icinga2/commitdiff
Implemented ServiceStatusMessage class.
authorGunnar Beutner <gunnar@beutner.name>
Tue, 3 Jul 2012 08:39:17 +0000 (10:39 +0200)
committerGunnar Beutner <gunnar@beutner.name>
Tue, 3 Jul 2012 08:41:25 +0000 (10:41 +0200)
15 files changed:
base/configobject.cpp
cib/Makefile.am
cib/checkresult.cpp
cib/checkresult.h
cib/cib.vcxproj
cib/i2-cib.h
cib/service.cpp
cib/service.h
cib/servicestatusmessage.cpp [new file with mode: 0644]
cib/servicestatusmessage.h [new file with mode: 0644]
components/checker/checkercomponent.cpp
components/cibsync/cibsynccomponent.cpp
components/delegation/delegationcomponent.cpp
components/discovery/discoverymessage.cpp
components/discovery/discoverymessage.h

index 245da3710390df0e49e297cdac7888807f8c0ce7..61e1a05c6fa471a2bf012a2fa1209a5a3d56565d 100644 (file)
@@ -101,7 +101,7 @@ string ConfigObject::GetSource(void) const
 
 void ConfigObject::SetCommitTimestamp(time_t ts)
 {
-       GetProperties()->SetProperty("__tx", ts);
+       GetProperties()->SetProperty("__tx", static_cast<long>(ts));
 }
 
 time_t ConfigObject::GetCommitTimestamp(void) const
index bd47083c297a0e22fff7d2f2e9ca70d707b8676b..79e45ae90b0872c1fc016b160c2238290f963eee 100644 (file)
@@ -24,7 +24,9 @@ libcib_la_SOURCES = \
        service.cpp \
        service.h \
        servicegroup.cpp \
-       servicegroup.h
+       servicegroup.h \
+       servicestatusmessage.cpp \
+       servicestatusmessage.h
 
 libcib_la_CPPFLAGS = \
        -DI2_CIB_BUILD \
index eca5775467b010e7caeec1d88921fed526b0e399..92adcdc13a3747fc4fc8a0b3b7e8136e073d7679 100644 (file)
@@ -2,6 +2,14 @@
 
 using namespace icinga;
 
+CheckResult::CheckResult(void)
+       : MessagePart()
+{ }
+
+CheckResult::CheckResult(const MessagePart& message)
+       : MessagePart(message)
+{ }
+
 void CheckResult::SetScheduleStart(time_t ts)
 {
        SetProperty("schedule_start", static_cast<long>(ts));
index c57b8ecea1d06c8ee579a77576208f12da77cabd..77720589126699c7be8da4d03b3418ccbebd6c14 100644 (file)
@@ -7,8 +7,8 @@ namespace icinga
 class I2_CIB_API CheckResult : public MessagePart
 {
 public:
-       CheckResult(void) : MessagePart() { }
-       CheckResult(const MessagePart& message) : MessagePart(message) { }
+       CheckResult(void);
+       CheckResult(const MessagePart& message);
 
        void SetScheduleStart(time_t ts);
        time_t GetScheduleStart(void) const;
index 4f5cfe63679298fff8e88a7ef59d67552e155c57..afea90e619818f86341d4f3e4eaae6568e3f2b12 100644 (file)
@@ -91,6 +91,7 @@
     <ClInclude Include="nagioschecktask.h" />
     <ClInclude Include="service.h" />
     <ClInclude Include="servicegroup.h" />
+    <ClInclude Include="servicestatusmessage.h" />
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="checkresult.cpp" />
     <ClCompile Include="nagioschecktask.cpp" />
     <ClCompile Include="service.cpp" />
     <ClCompile Include="servicegroup.cpp" />
+    <ClCompile Include="servicestatusmessage.cpp" />
   </ItemGroup>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
   <ImportGroup Label="ExtensionTargets">
index 6a5d382501aabcd556705efba467eb927ba07054..cc5901ca8cfcb48b4c8bf0eb8daf9d4399d33707 100644 (file)
@@ -29,4 +29,6 @@
 #include "checktask.h"
 #include "nagioschecktask.h"
 
+#include "servicestatusmessage.h"
+
 #endif /* I2CIB_H */
index 64e042a4284053439e519d0000e55c4e74265d98..fe34e74dc726bde61504e65b9d67e0e6b0fb8de7 100644 (file)
@@ -84,15 +84,6 @@ long Service::GetRetryInterval(void) const
        return value;
 }
 
-long Service::GetFreshnessInterval(void) const
-{
-       long value;
-       if (!GetConfigObject()->GetProperty("freshness_interval", &value));
-               value = GetCheckInterval() * 3;
-
-       return value;
-}
-
 Dictionary::Ptr Service::GetDependencies(void) const
 {
        Dictionary::Ptr value;
index d0e0ce8980b4e584ac160e1275a4b1b82ae3201a..320041b1fecab6def6ceaed2a4d5d0044b84e6b9 100644 (file)
@@ -40,7 +40,6 @@ public:
        long GetMaxCheckAttempts(void) const;
        long GetCheckInterval(void) const;
        long GetRetryInterval(void) const;
-       long GetFreshnessInterval(void) const;
        Dictionary::Ptr GetDependencies(void) const;
        Dictionary::Ptr GetGroups(void) const;
        Dictionary::Ptr GetCheckers(void) const;
diff --git a/cib/servicestatusmessage.cpp b/cib/servicestatusmessage.cpp
new file mode 100644 (file)
index 0000000..c05134b
--- /dev/null
@@ -0,0 +1,83 @@
+#include "i2-cib.h"
+
+using namespace icinga;
+
+bool ServiceStatusMessage::GetService(string *service) const
+{
+       return GetProperty("service", service);
+}
+
+void ServiceStatusMessage::SetService(const string& service)
+{
+       SetProperty("service", service);
+}
+
+bool ServiceStatusMessage::GetState(ServiceState *state) const
+{
+       long value;
+       if (GetProperty("state", &value)) {
+               *state = static_cast<ServiceState>(value);
+               return true;
+       }
+       return false;
+}
+
+void ServiceStatusMessage::SetState(ServiceState state)
+{
+       SetProperty("state", static_cast<long>(state));
+}
+
+bool ServiceStatusMessage::GetStateType(ServiceStateType *type) const
+{
+       long value;
+       if (GetProperty("state_type", &value)) {
+               *type = static_cast<ServiceStateType>(value);
+               return true;
+       }
+       return false;
+}
+
+void ServiceStatusMessage::SetStateType(ServiceStateType type)
+{
+       SetProperty("state_type", static_cast<long>(type));
+}
+
+bool ServiceStatusMessage::GetCurrentCheckAttempt(long *attempt) const
+{
+       return GetProperty("current_attempt", attempt);
+}
+
+void ServiceStatusMessage::SetCurrentCheckAttempt(long attempt)
+{
+       SetProperty("current_attempt", attempt);
+}
+
+bool ServiceStatusMessage::GetNextCheck(time_t *ts) const
+{
+       long value;
+       if (GetProperty("next_check", &value)) {
+               *ts = value;
+               return true;
+       }
+       return false;
+}
+
+void ServiceStatusMessage::SetNextCheck(time_t ts)
+{
+       SetProperty("next_check", static_cast<long>(ts));
+}
+
+bool ServiceStatusMessage::GetCheckResult(CheckResult *cr) const
+{
+       Dictionary::Ptr obj;
+       if (GetProperty("result", &obj)) {
+               *cr = CheckResult(MessagePart(obj));
+               return true;
+       }
+       return false;
+}
+
+void ServiceStatusMessage::SetCheckResult(CheckResult cr)
+{
+       SetProperty("result", cr.GetDictionary());
+}
\ No newline at end of file
diff --git a/cib/servicestatusmessage.h b/cib/servicestatusmessage.h
new file mode 100644 (file)
index 0000000..6a5c7ce
--- /dev/null
@@ -0,0 +1,34 @@
+#ifndef SERVICESTATUSMESSAGE_H
+#define SERVICESTATUSMESSAGE_H
+
+namespace icinga
+{
+
+class I2_CIB_API ServiceStatusMessage : public MessagePart
+{
+public:
+       ServiceStatusMessage(void) : MessagePart() { }
+       ServiceStatusMessage(const MessagePart& message) : MessagePart(message) { }
+
+       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 GetCurrentCheckAttempt(long *attempt) const;
+       void SetCurrentCheckAttempt(long attempt);
+
+       bool GetNextCheck(time_t *ts) const;
+       void SetNextCheck(time_t ts);
+
+       bool GetCheckResult(CheckResult *cr) const;
+       void SetCheckResult(CheckResult cr);
+};
+
+}
+
+#endif /* SERVICESTATUSMESSAGE_H */
index f2bb2f8ce05d2a617c1a014f9ef2b26c856132c8..e1dbb1bf05cdde63f556d82cb0da81f3551f88e1 100644 (file)
@@ -145,13 +145,13 @@ void CheckerComponent::ResultTimerHandler(void)
                RequestMessage rm;
                rm.SetMethod("checker::CheckResult");
 
-               MessagePart params;
-               params.SetProperty("service", service.GetName());
-               params.SetProperty("state", static_cast<long>(service.GetState()));
-               params.SetProperty("state_type", static_cast<long>(service.GetStateType()));
-               params.SetProperty("current_attempt", static_cast<long>(service.GetCurrentCheckAttempt()));
-               params.SetProperty("next_check", static_cast<long>(service.GetNextCheck()));
-               params.SetProperty("result", result.GetDictionary());
+               ServiceStatusMessage params;
+               params.SetService(service.GetName());
+               params.SetState(service.GetState());
+               params.SetStateType(service.GetStateType());
+               params.SetCurrentCheckAttempt(service.GetCurrentCheckAttempt());
+               params.SetNextCheck(service.GetNextCheck());
+               params.SetCheckResult(result);
 
                rm.SetParams(params);
 
index 893aa92a02590f5097d9e2aa49c936610cfb22bf..3468bc64191b0c44d7d24972e647f36f4e983b88 100644 (file)
@@ -291,7 +291,7 @@ void CIBSyncComponent::RemoteObjectRemovedHandler(const RequestMessage& request)
                        m_SyncingConfig = true;
                        object->Unregister();
                        m_SyncingConfig = false;
-               } catch (const std::exception& ex) {
+               } catch (const std::exception&) {
                        m_SyncingConfig = false;
                        throw;
                }
index b3139ecc8d22459ac611baba502ff595811e6bfe..886380993334b4163e28cbf258b3986600871481 100644 (file)
@@ -292,12 +292,12 @@ void DelegationComponent::DelegationTimerHandler(void)
 
 void DelegationComponent::CheckResultRequestHandler(const Endpoint::Ptr& sender, const RequestMessage& request)
 {
-       MessagePart params;
+       ServiceStatusMessage params;
        if (!request.GetParams(&params))
                return;
 
        string svcname;
-       if (!params.GetProperty("service", &svcname))
+       if (params.GetService(&svcname))
                return;
 
        Service service = Service::GetByName(svcname);
index 28ce93afb3cddb1bf25687e7b005093a982a2eb2..a509885572ad7f961c51dd84336b3b023d291036 100644 (file)
@@ -1,3 +1,61 @@
 #include "i2-discovery.h"
 
 using namespace icinga;
+
+DiscoveryMessage::DiscoveryMessage(void)
+       : MessagePart()
+{ }
+
+DiscoveryMessage::DiscoveryMessage(const MessagePart& message)
+       : MessagePart(message)
+{ }
+
+bool DiscoveryMessage::GetIdentity(string *value) const
+{
+       return GetProperty("identity", value);
+}
+
+void DiscoveryMessage::SetIdentity(const string& value)
+{
+       SetProperty("identity", value);
+}
+
+bool DiscoveryMessage::GetNode(string *value) const
+{
+       return GetProperty("node", value);
+}
+
+void DiscoveryMessage::SetNode(const string& value)
+{
+       SetProperty("node", value);
+}
+
+bool DiscoveryMessage::GetService(string *value) const
+{
+       return GetProperty("service", value);
+}
+
+void DiscoveryMessage::SetService(const string& value)
+{
+       SetProperty("service", value);
+}
+
+bool DiscoveryMessage::GetSubscriptions(MessagePart *value) const
+{
+       return GetProperty("subscriptions", value);
+}
+
+void DiscoveryMessage::SetSubscriptions(MessagePart value)
+{
+       SetProperty("subscriptions", value);
+}
+
+bool DiscoveryMessage::GetPublications(MessagePart *value) const
+{
+       return GetProperty("publications", value);
+}
+
+void DiscoveryMessage::SetPublications(MessagePart value)
+{
+       SetProperty("publications", value);
+}
\ No newline at end of file
index cad11aa032be6e8dba2c7885a3d56936ad092a25..b878054a869495d3f557affcee7c874a195cb901 100644 (file)
@@ -9,60 +9,24 @@ namespace icinga
  */
 class DiscoveryMessage : public MessagePart
 {
-
 public:
-       DiscoveryMessage(void) : MessagePart() { }
-       DiscoveryMessage(const MessagePart& message) : MessagePart(message) { }
-
-       inline bool GetIdentity(string *value) const
-       {
-               return GetProperty("identity", value);
-       }
-
-       inline void SetIdentity(const string& value)
-       {
-               SetProperty("identity", value);
-       }
-
-       inline bool GetNode(string *value) const
-       {
-               return GetProperty("node", value);
-       }
-
-       inline void SetNode(const string& value)
-       {
-               SetProperty("node", value);
-       }
-
-       inline bool GetService(string *value) const
-       {
-               return GetProperty("service", value);
-       }
+       DiscoveryMessage(void);
+       DiscoveryMessage(const MessagePart& message);
 
-       inline void SetService(const string& value)
-       {
-               SetProperty("service", value);
-       }
+       bool GetIdentity(string *value) const;
+       void SetIdentity(const string& value);
 
-       inline bool GetSubscriptions(MessagePart *value) const
-       {
-               return GetProperty("subscriptions", value);
-       }
+       bool GetNode(string *value) const;
+       void SetNode(const string& value);
 
-       inline void SetSubscriptions(MessagePart value)
-       {
-               SetProperty("subscriptions", value);
-       }
+       bool GetService(string *value) const;
+       void SetService(const string& value);
 
-       inline bool GetPublications(MessagePart *value) const
-       {
-               return GetProperty("publications", value);
-       }
+       bool GetSubscriptions(MessagePart *value) const;
+       void SetSubscriptions(MessagePart value);
 
-       inline void SetPublications(MessagePart value)
-       {
-               SetProperty("publications", value);
-       }
+       bool GetPublications(MessagePart *value) const;
+       void SetPublications(MessagePart value);
 };
 
 }