[Pkg-nagios-changes] [SCM] UNNAMED PROJECT branch, debian/master, updated. 810edbdd3feedbfe37f4a65bee50b57b2f60fa2a
Naparuba
naparuba at gmail.com
Tue Feb 28 22:14:38 UTC 2012
The following commit has been merged in the debian/master branch:
commit d3d889d35c185719e38431730f13133bdd880f3a
Author: Naparuba <naparuba at gmail.com>
Date: Tue Jan 17 12:47:12 2012 +0100
Fix : (reported by : lminoza) corner case with between date in multiple timerange timeperiod.
diff --git a/shinken/daterange.py b/shinken/daterange.py
index 2299fec..182ce75 100644
--- a/shinken/daterange.py
+++ b/shinken/daterange.py
@@ -238,6 +238,7 @@ class Daterange:
def get_next_future_timerange_valid(self, t):
+ #print "Look for get_next_future_timerange_valid for t", t, time.asctime(time.localtime(t))
sec_from_morning = get_sec_from_morning(t)
starts = []
for tr in self.timeranges:
@@ -294,7 +295,7 @@ class Daterange:
def get_next_valid_time_from_t(self, t):
- #print "DR Get next valid from:", time.asctime(time.localtime(t))
+ #print "\tDR Get next valid from:", time.asctime(time.localtime(t))
#print "DR Get next valid from:", t
if self.is_time_valid(t):
return t
@@ -306,25 +307,18 @@ class Daterange:
#print "Search for t", time.asctime(time.localtime(t))
#print "DR: next day", time.asctime(time.localtime(t_day))
- #print "DR: sec from morning", time.asctime(time.localtime(sec_from_morning))
+ #print "DR: sec from morning", sec_from_morning
#We search for the min of all tr.start > sec_from_morning
- starts = []
- for tr in self.timeranges:
- tr_start = tr.hstart * 3600 + tr.mstart * 3600
- if tr_start >= sec_from_morning:
- starts.append(tr_start)
-
- #tr can't be valid, or it will be return at the begining
- sec_from_morning = self.get_next_future_timerange_valid(t)
- #print "DR: sec from morning", time.asctime(time.localtime(sec_from_morning))
+ sec_from_morning = self.get_next_future_timerange_valid(t_day)
+ #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
- #Then we search for the next day of t
- #The sec will be the min of the day
+ # Then we search for the next day of t
+ # The sec will be the min of the day
t = get_day(t)+86400
t_day2 = self.get_next_valid_day(t)
sec_from_morning = self.get_next_future_timerange_valid(t_day2)
diff --git a/shinken/objects/timeperiod.py b/shinken/objects/timeperiod.py
index 7ba6428..74c241a 100644
--- a/shinken/objects/timeperiod.py
+++ b/shinken/objects/timeperiod.py
@@ -163,10 +163,10 @@ class Timeperiod(Item):
return None
- #clean the get_next_valid_time_from_t cache
- #The entries are a dict on t. t < now are useless
- #Because we do not care about past anymore.
- #If not, it's not important, it's just a cache after all :)
+ # clean the get_next_valid_time_from_t cache
+ # The entries are a dict on t. t < now are useless
+ # Because we do not care about past anymore.
+ # If not, it's not important, it's just a cache after all :)
def clean_cache(self):
now = int(time.time())
t_to_del = []
diff --git a/test/test_timeperiods.py b/test/test_timeperiods.py
index d67defd..50baecd 100755
--- a/test/test_timeperiods.py
+++ b/test/test_timeperiods.py
@@ -55,6 +55,42 @@ class TestTimeperiods(ShinkenTest):
self.assert_(t_next == "Tue Jul 13 16:30:00 2010")
+ def test_simple_with_multiple_time(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 = ''
+ 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 == "Tue Jul 13 00:00: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"))
+ #Then a simple same day
+ t = Timeperiod()
+ t.timeperiod_name = ''
+ 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 == "Tue Jul 13 00:00:00 2010")
+
+
def test_simple_timeperiod_with_exclude(self):
--
UNNAMED PROJECT
More information about the Pkg-nagios-changes
mailing list