]> granicus.if.org Git - icinga2/commitdiff
Bugfixes for the timeperiod feature.
authorGunnar Beutner <gunnar.beutner@netways.de>
Tue, 16 Apr 2013 08:12:53 +0000 (10:12 +0200)
committerGunnar Beutner <gunnar.beutner@netways.de>
Tue, 16 Apr 2013 08:12:53 +0000 (10:12 +0200)
lib/icinga/host.cpp
lib/icinga/legacytimeperiod.cpp
lib/icinga/notification.cpp
lib/icinga/timeperiod.cpp
lib/icinga/timeperiod.h

index e694146c747d54d26710e493cdbe425ecddeca3a..4c486f24c5a3682c88e52a7a2f69a3316c7e7a3a 100644 (file)
@@ -539,7 +539,7 @@ String Host::StateToString(HostState state)
        }
 }
 
-bool Host::ResolveMacro(const String& macro, const Dictionary::Ptr& cr, String *result) const
+bool Host::ResolveMacro(const String& macro, const Dictionary::Ptr&, String *result) const
 {
        if (macro == "HOSTNAME" || macro == "HOSTALIAS") {
                *result = GetName();
index a990487fcd6fd8de060e60da111b1687c2edb14b..51173626a20ae7a243bc67d77c5eee2a30498f45 100644 (file)
@@ -21,6 +21,7 @@
 #include "base/scriptfunction.h"
 #include "base/convert.h"
 #include "base/exception.h"
+#include "base/objectlock.h"
 #include "base/logger_fwd.h"
 #include <boost/smart_ptr/make_shared.hpp>
 #include <boost/algorithm/string/split.hpp>
@@ -140,6 +141,7 @@ Array::Ptr LegacyTimePeriod::ScriptFunc(const TimePeriod::Ptr& tp, double begin,
 
        if (ranges) {
                for (int i = 0; i <= (end - begin) / (24 * 60 * 60); i++) {
+                       ObjectLock olock(ranges);
                        String key;
                        Value value;
                        BOOST_FOREACH(boost::tie(key, value), ranges) {
@@ -149,7 +151,7 @@ Array::Ptr LegacyTimePeriod::ScriptFunc(const TimePeriod::Ptr& tp, double begin,
                                ProcessTimeRanges(value, &reference, segments);
                        }
 
-                       reference.tm_wday++;
+                       reference.tm_mday++;
                }
        }
 
index e8c3be2a218378ce404f845a2f23154fd0ba14ff..eafd8b4178628b75d97bc5317869308bc1b07b0a 100644 (file)
@@ -280,7 +280,7 @@ void Notification::OnAttributeChanged(const String& name)
                Service::InvalidateNotificationsCache();
 }
 
-bool Notification::ResolveMacro(const String& macro, const Dictionary::Ptr& cr, String *result) const
+bool Notification::ResolveMacro(const String& macro, const Dictionary::Ptr&, String *result) const
 {
        Dictionary::Ptr macros = GetMacros();
 
index 5a67322a45d046cf9e461b706634980d5ce08af9..f2d57aea1cd62230b38d7733c28934c047864691 100644 (file)
@@ -55,7 +55,8 @@ void TimePeriod::Start(void)
 {
        /* Pre-fill the time period for the next 24 hours. */
        double now = Utility::GetTime();
-       UpdateRegion(now, now + 24 * 3600);
+       UpdateRegion(now, now + 24 * 3600, true);
+       Dump();
 }
 
 TimePeriod::Ptr TimePeriod::GetByName(const String& name)
@@ -196,13 +197,15 @@ void TimePeriod::PurgeSegments(double end)
        Touch("segments");
 }
 
-void TimePeriod::UpdateRegion(double begin, double end)
+void TimePeriod::UpdateRegion(double begin, double end, bool clearExisting)
 {
-       if (begin < m_ValidEnd)
-               begin = m_ValidEnd;
+       if (!clearExisting) {
+               if (begin < m_ValidEnd)
+                       begin = m_ValidEnd;
 
-       if (end < m_ValidEnd)
-               return;
+               if (end < m_ValidEnd)
+                       return;
+       }
 
        TimePeriod::Ptr self = GetSelf();
 
@@ -288,18 +291,18 @@ void TimePeriod::UpdateTimerHandler(void)
                        valid_end = tp->m_ValidEnd;
                }
 
-               if (valid_end < now + 3 * 3600)
-                       tp->UpdateRegion(valid_end, now + 24 * 3600);
+               tp->UpdateRegion(valid_end, now + 24 * 3600, false);
+               tp->Dump();
        }
 }
 
-Array::Ptr TimePeriod::EmptyTimePeriodUpdate(const TimePeriod::Ptr tp, double begin, double end)
+Array::Ptr TimePeriod::EmptyTimePeriodUpdate(const TimePeriod::Ptr&, double, double)
 {
        Array::Ptr segments = boost::make_shared<Array>();
        return segments;
 }
 
-Array::Ptr TimePeriod::EvenMinutesTimePeriodUpdate(const TimePeriod::Ptr tp, double begin, double end)
+Array::Ptr TimePeriod::EvenMinutesTimePeriodUpdate(const TimePeriod::Ptr&, double begin, double end)
 {
        Array::Ptr segments = boost::make_shared<Array>();
 
@@ -315,3 +318,21 @@ Array::Ptr TimePeriod::EvenMinutesTimePeriodUpdate(const TimePeriod::Ptr tp, dou
 
        return segments;
 }
+
+void TimePeriod::Dump(void)
+{
+       Array::Ptr segments = m_Segments;
+
+       Log(LogDebug, "icinga", "Dumping TimePeriod '" + GetName() + "'");
+
+       if (segments) {
+               ObjectLock dlock(segments);
+               BOOST_FOREACH(const Dictionary::Ptr& segment, segments) {
+                       Log(LogDebug, "icinga", "Segment: " +
+                           Utility::FormatDateTime("%c", segment->Get("begin")) + " <-> " +
+                           Utility::FormatDateTime("%c", segment->Get("end")));
+               }
+       }
+
+       Log(LogDebug, "icinga", "---");
+}
index c9c29094e1e21850062c21d8bd227582defd6bb0..9f4036b641d4939a0bf1bd1c6f74536138e8b654 100644 (file)
@@ -44,13 +44,13 @@ public:
 
        virtual void Start(void);
 
-       void UpdateRegion(double begin, double end);
+       void UpdateRegion(double begin, double end, bool clearExisting);
 
        bool IsInside(double ts) const;
        double FindNextTransition(double begin);
 
-       static Array::Ptr EmptyTimePeriodUpdate(const TimePeriod::Ptr tp, double begin, double end);
-       static Array::Ptr EvenMinutesTimePeriodUpdate(const TimePeriod::Ptr tp, double begin, double end);
+       static Array::Ptr EmptyTimePeriodUpdate(const TimePeriod::Ptr& tp, double begin, double end);
+       static Array::Ptr EvenMinutesTimePeriodUpdate(const TimePeriod::Ptr& tp, double begin, double end);
 
 private:
        Attribute<double> m_ValidBegin;
@@ -62,6 +62,8 @@ private:
        void RemoveSegment(double begin, double end);
        void PurgeSegments(double end);
 
+       void Dump(void);
+
        static void UpdateTimerHandler(void);
 };