mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-23 05:34:48 +02:00
Implement Service::OnCheckResultReceived, rename ServiceStateChangeMessage to CheckResultMessage
Fixes #3597
This commit is contained in:
parent
15b260d75e
commit
070607a1d1
@ -40,8 +40,8 @@ void ReplicationComponent::Start(void)
|
|||||||
boost::bind(&ReplicationComponent::RemoteObjectRemovedHandler, this, _3));
|
boost::bind(&ReplicationComponent::RemoteObjectRemovedHandler, this, _3));
|
||||||
|
|
||||||
/* service status */
|
/* service status */
|
||||||
m_Endpoint->RegisterTopicHandler("checker::ServiceStateChange",
|
m_Endpoint->RegisterTopicHandler("checker::CheckResult",
|
||||||
boost::bind(&ReplicationComponent::ServiceStateChangeRequestHandler, _3));
|
boost::bind(&ReplicationComponent::CheckResultRequestHandler, _3));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -52,42 +52,35 @@ void ReplicationComponent::Stop(void)
|
|||||||
m_Endpoint->Unregister();
|
m_Endpoint->Unregister();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ReplicationComponent::ServiceStateChangeRequestHandler(const RequestMessage& request)
|
void ReplicationComponent::CheckResultRequestHandler(const RequestMessage& request)
|
||||||
{
|
{
|
||||||
ServiceStateChangeMessage params;
|
CheckResultMessage params;
|
||||||
if (!request.GetParams(¶ms))
|
if (!request.GetParams(¶ms))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
String svcname;
|
String svcname = params.GetService();
|
||||||
if (!params.GetService(&svcname))
|
|
||||||
return;
|
|
||||||
|
|
||||||
Service::Ptr service = Service::GetByName(svcname);
|
Service::Ptr service = Service::GetByName(svcname);
|
||||||
|
|
||||||
//CheckResult cr;
|
Service::OnCheckResultReceived(service, params);
|
||||||
//if (!params.GetCheckResult(&cr))
|
|
||||||
// return;
|
|
||||||
|
|
||||||
//Service::OnCheckResultReceived(service, params);
|
Dictionary::Ptr cr = params.GetCheckResult();
|
||||||
//service->ApplyCheckResult(cr);
|
if (!cr)
|
||||||
|
return;
|
||||||
|
|
||||||
Dictionary::Ptr cr = service->GetLastCheckResult();
|
Value active = cr->Get("active");
|
||||||
if (cr) {
|
|
||||||
Value active = cr->Get("active");
|
|
||||||
|
|
||||||
time_t ts;
|
time_t ts;
|
||||||
Value schedule_end = cr->Get("schedule_end");
|
Value schedule_end = cr->Get("schedule_end");
|
||||||
|
|
||||||
if (!schedule_end.IsEmpty())
|
if (!schedule_end.IsEmpty())
|
||||||
ts = static_cast<time_t>(schedule_end);
|
ts = static_cast<time_t>(schedule_end);
|
||||||
else
|
else
|
||||||
ts = static_cast<time_t>(Utility::GetTime());
|
ts = static_cast<time_t>(Utility::GetTime());
|
||||||
|
|
||||||
if (active.IsEmpty() || static_cast<long>(active))
|
if (active.IsEmpty() || static_cast<long>(active))
|
||||||
CIB::UpdateActiveChecksStatistics(ts, 1);
|
CIB::UpdateActiveChecksStatistics(ts, 1);
|
||||||
else
|
else
|
||||||
CIB::UpdatePassiveChecksStatistics(ts, 1);
|
CIB::UpdatePassiveChecksStatistics(ts, 1);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ReplicationComponent::EndpointConnectedHandler(const Endpoint::Ptr& endpoint)
|
void ReplicationComponent::EndpointConnectedHandler(const Endpoint::Ptr& endpoint)
|
||||||
|
@ -35,7 +35,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
Endpoint::Ptr m_Endpoint;
|
Endpoint::Ptr m_Endpoint;
|
||||||
|
|
||||||
static void ServiceStateChangeRequestHandler(const RequestMessage& request);
|
static void CheckResultRequestHandler(const RequestMessage& request);
|
||||||
|
|
||||||
void EndpointConnectedHandler(const Endpoint::Ptr& endpoint);
|
void EndpointConnectedHandler(const Endpoint::Ptr& endpoint);
|
||||||
|
|
||||||
|
@ -6,6 +6,8 @@ pkglib_LTLIBRARIES = \
|
|||||||
|
|
||||||
libicinga_la_SOURCES = \
|
libicinga_la_SOURCES = \
|
||||||
acknowledgement.h \
|
acknowledgement.h \
|
||||||
|
checkresultmessage.cpp \
|
||||||
|
checkresultmessage.h \
|
||||||
cib.cpp \
|
cib.cpp \
|
||||||
cib.h \
|
cib.h \
|
||||||
commentprocessor.cpp \
|
commentprocessor.cpp \
|
||||||
@ -31,8 +33,6 @@ libicinga_la_SOURCES = \
|
|||||||
servicegroup.cpp \
|
servicegroup.cpp \
|
||||||
servicegroup.h \
|
servicegroup.h \
|
||||||
service.h \
|
service.h \
|
||||||
servicestatechangemessage.cpp \
|
|
||||||
servicestatechangemessage.h \
|
|
||||||
timeperiod.cpp \
|
timeperiod.cpp \
|
||||||
timeperiod.h
|
timeperiod.h
|
||||||
|
|
||||||
|
@ -21,13 +21,27 @@
|
|||||||
|
|
||||||
using namespace icinga;
|
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);
|
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);
|
||||||
|
}
|
||||||
|
|
@ -17,8 +17,8 @@
|
|||||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
#ifndef SERVICESTATECHANGEMESSAGE_H
|
#ifndef CHECKRESULTMESSAGE_H
|
||||||
#define SERVICESTATECHANGEMESSAGE_H
|
#define CHECKRESULTMESSAGE_H
|
||||||
|
|
||||||
namespace icinga
|
namespace icinga
|
||||||
{
|
{
|
||||||
@ -28,16 +28,19 @@ namespace icinga
|
|||||||
*
|
*
|
||||||
* @ingroup icinga
|
* @ingroup icinga
|
||||||
*/
|
*/
|
||||||
class I2_ICINGA_API ServiceStateChangeMessage : public MessagePart
|
class I2_ICINGA_API CheckResultMessage : public MessagePart
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ServiceStateChangeMessage(void) : MessagePart() { }
|
CheckResultMessage(void) : MessagePart() { }
|
||||||
ServiceStateChangeMessage(const MessagePart& message) : MessagePart(message) { }
|
CheckResultMessage(const MessagePart& message) : MessagePart(message) { }
|
||||||
|
|
||||||
bool GetService(String *service) const;
|
String GetService(void) const;
|
||||||
void SetService(const String& service);
|
void SetService(const String& service);
|
||||||
|
|
||||||
|
Dictionary::Ptr GetCheckResult(void) const;
|
||||||
|
void SetCheckResult(const Dictionary::Ptr& result);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* SERVICESTATECHANGEMESSAGE_H */
|
#endif /* CHECKRESULTMESSAGE_H */
|
@ -61,7 +61,7 @@ using boost::algorithm::is_any_of;
|
|||||||
#include "pluginchecktask.h"
|
#include "pluginchecktask.h"
|
||||||
#include "nullchecktask.h"
|
#include "nullchecktask.h"
|
||||||
|
|
||||||
#include "servicestatechangemessage.h"
|
#include "checkresultmessage.h"
|
||||||
|
|
||||||
#include "cib.h"
|
#include "cib.h"
|
||||||
|
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
</ProjectConfiguration>
|
</ProjectConfiguration>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<ClCompile Include="checkresultmessage.cpp" />
|
||||||
<ClCompile Include="cib.cpp" />
|
<ClCompile Include="cib.cpp" />
|
||||||
<ClCompile Include="commentprocessor.cpp" />
|
<ClCompile Include="commentprocessor.cpp" />
|
||||||
<ClCompile Include="downtimeprocessor.cpp" />
|
<ClCompile Include="downtimeprocessor.cpp" />
|
||||||
@ -37,11 +38,11 @@
|
|||||||
<ClCompile Include="nullchecktask.cpp" />
|
<ClCompile Include="nullchecktask.cpp" />
|
||||||
<ClCompile Include="service.cpp" />
|
<ClCompile Include="service.cpp" />
|
||||||
<ClCompile Include="servicegroup.cpp" />
|
<ClCompile Include="servicegroup.cpp" />
|
||||||
<ClCompile Include="servicestatechangemessage.cpp" />
|
|
||||||
<ClCompile Include="timeperiod.cpp" />
|
<ClCompile Include="timeperiod.cpp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="acknowledgement.h" />
|
<ClInclude Include="acknowledgement.h" />
|
||||||
|
<ClInclude Include="checkresultmessage.h" />
|
||||||
<ClInclude Include="cib.h" />
|
<ClInclude Include="cib.h" />
|
||||||
<ClInclude Include="commentprocessor.h" />
|
<ClInclude Include="commentprocessor.h" />
|
||||||
<ClInclude Include="downtimeprocessor.h" />
|
<ClInclude Include="downtimeprocessor.h" />
|
||||||
@ -55,7 +56,6 @@
|
|||||||
<ClInclude Include="nullchecktask.h" />
|
<ClInclude Include="nullchecktask.h" />
|
||||||
<ClInclude Include="service.h" />
|
<ClInclude Include="service.h" />
|
||||||
<ClInclude Include="servicegroup.h" />
|
<ClInclude Include="servicegroup.h" />
|
||||||
<ClInclude Include="servicestatechangemessage.h" />
|
|
||||||
<ClInclude Include="timeperiod.h" />
|
<ClInclude Include="timeperiod.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<PropertyGroup Label="Globals">
|
<PropertyGroup Label="Globals">
|
||||||
@ -208,4 +208,4 @@
|
|||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||||
<ImportGroup Label="ExtensionTargets">
|
<ImportGroup Label="ExtensionTargets">
|
||||||
</ImportGroup>
|
</ImportGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
@ -742,17 +742,19 @@ void Service::ProcessCheckResult(const Dictionary::Ptr& cr)
|
|||||||
ApplyCheckResult(cr);
|
ApplyCheckResult(cr);
|
||||||
|
|
||||||
/* flush the current transaction so other instances see the service's
|
/* 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();
|
DynamicObject::FlushTx();
|
||||||
|
|
||||||
RequestMessage rm;
|
RequestMessage rm;
|
||||||
rm.SetMethod("checker::ServiceStateChange");
|
rm.SetMethod("checker::CheckResult");
|
||||||
|
|
||||||
/* TODO: add _old_ state to message */
|
/* TODO: add _old_ state to message */
|
||||||
ServiceStateChangeMessage params;
|
CheckResultMessage params;
|
||||||
params.SetService(GetName());
|
params.SetService(GetName());
|
||||||
|
params.SetCheckResult(cr);
|
||||||
|
|
||||||
rm.SetParams(params);
|
rm.SetParams(params);
|
||||||
|
|
||||||
EndpointManager::GetInstance()->SendMulticastMessage(rm);
|
EndpointManager::GetInstance()->SendMulticastMessage(rm);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,7 +49,6 @@ enum ServiceStateType
|
|||||||
};
|
};
|
||||||
|
|
||||||
class CheckResultMessage;
|
class CheckResultMessage;
|
||||||
class ServiceStatusMessage;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An Icinga service.
|
* An Icinga service.
|
||||||
|
@ -51,7 +51,7 @@ public:
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
bool Get(String key, T *value) const
|
bool Get(String key, T *value) const
|
||||||
{
|
{
|
||||||
Value v =GetDictionary()->Get(key);
|
Value v = GetDictionary()->Get(key);
|
||||||
|
|
||||||
if (v.IsEmpty())
|
if (v.IsEmpty())
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user