2013-06-21 10:20:29 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* Icinga 2 *
|
2018-01-02 12:06:00 +01:00
|
|
|
* Copyright (C) 2012-2018 Icinga Development Team (https://www.icinga.com/) *
|
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. *
|
|
|
|
******************************************************************************/
|
|
|
|
|
2017-10-19 17:32:52 +02:00
|
|
|
#include <bitset>
|
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
|
|
|
|
|
|
|
using namespace icinga;
|
|
|
|
|
2014-04-03 15:36:13 +02:00
|
|
|
void Checkable::UpdateFlappingStatus(bool stateChange)
|
2013-06-21 10:20:29 +02:00
|
|
|
{
|
2017-11-17 12:59:07 +01:00
|
|
|
/* TODO: Add support for Windows satellites/masters. */
|
|
|
|
#ifndef _WIN32 /* _WIN32 */
|
2017-10-19 17:32:52 +02:00
|
|
|
std::bitset<20> stateChangeBuf = GetFlappingBuffer();
|
2017-11-03 17:50:59 +01:00
|
|
|
int oldestIndex = GetFlappingIndex();
|
2013-06-21 10:20:29 +02:00
|
|
|
|
2017-10-19 17:32:52 +02:00
|
|
|
stateChangeBuf[oldestIndex] = stateChange;
|
|
|
|
oldestIndex = (oldestIndex + 1) % 20;
|
2013-06-21 10:20:29 +02:00
|
|
|
|
2017-10-19 17:32:52 +02:00
|
|
|
double stateChanges = 0;
|
2013-06-21 10:20:29 +02:00
|
|
|
|
2017-11-03 17:50:59 +01:00
|
|
|
/* Iterate over our state array and compute a weighted total */
|
2017-10-19 17:32:52 +02:00
|
|
|
for (int i = 0; i < 20; i++) {
|
|
|
|
if (stateChangeBuf[(oldestIndex + i) % 20])
|
|
|
|
stateChanges += 0.8 + (0.02 * i);
|
2013-06-21 12:51:29 +02:00
|
|
|
}
|
2013-06-21 10:20:29 +02:00
|
|
|
|
2017-10-19 17:32:52 +02:00
|
|
|
double flappingValue = 100.0 * stateChanges / 20.0;
|
2013-06-21 12:51:29 +02:00
|
|
|
|
2017-10-19 17:32:52 +02:00
|
|
|
bool flapping;
|
2013-06-26 08:52:06 +02:00
|
|
|
|
2017-10-19 17:32:52 +02:00
|
|
|
if (GetFlapping())
|
|
|
|
flapping = flappingValue > GetFlappingThresholdLow();
|
|
|
|
else
|
|
|
|
flapping = flappingValue > GetFlappingThresholdHigh();
|
2013-06-26 08:52:06 +02:00
|
|
|
|
2017-11-03 17:50:59 +01:00
|
|
|
SetFlappingBuffer(stateChangeBuf.to_ulong());
|
|
|
|
SetFlappingIndex(oldestIndex);
|
|
|
|
SetFlappingCurrent(flappingValue);
|
|
|
|
SetFlapping(flapping, true);
|
|
|
|
|
2017-10-19 17:32:52 +02:00
|
|
|
if (flapping != GetFlapping())
|
|
|
|
SetFlappingLastChange(Utility::GetTime());
|
2017-11-17 12:59:07 +01:00
|
|
|
|
|
|
|
#endif /* _WIN32 */
|
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
|
2017-10-19 17:32:52 +02:00
|
|
|
return GetFlapping();
|
2013-06-21 10:20:29 +02:00
|
|
|
}
|