1 /******************************************************************************
3 * Copyright (C) 2012-2016 Icinga Development Team (https://www.icinga.org/) *
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 ******************************************************************************/
20 #include "icinga/checkable.hpp"
21 #include "icinga/icingaapplication.hpp"
22 #include "base/utility.hpp"
23 #include <boost/foreach.hpp>
25 using namespace icinga;
27 #define FLAPPING_INTERVAL (30 * 60)
29 double Checkable::GetFlappingCurrent(void) const
31 if (GetFlappingPositive() + GetFlappingNegative() <= 0)
34 return 100 * GetFlappingPositive() / (GetFlappingPositive() + GetFlappingNegative());
37 void Checkable::UpdateFlappingStatus(bool stateChange)
40 long positive, negative;
42 now = Utility::GetTime();
44 ts = GetFlappingLastChange();
45 positive = GetFlappingPositive();
46 negative = GetFlappingNegative();
48 double diff = now - ts;
50 if (positive + negative > FLAPPING_INTERVAL) {
51 double pct = (positive + negative - FLAPPING_INTERVAL) / FLAPPING_INTERVAL;
52 positive -= pct * positive;
53 negative -= pct * negative;
67 // Log(LogDebug, "Checkable")
68 // << "Flapping counter for '" << GetName() << "' is positive=" << positive << ", negative=" << negative;
70 SetFlappingLastChange(now);
71 SetFlappingPositive(positive);
72 SetFlappingNegative(negative);
75 bool Checkable::IsFlapping(void) const
77 if (!GetEnableFlapping() || !IcingaApplication::GetInstance()->GetEnableFlapping())
80 return GetFlappingCurrent() > GetFlappingThreshold();