2013-06-21 10:20:29 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* Icinga 2 *
|
2013-09-25 07:43:57 +02:00
|
|
|
* Copyright (C) 2012-2013 Icinga Development Team (http://www.icinga.org/) *
|
2013-06-21 10:20:29 +02:00
|
|
|
* *
|
|
|
|
* 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/service.h"
|
2013-10-08 11:57:35 +02:00
|
|
|
#include "icinga/icingaapplication.h"
|
2013-06-21 10:20:29 +02:00
|
|
|
#include "base/dynamictype.h"
|
|
|
|
#include "base/objectlock.h"
|
|
|
|
#include "base/logger_fwd.h"
|
|
|
|
#include "base/timer.h"
|
|
|
|
#include "base/utility.h"
|
2013-06-21 12:51:29 +02:00
|
|
|
#include "base/convert.h"
|
2013-06-21 10:20:29 +02:00
|
|
|
#include <boost/foreach.hpp>
|
|
|
|
|
|
|
|
using namespace icinga;
|
|
|
|
|
|
|
|
#define FLAPPING_INTERVAL (30 * 60)
|
|
|
|
|
2013-07-01 14:39:43 +02:00
|
|
|
double Service::GetFlappingCurrent(void) const
|
|
|
|
{
|
2013-10-26 09:41:45 +02:00
|
|
|
if (GetFlappingPositive() + GetFlappingNegative() <= 0)
|
2013-07-01 17:25:30 +02:00
|
|
|
return 0;
|
|
|
|
|
2013-10-26 09:41:45 +02:00
|
|
|
return 100 * GetFlappingPositive() / (GetFlappingPositive() + GetFlappingNegative());
|
2013-07-01 14:30:19 +02:00
|
|
|
}
|
|
|
|
|
2013-06-21 10:28:21 +02:00
|
|
|
bool Service::GetEnableFlapping(void) const
|
|
|
|
{
|
2013-11-26 11:34:33 +01:00
|
|
|
if (!GetOverrideEnableFlapping().IsEmpty())
|
|
|
|
return GetOverrideEnableFlapping();
|
|
|
|
else
|
|
|
|
return GetEnableFlappingRaw();
|
2013-06-21 10:28:21 +02:00
|
|
|
}
|
|
|
|
|
2013-08-29 13:06:36 +02:00
|
|
|
void Service::SetEnableFlapping(bool enabled, const String& authority)
|
2013-06-21 10:28:21 +02:00
|
|
|
{
|
2013-11-26 11:34:33 +01:00
|
|
|
SetOverrideEnableFlapping(enabled);
|
2013-08-29 13:06:36 +02:00
|
|
|
|
|
|
|
OnFlappingChanged(GetSelf(), enabled ? FlappingEnabled : FlappingDisabled);
|
2013-11-10 16:53:57 +01:00
|
|
|
OnEnableFlappingChanged(GetSelf(), enabled, authority);
|
2013-06-21 10:28:21 +02:00
|
|
|
}
|
|
|
|
|
2013-06-21 10:20:29 +02:00
|
|
|
void Service::UpdateFlappingStatus(bool stateChange)
|
|
|
|
{
|
|
|
|
double ts, now;
|
2013-06-21 12:51:29 +02:00
|
|
|
long positive, negative;
|
2013-06-21 10:20:29 +02:00
|
|
|
|
|
|
|
now = Utility::GetTime();
|
|
|
|
|
2013-10-26 09:41:45 +02:00
|
|
|
ts = GetFlappingLastChange();
|
|
|
|
positive = GetFlappingPositive();
|
|
|
|
negative = GetFlappingNegative();
|
2013-06-21 10:20:29 +02:00
|
|
|
|
|
|
|
double diff = now - ts;
|
|
|
|
|
2013-06-21 12:51:29 +02:00
|
|
|
if (positive + negative > FLAPPING_INTERVAL) {
|
|
|
|
double pct = (positive + negative - FLAPPING_INTERVAL) / FLAPPING_INTERVAL;
|
|
|
|
positive -= pct * positive;
|
|
|
|
negative -= pct * negative;
|
|
|
|
}
|
2013-06-21 10:20:29 +02:00
|
|
|
|
|
|
|
if (stateChange)
|
2013-06-21 12:51:29 +02:00
|
|
|
positive += diff;
|
|
|
|
else
|
|
|
|
negative += diff;
|
|
|
|
|
2013-06-26 08:52:06 +02:00
|
|
|
if (positive < 0)
|
|
|
|
positive = 0;
|
|
|
|
|
|
|
|
if (negative < 0)
|
|
|
|
negative = 0;
|
|
|
|
|
2013-09-21 09:00:40 +02:00
|
|
|
// Log(LogDebug, "icinga", "Flapping counter for '" + GetName() + "' is positive=" + Convert::ToString(positive) + ", negative=" + Convert::ToString(negative));
|
2013-06-21 10:20:29 +02:00
|
|
|
|
2013-10-26 09:41:45 +02:00
|
|
|
SetFlappingLastChange(now);
|
|
|
|
SetFlappingPositive(positive);
|
|
|
|
SetFlappingNegative(negative);
|
2013-06-21 10:20:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Service::IsFlapping(void) const
|
|
|
|
{
|
2013-10-08 11:57:35 +02:00
|
|
|
if (!GetEnableFlapping() || !IcingaApplication::GetInstance()->GetEnableFlapping())
|
2013-08-29 14:13:18 +02:00
|
|
|
return false;
|
|
|
|
else
|
|
|
|
return GetFlappingCurrent() > GetFlappingThreshold();
|
2013-06-21 10:20:29 +02:00
|
|
|
}
|