mirror of
https://github.com/Icinga/icinga2.git
synced 2025-04-08 17:05:25 +02:00
parent
bdd0ee013c
commit
4de7908b94
@ -72,6 +72,7 @@ void CompatLog::Start(void)
|
||||
boost::bind(&CompatLog::NotificationSentRequestHandler, this, _3));
|
||||
|
||||
Service::OnDowntimeChanged.connect(bind(&CompatLog::DowntimeHandler, this, _1, _2));
|
||||
Service::OnFlappingChanged.connect(bind(&CompatLog::FlappingHandler, this, _1, _2));
|
||||
|
||||
m_RotationTimer = boost::make_shared<Timer>();
|
||||
m_RotationTimer->OnTimerExpired.connect(boost::bind(&CompatLog::RotationTimerHandler, this));
|
||||
@ -357,6 +358,70 @@ void CompatLog::NotificationSentRequestHandler(const RequestMessage& request)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @threadsafety Always.
|
||||
*/
|
||||
void CompatLog::FlappingHandler(const Service::Ptr& service, FlappingState flapping_state)
|
||||
{
|
||||
Host::Ptr host = service->GetHost();
|
||||
|
||||
if (!host)
|
||||
return;
|
||||
|
||||
String flapping_state_str;
|
||||
String flapping_output;
|
||||
|
||||
switch (flapping_state) {
|
||||
case FlappingStarted:
|
||||
flapping_output = "Service appears to have started flapping (00.0% change >= 00.0% threshold)";
|
||||
flapping_state_str = "STARTED";
|
||||
break;
|
||||
case FlappingStopped:
|
||||
flapping_output = "Service appears to have stopped flapping (00.0% change < 00.1% threshold)";
|
||||
flapping_state_str = "STOPPED";
|
||||
break;
|
||||
case FlappingDisabled:
|
||||
flapping_output = "Flap detection has been disabled";
|
||||
flapping_state_str = "DISABLED";
|
||||
break;
|
||||
default:
|
||||
Log(LogCritical, "compat", "Unknown flapping state: " + Convert::ToString(flapping_state));
|
||||
return;
|
||||
}
|
||||
|
||||
std::ostringstream msgbuf;
|
||||
msgbuf << "SERVICE FLAPPING ALERT: "
|
||||
<< host->GetName() << ";"
|
||||
<< service->GetShortName() << ";"
|
||||
<< flapping_state_str << "; "
|
||||
<< flapping_output
|
||||
<< "";
|
||||
|
||||
{
|
||||
ObjectLock oLock(this);
|
||||
WriteLine(msgbuf.str());
|
||||
}
|
||||
|
||||
if (service == host->GetHostCheckService()) {
|
||||
std::ostringstream msgbuf;
|
||||
msgbuf << "HOST FLAPPING ALERT: "
|
||||
<< host->GetName() << ";"
|
||||
<< flapping_state_str << "; "
|
||||
<< flapping_output
|
||||
<< "";
|
||||
|
||||
{
|
||||
ObjectLock oLock(this);
|
||||
WriteLine(msgbuf.str());
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
ObjectLock oLock(this);
|
||||
Flush();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void CompatLog::WriteLine(const String& line)
|
||||
{
|
||||
|
@ -66,6 +66,7 @@ private:
|
||||
void CheckResultRequestHandler(const RequestMessage& request);
|
||||
void NotificationSentRequestHandler(const RequestMessage& request);
|
||||
void DowntimeHandler(const Service::Ptr& service, DowntimeState downtime_state);
|
||||
void FlappingHandler(const Service::Ptr& service, FlappingState flapping_state);
|
||||
|
||||
Timer::Ptr m_RotationTimer;
|
||||
void RotationTimerHandler(void);
|
||||
|
@ -27,6 +27,8 @@ libicinga_la_SOURCES = \
|
||||
eventcommand.h \
|
||||
externalcommandprocessor.cpp \
|
||||
externalcommandprocessor.h \
|
||||
flappingmessage.cpp \
|
||||
flappingmessage.h \
|
||||
host.cpp \
|
||||
hostgroup.cpp \
|
||||
hostgroup.h \
|
||||
|
@ -24,11 +24,13 @@
|
||||
#include "icinga/hostgroup.h"
|
||||
#include "icinga/servicegroup.h"
|
||||
#include "icinga/pluginchecktask.h"
|
||||
#include "icinga/flappingmessage.h"
|
||||
#include "base/convert.h"
|
||||
#include "base/logger_fwd.h"
|
||||
#include "base/objectlock.h"
|
||||
#include "base/application.h"
|
||||
#include "base/utility.h"
|
||||
#include "remoting/endpointmanager.h"
|
||||
#include <fstream>
|
||||
#include <boost/algorithm/string/classification.hpp>
|
||||
#include <boost/foreach.hpp>
|
||||
@ -1499,5 +1501,16 @@ void ExternalCommandProcessor::DisableSvcFlapping(double, const std::vector<Stri
|
||||
ObjectLock olock(service);
|
||||
|
||||
service->SetEnableFlapping(false);
|
||||
|
||||
RequestMessage rm;
|
||||
rm.SetMethod("icinga::Flapping");
|
||||
|
||||
FlappingMessage params;
|
||||
params.SetService(service->GetName());
|
||||
params.SetState(FlappingDisabled);
|
||||
|
||||
rm.SetParams(params);
|
||||
|
||||
EndpointManager::GetInstance()->SendMulticastMessage(rm);
|
||||
}
|
||||
}
|
||||
|
46
lib/icinga/flappingmessage.cpp
Normal file
46
lib/icinga/flappingmessage.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/flappingmessage.h"
|
||||
|
||||
using namespace icinga;
|
||||
|
||||
String FlappingMessage::GetService(void) const
|
||||
{
|
||||
String service;
|
||||
Get("service", &service);
|
||||
return service;
|
||||
}
|
||||
|
||||
void FlappingMessage::SetService(const String& service)
|
||||
{
|
||||
Set("service", service);
|
||||
}
|
||||
|
||||
FlappingState FlappingMessage::GetState(void) const
|
||||
{
|
||||
long state;
|
||||
Get("state", &state);
|
||||
return static_cast<FlappingState>(state);
|
||||
}
|
||||
|
||||
void FlappingMessage::SetState(FlappingState state)
|
||||
{
|
||||
Set("state", state);
|
||||
}
|
50
lib/icinga/flappingmessage.h
Normal file
50
lib/icinga/flappingmessage.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 FLAPPINGMESSAGE_H
|
||||
#define FLAPPINGMESSAGE_H
|
||||
|
||||
#include "icinga/i2-icinga.h"
|
||||
#include "icinga/service.h"
|
||||
#include "remoting/messagepart.h"
|
||||
|
||||
namespace icinga
|
||||
{
|
||||
|
||||
/**
|
||||
* A downtime message for a service.
|
||||
*
|
||||
* @ingroup icinga
|
||||
*/
|
||||
class I2_ICINGA_API FlappingMessage : public MessagePart
|
||||
{
|
||||
public:
|
||||
FlappingMessage(void) : MessagePart() { }
|
||||
explicit FlappingMessage(const MessagePart& message) : MessagePart(message) { }
|
||||
|
||||
String GetService(void) const;
|
||||
void SetService(const String& service);
|
||||
|
||||
FlappingState GetState(void) const;
|
||||
void SetState(FlappingState state);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif /* FLAPPINGMESSAGE_H */
|
@ -24,6 +24,7 @@
|
||||
<ClCompile Include="cib.cpp" />
|
||||
<ClCompile Include="downtimemessage.cpp" />
|
||||
<ClCompile Include="externalcommandprocessor.cpp" />
|
||||
<ClCompile Include="flappingmessage.cpp" />
|
||||
<ClCompile Include="host.cpp" />
|
||||
<ClCompile Include="hostgroup.cpp" />
|
||||
<ClCompile Include="icinga-type.cpp">
|
||||
@ -58,6 +59,7 @@
|
||||
<ClInclude Include="cib.h" />
|
||||
<ClInclude Include="downtimemessage.h" />
|
||||
<ClInclude Include="externalcommandprocessor.h" />
|
||||
<ClInclude Include="flappingmessage.h" />
|
||||
<ClInclude Include="host.h" />
|
||||
<ClInclude Include="hostgroup.h" />
|
||||
<ClInclude Include="i2-icinga.h" />
|
||||
|
@ -37,6 +37,9 @@
|
||||
<ClCompile Include="downtimemessage.cpp">
|
||||
<Filter>Quelldateien</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="flappingmessage.cpp">
|
||||
<Filter>Quelldateien</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="service-comment.cpp">
|
||||
<Filter>Quelldateien</Filter>
|
||||
</ClCompile>
|
||||
@ -117,6 +120,9 @@
|
||||
<ClInclude Include="downtimemessage.h">
|
||||
<Filter>Headerdateien</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="flappingmessage.h">
|
||||
<Filter>Headerdateien</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="pluginnotificationtask.h">
|
||||
<Filter>Headerdateien</Filter>
|
||||
</ClInclude>
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include "icinga/checkcommand.h"
|
||||
#include "icinga/icingaapplication.h"
|
||||
#include "icinga/checkresultmessage.h"
|
||||
#include "icinga/flappingmessage.h"
|
||||
#include "icinga/cib.h"
|
||||
#include "remoting/endpointmanager.h"
|
||||
#include "base/dynamictype.h"
|
||||
@ -38,6 +39,7 @@ const double Service::CheckIntervalDivisor = 5.0;
|
||||
|
||||
boost::signals2::signal<void (const Service::Ptr&)> Service::OnCheckerChanged;
|
||||
boost::signals2::signal<void (const Service::Ptr&)> Service::OnNextCheckChanged;
|
||||
boost::signals2::signal<void (const Service::Ptr&, FlappingState)> Service::OnFlappingChanged;
|
||||
|
||||
CheckCommand::Ptr Service::GetCheckCommand(void) const
|
||||
{
|
||||
@ -480,10 +482,34 @@ void Service::ProcessCheckResult(const Dictionary::Ptr& cr)
|
||||
if (send_downtime_notification)
|
||||
RequestNotifications(in_downtime ? NotificationDowntimeStart : NotificationDowntimeEnd, cr);
|
||||
|
||||
if (!was_flapping && is_flapping)
|
||||
if (!was_flapping && is_flapping) {
|
||||
RequestNotifications(NotificationFlappingStart, cr);
|
||||
else if (was_flapping && !is_flapping)
|
||||
|
||||
RequestMessage rm;
|
||||
rm.SetMethod("icinga::Flapping");
|
||||
|
||||
FlappingMessage params;
|
||||
params.SetService(GetName());
|
||||
params.SetState(FlappingStarted);
|
||||
|
||||
rm.SetParams(params);
|
||||
|
||||
EndpointManager::GetInstance()->SendMulticastMessage(rm);
|
||||
}
|
||||
else if (was_flapping && !is_flapping) {
|
||||
RequestNotifications(NotificationFlappingEnd, cr);
|
||||
|
||||
RequestMessage rm;
|
||||
rm.SetMethod("icinga::Flapping");
|
||||
|
||||
FlappingMessage params;
|
||||
params.SetService(GetName());
|
||||
params.SetState(FlappingStopped);
|
||||
|
||||
rm.SetParams(params);
|
||||
|
||||
EndpointManager::GetInstance()->SendMulticastMessage(rm);
|
||||
}
|
||||
else if (send_notification)
|
||||
RequestNotifications(recovery ? NotificationRecovery : NotificationProblem, cr);
|
||||
}
|
||||
|
@ -18,6 +18,7 @@
|
||||
******************************************************************************/
|
||||
|
||||
#include "icinga/service.h"
|
||||
#include "icinga/flappingmessage.h"
|
||||
#include "base/dynamictype.h"
|
||||
#include "base/objectlock.h"
|
||||
#include "base/logger_fwd.h"
|
||||
@ -48,6 +49,18 @@ double Service::GetFlappingThreshold(void) const
|
||||
return m_FlappingThreshold;
|
||||
}
|
||||
|
||||
void Service::FlappingRequestHandler(const RequestMessage& request)
|
||||
{
|
||||
FlappingMessage params;
|
||||
if (!request.GetParams(¶ms))
|
||||
return;
|
||||
|
||||
String svcname = params.GetService();
|
||||
Service::Ptr service = Service::GetByName(svcname);
|
||||
|
||||
OnFlappingChanged(service, params.GetState());
|
||||
}
|
||||
|
||||
bool Service::GetEnableFlapping(void) const
|
||||
{
|
||||
if (m_EnableFlapping.IsEmpty())
|
||||
|
@ -111,6 +111,8 @@ void Service::Initialize(void)
|
||||
m_Endpoint = Endpoint::MakeEndpoint("service", false);
|
||||
m_Endpoint->RegisterTopicHandler("icinga::Downtime",
|
||||
boost::bind(&Service::DowntimeRequestHandler, _3));
|
||||
m_Endpoint->RegisterTopicHandler("icinga::Flapping",
|
||||
boost::bind(&Service::FlappingRequestHandler, _3));
|
||||
}
|
||||
|
||||
void Service::OnRegistrationCompleted(void)
|
||||
|
@ -73,6 +73,18 @@ enum DowntimeState
|
||||
DowntimeStopped = 2
|
||||
};
|
||||
|
||||
/**
|
||||
* The sate of service flapping.
|
||||
*
|
||||
* @ingroup icinga
|
||||
*/
|
||||
enum FlappingState
|
||||
{
|
||||
FlappingStarted = 0,
|
||||
FlappingDisabled = 1,
|
||||
FlappingStopped = 2
|
||||
};
|
||||
|
||||
class CheckCommand;
|
||||
class EventCommand;
|
||||
|
||||
@ -196,6 +208,7 @@ public:
|
||||
static boost::signals2::signal<void (const Service::Ptr&)> OnCheckerChanged;
|
||||
static boost::signals2::signal<void (const Service::Ptr&)> OnNextCheckChanged;
|
||||
static boost::signals2::signal<void (const Service::Ptr&, DowntimeState)> OnDowntimeChanged;
|
||||
static boost::signals2::signal<void (const Service::Ptr&, FlappingState)> OnFlappingChanged;
|
||||
|
||||
virtual bool ResolveMacro(const String& macro, const Dictionary::Ptr& cr, String *result) const;
|
||||
|
||||
@ -359,6 +372,8 @@ private:
|
||||
Attribute<long> m_FlappingNegative;
|
||||
Attribute<double> m_FlappingLastChange;
|
||||
Attribute<double> m_FlappingThreshold;
|
||||
|
||||
static void FlappingRequestHandler(const RequestMessage& request);
|
||||
};
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user