Skip to content

Commit

Permalink
Fix flapping endianness and events
Browse files Browse the repository at this point in the history
fixes #5720
  • Loading branch information
Crunsher committed Nov 7, 2017
1 parent 36fddaf commit 73d73ee
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
3 changes: 3 additions & 0 deletions lib/icinga/apievents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@ void ApiEvents::FlappingChangedHandler(const Checkable::Ptr& checkable, const Me
result->Set("state", service ? static_cast<int>(service->GetState()) : static_cast<int>(host->GetState()));
result->Set("state_type", checkable->GetStateType());
result->Set("is_flapping", checkable->IsFlapping());
result->Set("flapping_current", checkable->GetFlappingCurrent());
result->Set("threshold_low", checkable->GetFlappingThresholdLow());
result->Set("threshold_high", checkable->GetFlappingThresholdHigh());

for (const EventQueue::Ptr& queue : queues) {
queue->ProcessEvent(result);
Expand Down
12 changes: 7 additions & 5 deletions lib/icinga/checkable-flapping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@ using namespace icinga;
void Checkable::UpdateFlappingStatus(bool stateChange)
{
std::bitset<20> stateChangeBuf = GetFlappingBuffer();
int oldestIndex = (GetFlappingBuffer() & 0xFF00000) >> 20;
int oldestIndex = GetFlappingIndex();

stateChangeBuf[oldestIndex] = stateChange;
oldestIndex = (oldestIndex + 1) % 20;

double stateChanges = 0;

/* Iterate over our state array and compute a weighted total */
for (int i = 0; i < 20; i++) {
if (stateChangeBuf[(oldestIndex + i) % 20])
stateChanges += 0.8 + (0.02 * i);
Expand All @@ -48,12 +49,13 @@ void Checkable::UpdateFlappingStatus(bool stateChange)
else
flapping = flappingValue > GetFlappingThresholdHigh();

SetFlappingBuffer(stateChangeBuf.to_ulong());
SetFlappingIndex(oldestIndex);
SetFlappingCurrent(flappingValue);
SetFlapping(flapping, true);

if (flapping != GetFlapping())
SetFlappingLastChange(Utility::GetTime());

SetFlappingBuffer((stateChangeBuf.to_ulong() | (oldestIndex << 20)));
SetFlappingCurrent(flappingValue);
SetFlapping(flapping);
}

bool Checkable::IsFlapping(void) const
Expand Down
4 changes: 3 additions & 1 deletion lib/icinga/checkable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ class I2_ICINGA_API Checkable : public ObjectImpl<Checkable>

/* Flapping Detection */
bool IsFlapping(void) const;
void UpdateFlappingStatus(bool stateChange);

/* Dependencies */
void AddDependency(const intrusive_ptr<Dependency>& dep);
Expand Down Expand Up @@ -237,6 +236,9 @@ class I2_ICINGA_API Checkable : public ObjectImpl<Checkable>
std::set<intrusive_ptr<Dependency> > m_ReverseDependencies;

void GetAllChildrenInternal(std::set<Checkable::Ptr>& children, int level = 0) const;

/* Flapping */
void UpdateFlappingStatus(bool stateChange);
};

}
Expand Down
2 changes: 2 additions & 0 deletions lib/icinga/checkable.ti
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,9 @@ abstract class Checkable : CustomVarObject
default {{{ return 0; }}}
};
[state] Timestamp flapping_last_change;

[state, no_user_view, no_user_modify] int flapping_buffer;
[state, no_user_view, no_user_modify] int flapping_index;
[state, protected] bool flapping;

[config, navigation] name(Endpoint) command_endpoint (CommandEndpointRaw) {
Expand Down

0 comments on commit 73d73ee

Please sign in to comment.