MCPcopy Create free account
hub / github.com/Icinga/icinga2 / UpdateFlappingStatus

Method UpdateFlappingStatus

lib/icinga/checkable-flapping.cpp:40–91  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

38};
39
40void Checkable::UpdateFlappingStatus(ServiceState newState)
41{
42 Bitset<unsigned long> stateChangeBuf = GetFlappingBuffer();
43 int oldestIndex = GetFlappingIndex();
44
45 ServiceState lastState = GetFlappingLastState();
46 bool stateChange = false;
47
48 int stateFilter = GetFlappingIgnoreStatesFilter();
49
50 /* Only count as state change if no state filter is set or the new state isn't filtered out */
51 if (stateFilter == -1 || !(ServiceStateToFlappingFilter(newState) & stateFilter)) {
52 stateChange = newState != lastState;
53 SetFlappingLastState(newState);
54 }
55
56 stateChangeBuf.Modify(oldestIndex, stateChange);
57 oldestIndex = (oldestIndex + 1) % 20;
58
59 double stateChanges = 0;
60
61 /* Iterate over our state array and compute a weighted total */
62 for (int i = 0; i < 20; i++) {
63 if (stateChangeBuf.Get((oldestIndex + i) % 20))
64 stateChanges += 0.8 + (0.02 * i);
65 }
66
67 double flappingValue = 100.0 * stateChanges / 20.0;
68
69 bool flapping;
70
71 if (GetFlapping())
72 flapping = flappingValue > GetFlappingThresholdLow();
73 else
74 flapping = flappingValue > GetFlappingThresholdHigh();
75
76 SetFlappingBuffer(stateChangeBuf.GetValue());
77 SetFlappingIndex(oldestIndex);
78 SetFlappingCurrent(flappingValue);
79
80 if (flapping != GetFlapping()) {
81 SetFlapping(flapping, true);
82
83 double ee = GetLastCheckResult()->GetExecutionEnd();
84
85 if (GetEnableFlapping() && IcingaApplication::GetInstance()->GetEnableFlapping()) {
86 OnFlappingChange(this, ee);
87 }
88
89 SetFlappingLastChange(ee);
90 }
91}
92
93bool Checkable::IsFlapping() const
94{

Callers

nothing calls this directly

Calls 3

ModifyMethod · 0.80
GetMethod · 0.45
GetValueMethod · 0.45

Tested by

no test coverage detected