mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-26 23:24:09 +02:00
add downtime message (started,stopped,cancelled) and compat logger
refs #3985 refs #2750
This commit is contained in:
parent
6f3d60a647
commit
147cd81328
@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
#include "compat/compatlog.h"
|
#include "compat/compatlog.h"
|
||||||
#include "icinga/checkresultmessage.h"
|
#include "icinga/checkresultmessage.h"
|
||||||
|
#include "icinga/downtimemessage.h"
|
||||||
#include "icinga/service.h"
|
#include "icinga/service.h"
|
||||||
#include "icinga/macroprocessor.h"
|
#include "icinga/macroprocessor.h"
|
||||||
#include "config/configcompilercontext.h"
|
#include "config/configcompilercontext.h"
|
||||||
@ -64,6 +65,8 @@ void CompatLog::Start(void)
|
|||||||
m_Endpoint = Endpoint::MakeEndpoint("compatlog_" + GetName(), false);
|
m_Endpoint = Endpoint::MakeEndpoint("compatlog_" + GetName(), false);
|
||||||
m_Endpoint->RegisterTopicHandler("checker::CheckResult",
|
m_Endpoint->RegisterTopicHandler("checker::CheckResult",
|
||||||
boost::bind(&CompatLog::CheckResultRequestHandler, this, _3));
|
boost::bind(&CompatLog::CheckResultRequestHandler, this, _3));
|
||||||
|
m_Endpoint->RegisterTopicHandler("icinga::Downtime",
|
||||||
|
boost::bind(&CompatLog::DowntimeRequestHandler, this, _3));
|
||||||
|
|
||||||
m_RotationTimer = boost::make_shared<Timer>();
|
m_RotationTimer = boost::make_shared<Timer>();
|
||||||
m_RotationTimer->OnTimerExpired.connect(boost::bind(&CompatLog::RotationTimerHandler, this));
|
m_RotationTimer->OnTimerExpired.connect(boost::bind(&CompatLog::RotationTimerHandler, this));
|
||||||
@ -197,6 +200,78 @@ void CompatLog::CheckResultRequestHandler(const RequestMessage& request)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @threadsafety Always.
|
||||||
|
*/
|
||||||
|
void CompatLog::DowntimeRequestHandler(const RequestMessage& request)
|
||||||
|
{
|
||||||
|
DowntimeMessage params;
|
||||||
|
if (!request.GetParams(¶ms))
|
||||||
|
return;
|
||||||
|
|
||||||
|
String svcname = params.GetService();
|
||||||
|
Service::Ptr service = Service::GetByName(svcname);
|
||||||
|
|
||||||
|
Host::Ptr host = service->GetHost();
|
||||||
|
|
||||||
|
if (!host)
|
||||||
|
return;
|
||||||
|
|
||||||
|
DowntimeState downtime_state = params.GetState();
|
||||||
|
String downtime_state_str;
|
||||||
|
String downtime_output;
|
||||||
|
|
||||||
|
switch (downtime_state) {
|
||||||
|
case DowntimeStarted:
|
||||||
|
downtime_output = "Service has entered a period of scheduled downtime.";
|
||||||
|
downtime_state_str = "STARTED";
|
||||||
|
break;
|
||||||
|
case DowntimeStopped:
|
||||||
|
downtime_output = "Service has exited from a period of scheduled downtime.";
|
||||||
|
downtime_state_str = "STOPPED";
|
||||||
|
break;
|
||||||
|
case DowntimeCancelled:
|
||||||
|
downtime_output = "Scheduled downtime for service has been cancelled.";
|
||||||
|
downtime_state_str = "CANCELLED";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
Log(LogCritical, "compat", "Unknown downtime state: " + Convert::ToString(downtime_state));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::ostringstream msgbuf;
|
||||||
|
msgbuf << "SERVICE DOWNTIME ALERT: "
|
||||||
|
<< host->GetName() << ";"
|
||||||
|
<< service->GetShortName() << ";"
|
||||||
|
<< downtime_state_str << "; "
|
||||||
|
<< downtime_output
|
||||||
|
<< "";
|
||||||
|
|
||||||
|
{
|
||||||
|
ObjectLock oLock(this);
|
||||||
|
WriteLine(msgbuf.str());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (service == host->GetHostCheckService()) {
|
||||||
|
std::ostringstream msgbuf;
|
||||||
|
msgbuf << "HOST DOWNTIME ALERT: "
|
||||||
|
<< host->GetName() << ";"
|
||||||
|
<< downtime_state_str << "; "
|
||||||
|
<< downtime_output
|
||||||
|
<< "";
|
||||||
|
|
||||||
|
{
|
||||||
|
ObjectLock oLock(this);
|
||||||
|
WriteLine(msgbuf.str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
ObjectLock oLock(this);
|
||||||
|
Flush();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void CompatLog::WriteLine(const String& line)
|
void CompatLog::WriteLine(const String& line)
|
||||||
{
|
{
|
||||||
ASSERT(OwnsLock());
|
ASSERT(OwnsLock());
|
||||||
|
@ -63,6 +63,7 @@ private:
|
|||||||
|
|
||||||
Endpoint::Ptr m_Endpoint;
|
Endpoint::Ptr m_Endpoint;
|
||||||
void CheckResultRequestHandler(const RequestMessage& request);
|
void CheckResultRequestHandler(const RequestMessage& request);
|
||||||
|
void DowntimeRequestHandler(const RequestMessage& request);
|
||||||
|
|
||||||
Timer::Ptr m_RotationTimer;
|
Timer::Ptr m_RotationTimer;
|
||||||
void RotationTimerHandler(void);
|
void RotationTimerHandler(void);
|
||||||
|
@ -21,6 +21,8 @@ libicinga_la_SOURCES = \
|
|||||||
cib.h \
|
cib.h \
|
||||||
command.cpp \
|
command.cpp \
|
||||||
command.h \
|
command.h \
|
||||||
|
downtimemessage.cpp \
|
||||||
|
downtimemessage.h \
|
||||||
eventcommand.cpp \
|
eventcommand.cpp \
|
||||||
eventcommand.h \
|
eventcommand.h \
|
||||||
externalcommandprocessor.cpp \
|
externalcommandprocessor.cpp \
|
||||||
|
46
lib/icinga/downtimemessage.cpp
Normal file
46
lib/icinga/downtimemessage.cpp
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
/******************************************************************************
|
||||||
|
* Icinga 2 *
|
||||||
|
* Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/) *
|
||||||
|
* *
|
||||||
|
* This program is free software; you can redistribute it and/or *
|
||||||
|
* modify it under the terms of the GNU General Public License *
|
||||||
|
* as published by the Free Software Foundation; either version 2 *
|
||||||
|
* of the License, or (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* This program is distributed in the hope that it will be useful, *
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||||
|
* GNU General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU General Public License *
|
||||||
|
* along with this program; if not, write to the Free Software Foundation *
|
||||||
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
#include "icinga/downtimemessage.h"
|
||||||
|
|
||||||
|
using namespace icinga;
|
||||||
|
|
||||||
|
String DowntimeMessage::GetService(void) const
|
||||||
|
{
|
||||||
|
String service;
|
||||||
|
Get("service", &service);
|
||||||
|
return service;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DowntimeMessage::SetService(const String& service)
|
||||||
|
{
|
||||||
|
Set("service", service);
|
||||||
|
}
|
||||||
|
|
||||||
|
DowntimeState DowntimeMessage::GetState(void) const
|
||||||
|
{
|
||||||
|
long state;
|
||||||
|
Get("state", &state);
|
||||||
|
return static_cast<DowntimeState>(state);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DowntimeMessage::SetState(DowntimeState state)
|
||||||
|
{
|
||||||
|
Set("state", state);
|
||||||
|
}
|
50
lib/icinga/downtimemessage.h
Normal file
50
lib/icinga/downtimemessage.h
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
/******************************************************************************
|
||||||
|
* Icinga 2 *
|
||||||
|
* Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/) *
|
||||||
|
* *
|
||||||
|
* This program is free software; you can redistribute it and/or *
|
||||||
|
* modify it under the terms of the GNU General Public License *
|
||||||
|
* as published by the Free Software Foundation; either version 2 *
|
||||||
|
* of the License, or (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* This program is distributed in the hope that it will be useful, *
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||||
|
* GNU General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU General Public License *
|
||||||
|
* along with this program; if not, write to the Free Software Foundation *
|
||||||
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
#ifndef DOWNTIMEMESSAGE_H
|
||||||
|
#define DOWNTIMEMESSAGE_H
|
||||||
|
|
||||||
|
#include "icinga/i2-icinga.h"
|
||||||
|
#include "icinga/service.h"
|
||||||
|
#include "remoting/messagepart.h"
|
||||||
|
|
||||||
|
namespace icinga
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A state change message for a service.
|
||||||
|
*
|
||||||
|
* @ingroup icinga
|
||||||
|
*/
|
||||||
|
class I2_ICINGA_API DowntimeMessage : public MessagePart
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
DowntimeMessage(void) : MessagePart() { }
|
||||||
|
explicit DowntimeMessage(const MessagePart& message) : MessagePart(message) { }
|
||||||
|
|
||||||
|
String GetService(void) const;
|
||||||
|
void SetService(const String& service);
|
||||||
|
|
||||||
|
DowntimeState GetState(void) const;
|
||||||
|
void SetState(DowntimeState state);
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* DOWNTIMEMESSAGE_H */
|
@ -22,6 +22,7 @@
|
|||||||
<ClCompile Include="api.cpp" />
|
<ClCompile Include="api.cpp" />
|
||||||
<ClCompile Include="checkresultmessage.cpp" />
|
<ClCompile Include="checkresultmessage.cpp" />
|
||||||
<ClCompile Include="cib.cpp" />
|
<ClCompile Include="cib.cpp" />
|
||||||
|
<ClCompile Include="downtimemessage.cpp" />
|
||||||
<ClCompile Include="externalcommandprocessor.cpp" />
|
<ClCompile Include="externalcommandprocessor.cpp" />
|
||||||
<ClCompile Include="host.cpp" />
|
<ClCompile Include="host.cpp" />
|
||||||
<ClCompile Include="hostgroup.cpp" />
|
<ClCompile Include="hostgroup.cpp" />
|
||||||
@ -54,6 +55,7 @@
|
|||||||
<ClInclude Include="api.h" />
|
<ClInclude Include="api.h" />
|
||||||
<ClInclude Include="checkresultmessage.h" />
|
<ClInclude Include="checkresultmessage.h" />
|
||||||
<ClInclude Include="cib.h" />
|
<ClInclude Include="cib.h" />
|
||||||
|
<ClInclude Include="downtimemessage.h" />
|
||||||
<ClInclude Include="externalcommandprocessor.h" />
|
<ClInclude Include="externalcommandprocessor.h" />
|
||||||
<ClInclude Include="host.h" />
|
<ClInclude Include="host.h" />
|
||||||
<ClInclude Include="hostgroup.h" />
|
<ClInclude Include="hostgroup.h" />
|
||||||
|
@ -34,6 +34,9 @@
|
|||||||
<ClCompile Include="checkresultmessage.cpp">
|
<ClCompile Include="checkresultmessage.cpp">
|
||||||
<Filter>Quelldateien</Filter>
|
<Filter>Quelldateien</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="downtimemessage.cpp">
|
||||||
|
<Filter>Quelldateien</Filter>
|
||||||
|
</ClCompile>
|
||||||
<ClCompile Include="service-comment.cpp">
|
<ClCompile Include="service-comment.cpp">
|
||||||
<Filter>Quelldateien</Filter>
|
<Filter>Quelldateien</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
@ -108,6 +111,9 @@
|
|||||||
<ClInclude Include="checkresultmessage.h">
|
<ClInclude Include="checkresultmessage.h">
|
||||||
<Filter>Headerdateien</Filter>
|
<Filter>Headerdateien</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="downtimemessage.h">
|
||||||
|
<Filter>Headerdateien</Filter>
|
||||||
|
</ClInclude>
|
||||||
<ClInclude Include="pluginnotificationtask.h">
|
<ClInclude Include="pluginnotificationtask.h">
|
||||||
<Filter>Headerdateien</Filter>
|
<Filter>Headerdateien</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
@ -18,6 +18,8 @@
|
|||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
#include "icinga/service.h"
|
#include "icinga/service.h"
|
||||||
|
#include "icinga/downtimemessage.h"
|
||||||
|
#include "remoting/endpointmanager.h"
|
||||||
#include "base/dynamictype.h"
|
#include "base/dynamictype.h"
|
||||||
#include "base/objectlock.h"
|
#include "base/objectlock.h"
|
||||||
#include "base/logger_fwd.h"
|
#include "base/logger_fwd.h"
|
||||||
@ -127,7 +129,20 @@ void Service::RemoveDowntime(const String& id)
|
|||||||
|
|
||||||
{
|
{
|
||||||
ObjectLock olock(owner);
|
ObjectLock olock(owner);
|
||||||
|
|
||||||
downtimes->Remove(id);
|
downtimes->Remove(id);
|
||||||
|
|
||||||
|
RequestMessage rm;
|
||||||
|
rm.SetMethod("icinga::Downtime");
|
||||||
|
|
||||||
|
DowntimeMessage params;
|
||||||
|
params.SetService(owner->GetName());
|
||||||
|
params.SetState(DowntimeCancelled);
|
||||||
|
|
||||||
|
rm.SetParams(params);
|
||||||
|
|
||||||
|
EndpointManager::GetInstance()->SendMulticastMessage(rm);
|
||||||
|
|
||||||
owner->Touch("downtimes");
|
owner->Touch("downtimes");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -180,6 +195,17 @@ void Service::TriggerDowntime(const String& id)
|
|||||||
TriggerDowntime(tid);
|
TriggerDowntime(tid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RequestMessage rm;
|
||||||
|
rm.SetMethod("icinga::Downtime");
|
||||||
|
|
||||||
|
DowntimeMessage params;
|
||||||
|
params.SetService(owner->GetName());
|
||||||
|
params.SetState(DowntimeStarted);
|
||||||
|
|
||||||
|
rm.SetParams(params);
|
||||||
|
|
||||||
|
EndpointManager::GetInstance()->SendMulticastMessage(rm);
|
||||||
|
|
||||||
owner->Touch("downtimes");
|
owner->Touch("downtimes");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -339,6 +365,17 @@ void Service::RemoveExpiredDowntimes(void)
|
|||||||
|
|
||||||
if (!expiredDowntimes.empty()) {
|
if (!expiredDowntimes.empty()) {
|
||||||
BOOST_FOREACH(const String& id, expiredDowntimes) {
|
BOOST_FOREACH(const String& id, expiredDowntimes) {
|
||||||
|
RequestMessage rm;
|
||||||
|
rm.SetMethod("icinga::Downtime");
|
||||||
|
|
||||||
|
DowntimeMessage params;
|
||||||
|
params.SetService(GetName());
|
||||||
|
params.SetState(DowntimeStopped);
|
||||||
|
|
||||||
|
rm.SetParams(params);
|
||||||
|
|
||||||
|
EndpointManager::GetInstance()->SendMulticastMessage(rm);
|
||||||
|
|
||||||
downtimes->Remove(id);
|
downtimes->Remove(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,6 +57,18 @@ enum CommentType
|
|||||||
CommentAcknowledgement = 4
|
CommentAcknowledgement = 4
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The state of a service downtime.
|
||||||
|
*
|
||||||
|
* @ingroup icinga
|
||||||
|
*/
|
||||||
|
enum DowntimeState
|
||||||
|
{
|
||||||
|
DowntimeStarted = 0,
|
||||||
|
DowntimeCancelled = 1,
|
||||||
|
DowntimeStopped = 2
|
||||||
|
};
|
||||||
|
|
||||||
class CheckCommand;
|
class CheckCommand;
|
||||||
class EventCommand;
|
class EventCommand;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user