1 /******************************************************************************
3 * Copyright (C) 2012-2018 Icinga Development Team (https://www.icinga.com/) *
5 * This program is free software; you can redistribute it and/or *
6 * modify it under the terms of the GNU General Public License *
7 * as published by the Free Software Foundation; either version 2 *
8 * of the License, or (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the Free Software Foundation *
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
18 ******************************************************************************/
21 #include "icinga/checkable.hpp"
22 #include "icinga/icingaapplication.hpp"
23 #include "base/utility.hpp"
25 using namespace icinga;
27 void Checkable::UpdateFlappingStatus(bool stateChange)
29 /* TODO: Add support for Windows satellites/masters. */
30 #ifndef _WIN32 /* _WIN32 */
31 std::bitset<20> stateChangeBuf = GetFlappingBuffer();
32 int oldestIndex = GetFlappingIndex();
34 stateChangeBuf[oldestIndex] = stateChange;
35 oldestIndex = (oldestIndex + 1) % 20;
37 double stateChanges = 0;
39 /* Iterate over our state array and compute a weighted total */
40 for (int i = 0; i < 20; i++) {
41 if (stateChangeBuf[(oldestIndex + i) % 20])
42 stateChanges += 0.8 + (0.02 * i);
45 double flappingValue = 100.0 * stateChanges / 20.0;
50 flapping = flappingValue > GetFlappingThresholdLow();
52 flapping = flappingValue > GetFlappingThresholdHigh();
54 SetFlappingBuffer(stateChangeBuf.to_ulong());
55 SetFlappingIndex(oldestIndex);
56 SetFlappingCurrent(flappingValue);
57 SetFlapping(flapping, true);
59 if (flapping != GetFlapping())
60 SetFlappingLastChange(Utility::GetTime());
65 bool Checkable::IsFlapping() const
67 if (!GetEnableFlapping() || !IcingaApplication::GetInstance()->GetEnableFlapping())