2013-06-21 10:20:29 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* 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/service.h"
|
|
|
|
#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/tuple/tuple.hpp>
|
|
|
|
#include <boost/smart_ptr/make_shared.hpp>
|
|
|
|
#include <boost/foreach.hpp>
|
|
|
|
|
|
|
|
using namespace icinga;
|
|
|
|
|
|
|
|
#define FLAPPING_INTERVAL (30 * 60)
|
|
|
|
|
2013-06-21 10:28:21 +02:00
|
|
|
bool Service::GetEnableFlapping(void) const
|
|
|
|
{
|
|
|
|
if (m_EnableFlapping.IsEmpty())
|
|
|
|
return true;
|
|
|
|
else
|
|
|
|
return m_EnableFlapping;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void Service::SetEnableFlapping(bool enabled)
|
|
|
|
{
|
|
|
|
m_EnableFlapping = enabled ? 1 : 0;
|
|
|
|
Touch("enable_flapping");
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
if (m_FlappingLastChange.IsEmpty()) {
|
|
|
|
ts = now;
|
2013-06-21 12:51:29 +02:00
|
|
|
positive = 0;
|
|
|
|
negative = 0;
|
2013-06-21 10:20:29 +02:00
|
|
|
} else {
|
|
|
|
ts = m_FlappingLastChange;
|
2013-06-21 12:51:29 +02:00
|
|
|
positive = m_FlappingPositive;
|
|
|
|
negative = m_FlappingNegative;
|
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;
|
|
|
|
|
|
|
|
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-06-21 12:51:29 +02:00
|
|
|
m_FlappingPositive = positive;
|
|
|
|
Touch("flapping_positive");
|
|
|
|
|
|
|
|
m_FlappingNegative = negative;
|
|
|
|
Touch("flapping_negative");
|
2013-06-21 10:20:29 +02:00
|
|
|
|
|
|
|
m_FlappingLastChange = now;
|
|
|
|
Touch("flapping_lastchange");
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Service::IsFlapping(void) const
|
|
|
|
{
|
2013-06-21 12:51:29 +02:00
|
|
|
double threshold = 20;
|
2013-06-21 10:20:29 +02:00
|
|
|
|
|
|
|
if (!m_FlappingThreshold.IsEmpty())
|
|
|
|
threshold = m_FlappingThreshold;
|
|
|
|
|
2013-06-21 12:51:29 +02:00
|
|
|
if (m_FlappingNegative.IsEmpty() || m_FlappingPositive.IsEmpty())
|
2013-06-21 10:20:29 +02:00
|
|
|
return false;
|
|
|
|
|
2013-06-21 12:51:29 +02:00
|
|
|
return (m_FlappingPositive > threshold * (m_FlappingPositive + m_FlappingNegative) / 100);
|
2013-06-21 10:20:29 +02:00
|
|
|
|
|
|
|
}
|