2013-06-21 10:20:29 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* Icinga 2 *
|
2014-03-19 01:02:29 +01:00
|
|
|
* Copyright (C) 2012-2014 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. *
|
|
|
|
******************************************************************************/
|
|
|
|
|
2014-05-25 16:23:35 +02:00
|
|
|
#include "icinga/checkable.hpp"
|
|
|
|
#include "icinga/icingaapplication.hpp"
|
|
|
|
#include "base/utility.hpp"
|
2013-06-21 10:20:29 +02:00
|
|
|
#include <boost/foreach.hpp>
|
|
|
|
|
|
|
|
using namespace icinga;
|
|
|
|
|
|
|
|
#define FLAPPING_INTERVAL (30 * 60)
|
|
|
|
|
2014-04-03 15:36:13 +02:00
|
|
|
double Checkable::GetFlappingCurrent(void) const
|
2013-07-01 14:39:43 +02:00
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
2014-04-03 15:36:13 +02:00
|
|
|
bool Checkable::GetEnableFlapping(void) const
|
2013-06-21 10:28:21 +02:00
|
|
|
{
|
2013-11-26 11:34:33 +01:00
|
|
|
if (!GetOverrideEnableFlapping().IsEmpty())
|
|
|
|
return GetOverrideEnableFlapping();
|
|
|
|
else
|
|
|
|
return GetEnableFlappingRaw();
|
2013-06-21 10:28:21 +02:00
|
|
|
}
|
|
|
|
|
2014-05-03 20:02:22 +02:00
|
|
|
void Checkable::SetEnableFlapping(bool enabled, const MessageOrigin& origin)
|
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);
|
2014-05-03 20:02:22 +02:00
|
|
|
OnEnableFlappingChanged(GetSelf(), enabled, origin);
|
2013-06-21 10:28:21 +02:00
|
|
|
}
|
|
|
|
|
2014-04-03 15:36:13 +02:00
|
|
|
void Checkable::UpdateFlappingStatus(bool stateChange)
|
2013-06-21 10:20:29 +02:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
2014-05-28 13:45:45 +02:00
|
|
|
// Log(LogDebug, "Checkable", "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
|
|
|
}
|
|
|
|
|
2014-04-03 15:36:13 +02:00
|
|
|
bool Checkable::IsFlapping(void) const
|
2013-06-21 10:20:29 +02:00
|
|
|
{
|
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
|
|
|
}
|