]> granicus.if.org Git - icinga2/commitdiff
Fix flapping endianness and events
authorJean Flach <jean-marcel.flach@icinga.com>
Fri, 3 Nov 2017 16:50:59 +0000 (17:50 +0100)
committerJean Flach <jean-marcel.flach@icinga.com>
Tue, 7 Nov 2017 10:13:17 +0000 (11:13 +0100)
fixes #5720

lib/icinga/apievents.cpp
lib/icinga/checkable-flapping.cpp
lib/icinga/checkable.hpp
lib/icinga/checkable.ti

index 0fb38e19013fc126b4349e8b80f69e9adcc5b7a0..7d0f5cd295ab3ca7b4452ded7ac5eb6b6a72b9c8 100644 (file)
@@ -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);
index af5ced0502049dc542178b62c68466b6846aa05a..84bba8e5bd719035ddf444af68b57fe7fdf589e2 100644 (file)
@@ -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);
@@ -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
index 0617eca127260eb5229e526e3cd9be440b2e75bd..413e452d3f01432f756cdaba5bfa14f0a6afd895 100644 (file)
@@ -181,7 +181,6 @@ public:
 
        /* Flapping Detection */
        bool IsFlapping(void) const;
-       void UpdateFlappingStatus(bool stateChange);
 
        /* Dependencies */
        void AddDependency(const intrusive_ptr<Dependency>& dep);
@@ -237,6 +236,10 @@ private:
        std::set<intrusive_ptr<Dependency> > m_ReverseDependencies;
 
        void GetAllChildrenInternal(std::set<Checkable::Ptr>& children, int level = 0) const;
+
+       /* Flapping */
+       void UpdateFlappingStatus(bool stateChange);
+       bool SuppressEvent(void) const;
 };
 
 }
index ced78b8e9fa2ac96239536efb170c529bb4e02b6..6ecf3ffaff1d9d4c94de930ef589efa5c47375cc 100644 (file)
@@ -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) {