1 /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
3 #include "icinga/checkable.hpp"
4 #include "icinga/icingaapplication.hpp"
5 #include "base/utility.hpp"
7 using namespace icinga;
17 void Modify(int index, bool bit)
22 m_Data &= ~(1 << index);
25 bool Get(int index) const
27 return m_Data & (1 << index);
39 void Checkable::UpdateFlappingStatus(bool stateChange)
41 Bitset<unsigned long> stateChangeBuf = GetFlappingBuffer();
42 int oldestIndex = GetFlappingIndex();
44 stateChangeBuf.Modify(oldestIndex, stateChange);
45 oldestIndex = (oldestIndex + 1) % 20;
47 double stateChanges = 0;
49 /* Iterate over our state array and compute a weighted total */
50 for (int i = 0; i < 20; i++) {
51 if (stateChangeBuf.Get((oldestIndex + i) % 20))
52 stateChanges += 0.8 + (0.02 * i);
55 double flappingValue = 100.0 * stateChanges / 20.0;
60 flapping = flappingValue > GetFlappingThresholdLow();
62 flapping = flappingValue > GetFlappingThresholdHigh();
64 SetFlappingBuffer(stateChangeBuf.GetValue());
65 SetFlappingIndex(oldestIndex);
66 SetFlappingCurrent(flappingValue);
67 SetFlapping(flapping, true);
69 if (flapping != GetFlapping())
70 SetFlappingLastChange(Utility::GetTime());
73 bool Checkable::IsFlapping() const
75 if (!GetEnableFlapping() || !IcingaApplication::GetInstance()->GetEnableFlapping())