From: Gunnar Beutner Date: Tue, 3 Jul 2012 08:39:17 +0000 (+0200) Subject: Implemented ServiceStatusMessage class. X-Git-Tag: v0.0.1~318 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d577406a66dde4c677e2fd3e8030fba954e41ea1;p=icinga2 Implemented ServiceStatusMessage class. --- diff --git a/base/configobject.cpp b/base/configobject.cpp index 245da3710..61e1a05c6 100644 --- a/base/configobject.cpp +++ b/base/configobject.cpp @@ -101,7 +101,7 @@ string ConfigObject::GetSource(void) const void ConfigObject::SetCommitTimestamp(time_t ts) { - GetProperties()->SetProperty("__tx", ts); + GetProperties()->SetProperty("__tx", static_cast(ts)); } time_t ConfigObject::GetCommitTimestamp(void) const diff --git a/cib/Makefile.am b/cib/Makefile.am index bd47083c2..79e45ae90 100644 --- a/cib/Makefile.am +++ b/cib/Makefile.am @@ -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 \ diff --git a/cib/checkresult.cpp b/cib/checkresult.cpp index eca577546..92adcdc13 100644 --- a/cib/checkresult.cpp +++ b/cib/checkresult.cpp @@ -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(ts)); diff --git a/cib/checkresult.h b/cib/checkresult.h index c57b8ecea..777205891 100644 --- a/cib/checkresult.h +++ b/cib/checkresult.h @@ -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; diff --git a/cib/cib.vcxproj b/cib/cib.vcxproj index 4f5cfe636..afea90e61 100644 --- a/cib/cib.vcxproj +++ b/cib/cib.vcxproj @@ -91,6 +91,7 @@ + @@ -103,6 +104,7 @@ + diff --git a/cib/i2-cib.h b/cib/i2-cib.h index 6a5d38250..cc5901ca8 100644 --- a/cib/i2-cib.h +++ b/cib/i2-cib.h @@ -29,4 +29,6 @@ #include "checktask.h" #include "nagioschecktask.h" +#include "servicestatusmessage.h" + #endif /* I2CIB_H */ diff --git a/cib/service.cpp b/cib/service.cpp index 64e042a42..fe34e74dc 100644 --- a/cib/service.cpp +++ b/cib/service.cpp @@ -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; diff --git a/cib/service.h b/cib/service.h index d0e0ce898..320041b1f 100644 --- a/cib/service.h +++ b/cib/service.h @@ -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 index 000000000..c05134b48 --- /dev/null +++ b/cib/servicestatusmessage.cpp @@ -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(value); + return true; + } + return false; +} + +void ServiceStatusMessage::SetState(ServiceState state) +{ + SetProperty("state", static_cast(state)); +} + +bool ServiceStatusMessage::GetStateType(ServiceStateType *type) const +{ + long value; + if (GetProperty("state_type", &value)) { + *type = static_cast(value); + return true; + } + return false; +} + +void ServiceStatusMessage::SetStateType(ServiceStateType type) +{ + SetProperty("state_type", static_cast(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(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 index 000000000..6a5c7ce18 --- /dev/null +++ b/cib/servicestatusmessage.h @@ -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 */ diff --git a/components/checker/checkercomponent.cpp b/components/checker/checkercomponent.cpp index f2bb2f8ce..e1dbb1bf0 100644 --- a/components/checker/checkercomponent.cpp +++ b/components/checker/checkercomponent.cpp @@ -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(service.GetState())); - params.SetProperty("state_type", static_cast(service.GetStateType())); - params.SetProperty("current_attempt", static_cast(service.GetCurrentCheckAttempt())); - params.SetProperty("next_check", static_cast(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); diff --git a/components/cibsync/cibsynccomponent.cpp b/components/cibsync/cibsynccomponent.cpp index 893aa92a0..3468bc641 100644 --- a/components/cibsync/cibsynccomponent.cpp +++ b/components/cibsync/cibsynccomponent.cpp @@ -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; } diff --git a/components/delegation/delegationcomponent.cpp b/components/delegation/delegationcomponent.cpp index b3139ecc8..886380993 100644 --- a/components/delegation/delegationcomponent.cpp +++ b/components/delegation/delegationcomponent.cpp @@ -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(¶ms)) return; string svcname; - if (!params.GetProperty("service", &svcname)) + if (params.GetService(&svcname)) return; Service service = Service::GetByName(svcname); diff --git a/components/discovery/discoverymessage.cpp b/components/discovery/discoverymessage.cpp index 28ce93afb..a50988557 100644 --- a/components/discovery/discoverymessage.cpp +++ b/components/discovery/discoverymessage.cpp @@ -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 diff --git a/components/discovery/discoverymessage.h b/components/discovery/discoverymessage.h index cad11aa03..b878054a8 100644 --- a/components/discovery/discoverymessage.h +++ b/components/discovery/discoverymessage.h @@ -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); }; }