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));
}
}
+/**
+ * @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)
{
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);
eventcommand.h \
externalcommandprocessor.cpp \
externalcommandprocessor.h \
+ flappingmessage.cpp \
+ flappingmessage.h \
host.cpp \
hostgroup.cpp \
hostgroup.h \
#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>
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);
}
}
--- /dev/null
+/******************************************************************************
+ * 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);
+}
--- /dev/null
+/******************************************************************************
+ * 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 */
<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">
<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" />
<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>
<ClInclude Include="downtimemessage.h">
<Filter>Headerdateien</Filter>
</ClInclude>
+ <ClInclude Include="flappingmessage.h">
+ <Filter>Headerdateien</Filter>
+ </ClInclude>
<ClInclude Include="pluginnotificationtask.h">
<Filter>Headerdateien</Filter>
</ClInclude>
#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"
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
{
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);
}
******************************************************************************/
#include "icinga/service.h"
+#include "icinga/flappingmessage.h"
#include "base/dynamictype.h"
#include "base/objectlock.h"
#include "base/logger_fwd.h"
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())
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)
DowntimeStopped = 2
};
+/**
+ * The sate of service flapping.
+ *
+ * @ingroup icinga
+ */
+enum FlappingState
+{
+ FlappingStarted = 0,
+ FlappingDisabled = 1,
+ FlappingStopped = 2
+};
+
class CheckCommand;
class EventCommand;
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;
Attribute<long> m_FlappingNegative;
Attribute<double> m_FlappingLastChange;
Attribute<double> m_FlappingThreshold;
+
+ static void FlappingRequestHandler(const RequestMessage& request);
};
}