[Pkg-nagios-changes] [SCM] UNNAMED PROJECT branch, debian/master, updated. 810edbdd3feedbfe37f4a65bee50b57b2f60fa2a

Naparuba naparuba at gmail.com
Tue Feb 28 22:14:46 UTC 2012


The following commit has been merged in the debian/master branch:
commit cae166fafa0da876ed0805706b5b5798c304b251
Author: Naparuba <naparuba at gmail.com>
Date:   Thu Jan 19 10:20:27 2012 +0100

    Fix : flaw on multiple date and multiple timerange.

diff --git a/shinken/daterange.py b/shinken/daterange.py
index 182ce75..72da8db 100644
--- a/shinken/daterange.py
+++ b/shinken/daterange.py
@@ -303,16 +303,17 @@ class Daterange:
         #print "DR Get next valid from:", time.asctime(time.localtime(t))
         #First we search fot the day of t
         t_day = self.get_next_valid_day(t)
-        sec_from_morning = self.get_min_sec_from_morning()
 
-        #print "Search for t", time.asctime(time.localtime(t))
-        #print "DR: next day", time.asctime(time.localtime(t_day))
-        #print "DR: sec from morning", sec_from_morning
+        #print "DR: T next valid day", time.asctime(time.localtime(t_day))
 
-        #We search for the min of all tr.start > sec_from_morning
-        sec_from_morning = self.get_next_future_timerange_valid(t_day)
+        # We search for the min of all tr.start > sec_from_morning
+        # if it's the next day, use a start of the day search for timerange
+        if t < t_day:
+            sec_from_morning = self.get_next_future_timerange_valid(t_day)
+        else: # t is in this day, so look from t (can be in the evening or so)
+            sec_from_morning = self.get_next_future_timerange_valid(t)
         #print "DR: sec from morning", sec_from_morning
-        #print "Sec from morning", t_day
+
         if sec_from_morning is not None:
             if t_day is not None and sec_from_morning is not None:
                 return t_day + sec_from_morning
diff --git a/test/test_timeperiods.py b/test/test_timeperiods.py
index 50baecd..647139e 100755
--- a/test/test_timeperiods.py
+++ b/test/test_timeperiods.py
@@ -1,5 +1,5 @@
 #!/usr/bin/env python2.6
-#Copyright (C) 2009-2010 :
+#Copyright (C) 2009-2012 :
 #    Gabes Jean, naparuba at gmail.com
 #    Gerhard Lausser, Gerhard.Lausser at consol.de
 #
@@ -71,6 +71,7 @@ class TestTimeperiods(ShinkenTest):
         self.assert_(t_next is None)
 
         #Then a simple same day
+        print "Cheking validity for", time.asctime(time.localtime(july_the_12))
         t = Timeperiod()
         t.timeperiod_name = ''
         t.resolve_daterange(t.dateranges, 'tuesday 00:00-07:00,21:30-24:00')
@@ -92,6 +93,49 @@ class TestTimeperiods(ShinkenTest):
 
 
 
+    def test_simple_with_multiple_time_mutltiple_days(self):
+        self.print_header()
+        t = Timeperiod()
+        now = time.time()
+        # Get the 12 of july 2010 at 15:00, monday
+        july_the_12 = time.mktime(time.strptime("12 Jul 2010 15:00:00", "%d %b %Y %H:%M:%S"))
+        print july_the_12
+
+        # First a false test, no results
+        t = Timeperiod()
+        t.timeperiod_name = ''
+        t.resolve_daterange(t.dateranges, '1999-01-28  00:00-07:00,21:30-24:00')
+        t_next = t.get_next_valid_time_from_t(now)
+        self.assert_(t_next is None)
+
+        # Then a simple same day
+        t = Timeperiod()
+        t.timeperiod_name = ''
+        #monday          00:00-07:00,21:30-24:00
+        #tuesday         00:00-07:00,21:30-24:00
+        print "Cheking validity for", time.asctime(time.localtime(july_the_12))
+        t.resolve_daterange(t.dateranges, 'monday 00:00-07:00,21:30-24:00')
+        t.resolve_daterange(t.dateranges, 'tuesday 00:00-07:00,21:30-24:00')
+        t_next = t.get_next_valid_time_from_t(july_the_12)
+        t_next = time.asctime(time.localtime(t_next))
+        print "RES:", t_next
+        self.assert_(t_next == "Mon Jul 12 21:30:00 2010")
+
+        # Now ask about at 00:00 time?
+        july_the_12 = time.mktime(time.strptime("12 Jul 2010 00:00:00", "%d %b %Y %H:%M:%S"))
+        print "Cheking validity for", time.asctime(time.localtime(july_the_12))
+        # Then a simple same day
+        t = Timeperiod()
+        t.timeperiod_name = ''
+        t.resolve_daterange(t.dateranges, 'monday 00:00-07:00,21:30-24:00')
+        t.resolve_daterange(t.dateranges, 'tuesday 00:00-07:00,21:30-24:00')
+        t_next = t.get_next_valid_time_from_t(july_the_12)
+        t_next = time.asctime(time.localtime(t_next))
+        print "Next?", t_next
+        self.assert_(t_next == "Mon Jul 12 00:00:00 2010")
+
+
+
 
     def test_simple_timeperiod_with_exclude(self):
         self.print_header()

-- 
UNNAMED PROJECT



More information about the Pkg-nagios-changes mailing list