Implemented ServiceStatusMessage class.

This commit is contained in:
Gunnar Beutner 2012-07-03 10:39:17 +02:00
parent 5dc74ecf0e
commit d577406a66
15 changed files with 215 additions and 72 deletions

View File

@ -101,7 +101,7 @@ string ConfigObject::GetSource(void) const
void ConfigObject::SetCommitTimestamp(time_t ts) void ConfigObject::SetCommitTimestamp(time_t ts)
{ {
GetProperties()->SetProperty("__tx", ts); GetProperties()->SetProperty("__tx", static_cast<long>(ts));
} }
time_t ConfigObject::GetCommitTimestamp(void) const time_t ConfigObject::GetCommitTimestamp(void) const

View File

@ -24,7 +24,9 @@ libcib_la_SOURCES = \
service.cpp \ service.cpp \
service.h \ service.h \
servicegroup.cpp \ servicegroup.cpp \
servicegroup.h servicegroup.h \
servicestatusmessage.cpp \
servicestatusmessage.h
libcib_la_CPPFLAGS = \ libcib_la_CPPFLAGS = \
-DI2_CIB_BUILD \ -DI2_CIB_BUILD \

View File

@ -2,6 +2,14 @@
using namespace icinga; using namespace icinga;
CheckResult::CheckResult(void)
: MessagePart()
{ }
CheckResult::CheckResult(const MessagePart& message)
: MessagePart(message)
{ }
void CheckResult::SetScheduleStart(time_t ts) void CheckResult::SetScheduleStart(time_t ts)
{ {
SetProperty("schedule_start", static_cast<long>(ts)); SetProperty("schedule_start", static_cast<long>(ts));

View File

@ -7,8 +7,8 @@ namespace icinga
class I2_CIB_API CheckResult : public MessagePart class I2_CIB_API CheckResult : public MessagePart
{ {
public: public:
CheckResult(void) : MessagePart() { } CheckResult(void);
CheckResult(const MessagePart& message) : MessagePart(message) { } CheckResult(const MessagePart& message);
void SetScheduleStart(time_t ts); void SetScheduleStart(time_t ts);
time_t GetScheduleStart(void) const; time_t GetScheduleStart(void) const;

View File

@ -91,6 +91,7 @@
<ClInclude Include="nagioschecktask.h" /> <ClInclude Include="nagioschecktask.h" />
<ClInclude Include="service.h" /> <ClInclude Include="service.h" />
<ClInclude Include="servicegroup.h" /> <ClInclude Include="servicegroup.h" />
<ClInclude Include="servicestatusmessage.h" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="checkresult.cpp" /> <ClCompile Include="checkresult.cpp" />
@ -103,6 +104,7 @@
<ClCompile Include="nagioschecktask.cpp" /> <ClCompile Include="nagioschecktask.cpp" />
<ClCompile Include="service.cpp" /> <ClCompile Include="service.cpp" />
<ClCompile Include="servicegroup.cpp" /> <ClCompile Include="servicegroup.cpp" />
<ClCompile Include="servicestatusmessage.cpp" />
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">

View File

@ -29,4 +29,6 @@
#include "checktask.h" #include "checktask.h"
#include "nagioschecktask.h" #include "nagioschecktask.h"
#include "servicestatusmessage.h"
#endif /* I2CIB_H */ #endif /* I2CIB_H */

View File

@ -84,15 +84,6 @@ long Service::GetRetryInterval(void) const
return value; 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 Service::GetDependencies(void) const
{ {
Dictionary::Ptr value; Dictionary::Ptr value;

View File

@ -40,7 +40,6 @@ public:
long GetMaxCheckAttempts(void) const; long GetMaxCheckAttempts(void) const;
long GetCheckInterval(void) const; long GetCheckInterval(void) const;
long GetRetryInterval(void) const; long GetRetryInterval(void) const;
long GetFreshnessInterval(void) const;
Dictionary::Ptr GetDependencies(void) const; Dictionary::Ptr GetDependencies(void) const;
Dictionary::Ptr GetGroups(void) const; Dictionary::Ptr GetGroups(void) const;
Dictionary::Ptr GetCheckers(void) const; Dictionary::Ptr GetCheckers(void) const;

View File

@ -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());
}

View File

@ -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 */

View File

@ -145,13 +145,13 @@ void CheckerComponent::ResultTimerHandler(void)
RequestMessage rm; RequestMessage rm;
rm.SetMethod("checker::CheckResult"); rm.SetMethod("checker::CheckResult");
MessagePart params; ServiceStatusMessage params;
params.SetProperty("service", service.GetName()); params.SetService(service.GetName());
params.SetProperty("state", static_cast<long>(service.GetState())); params.SetState(service.GetState());
params.SetProperty("state_type", static_cast<long>(service.GetStateType())); params.SetStateType(service.GetStateType());
params.SetProperty("current_attempt", static_cast<long>(service.GetCurrentCheckAttempt())); params.SetCurrentCheckAttempt(service.GetCurrentCheckAttempt());
params.SetProperty("next_check", static_cast<long>(service.GetNextCheck())); params.SetNextCheck(service.GetNextCheck());
params.SetProperty("result", result.GetDictionary()); params.SetCheckResult(result);
rm.SetParams(params); rm.SetParams(params);

View File

@ -291,7 +291,7 @@ void CIBSyncComponent::RemoteObjectRemovedHandler(const RequestMessage& request)
m_SyncingConfig = true; m_SyncingConfig = true;
object->Unregister(); object->Unregister();
m_SyncingConfig = false; m_SyncingConfig = false;
} catch (const std::exception& ex) { } catch (const std::exception&) {
m_SyncingConfig = false; m_SyncingConfig = false;
throw; throw;
} }

View File

@ -292,12 +292,12 @@ void DelegationComponent::DelegationTimerHandler(void)
void DelegationComponent::CheckResultRequestHandler(const Endpoint::Ptr& sender, const RequestMessage& request) void DelegationComponent::CheckResultRequestHandler(const Endpoint::Ptr& sender, const RequestMessage& request)
{ {
MessagePart params; ServiceStatusMessage params;
if (!request.GetParams(&params)) if (!request.GetParams(&params))
return; return;
string svcname; string svcname;
if (!params.GetProperty("service", &svcname)) if (params.GetService(&svcname))
return; return;
Service service = Service::GetByName(svcname); Service service = Service::GetByName(svcname);

View File

@ -1,3 +1,61 @@
#include "i2-discovery.h" #include "i2-discovery.h"
using namespace icinga; 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);
}

View File

@ -9,60 +9,24 @@ namespace icinga
*/ */
class DiscoveryMessage : public MessagePart class DiscoveryMessage : public MessagePart
{ {
public: public:
DiscoveryMessage(void) : MessagePart() { } DiscoveryMessage(void);
DiscoveryMessage(const MessagePart& message) : MessagePart(message) { } DiscoveryMessage(const MessagePart& message);
inline bool GetIdentity(string *value) const bool GetIdentity(string *value) const;
{ void SetIdentity(const string& value);
return GetProperty("identity", value);
}
inline void SetIdentity(const string& value) bool GetNode(string *value) const;
{ void SetNode(const string& value);
SetProperty("identity", value);
}
inline bool GetNode(string *value) const bool GetService(string *value) const;
{ void SetService(const string& value);
return GetProperty("node", value);
}
inline void SetNode(const string& value) bool GetSubscriptions(MessagePart *value) const;
{ void SetSubscriptions(MessagePart value);
SetProperty("node", value);
}
inline bool GetService(string *value) const bool GetPublications(MessagePart *value) const;
{ void SetPublications(MessagePart value);
return GetProperty("service", value);
}
inline void SetService(const string& value)
{
SetProperty("service", value);
}
inline bool GetSubscriptions(MessagePart *value) const
{
return GetProperty("subscriptions", value);
}
inline void SetSubscriptions(MessagePart value)
{
SetProperty("subscriptions", value);
}
inline bool GetPublications(MessagePart *value) const
{
return GetProperty("publications", value);
}
inline void SetPublications(MessagePart value)
{
SetProperty("publications", value);
}
}; };
} }