Skip to content

Commit

Permalink
improve tests with validtime macros
Browse files Browse the repository at this point in the history
  • Loading branch information
HubLot committed Jan 13, 2015
1 parent 3afc228 commit 079528d
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions test/test_macroresolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,12 @@ def test_validtime_ondemand_macros(self):
data = hst.get_data_for_checks()

# Get the 18 of December 2014 at 15:00, thursday
dec_the_18 = time.mktime(time.strptime("18 Dec 2014 15:00:00", "%d %b %Y %H:%M:%S"))
dec_the_18_15h = int(time.mktime(time.strptime("18 Dec 2014 15:00:00", "%d %b %Y %H:%M:%S")))
# Get the 18 of December 2014 at 20:00, thursday
dec_the_18_20h = time.mktime(time.strptime("18 Dec 2014 20:00:00", "%d %b %Y %H:%M:%S"))
dec_the_18_20h = int(time.mktime(time.strptime("18 Dec 2014 20:00:00", "%d %b %Y %H:%M:%S")))
# Get the 18 of December 2014 at 09:00, friday
dec_the_19_9h = int(time.mktime(time.strptime("19 Dec 2014 09:00:00", "%d %b %Y %H:%M:%S")))


#with a 24x7 timeperiod
data = svc.get_data_for_checks()
Expand All @@ -224,15 +227,15 @@ def test_validtime_ondemand_macros(self):

#with workhours timeperiod and a timestamp (equals to 18 Dec 2014 15:00:00)
data = svc.get_data_for_checks()
dummy_call = "special_macro!$ISVALIDTIME:workhours:1418911200$"
dummy_call = "special_macro!$ISVALIDTIME:workhours:{0}$".format(dec_the_18_15h)
cc = CommandCall(self.conf.commands, dummy_call)
com = mr.resolve_command(cc, data)
print com
self.assertEqual('plugins/nothing 1', com)

#with a timestamp off workhours (equals to 18 Dec 2014 20:00:00)
data = svc.get_data_for_checks()
dummy_call = "special_macro!$ISVALIDTIME:workhours:1418929200$"
dummy_call = "special_macro!$ISVALIDTIME:workhours:{0}$".format(dec_the_18_20h)
cc = CommandCall(self.conf.commands, dummy_call)
com = mr.resolve_command(cc, data)
print com
Expand All @@ -249,29 +252,29 @@ def test_validtime_ondemand_macros(self):
# with a 24x7 timeperiod and a timestamp (equals to 18 Dec 2014 15:00:00)
# Next validtime will be equal to the timestamp
data = svc.get_data_for_checks()
dummy_call = "special_macro!$NEXTVALIDTIME:24x7:1418911200$"
dummy_call = "special_macro!$NEXTVALIDTIME:24x7:{0}$".format(dec_the_18_15h)
cc = CommandCall(self.conf.commands, dummy_call)
com = mr.resolve_command(cc, data)
print com
self.assertEqual('plugins/nothing 1418911200', com)
self.assertEqual('plugins/nothing {0}'.format(dec_the_18_15h), com)

# with workhours timeperiod and a timestamp (equals to 18 Dec 2014 15:00:00)
# Next validtime will be equal to the timestamp
data = svc.get_data_for_checks()
dummy_call = "special_macro!$NEXTVALIDTIME:workhours:1418911200$"
dummy_call = "special_macro!$NEXTVALIDTIME:workhours:{0}$".format(dec_the_18_15h)
cc = CommandCall(self.conf.commands, dummy_call)
com = mr.resolve_command(cc, data)
print com
self.assertEqual('plugins/nothing 1418911200', com)
self.assertEqual('plugins/nothing {0}'.format(dec_the_18_15h), com)

# with a timestamp off workhours (equals to 18 Dec 2014 20:00:00)
# Next valid time will be 1418976000 (19 Dec 2014 08:00:00)
# Next valid time will be 1418976000 (19 Dec 2014 09:00:00)
data = svc.get_data_for_checks()
dummy_call = "special_macro!$NEXTVALIDTIME:workhours:1418929200$"
dummy_call = "special_macro!$NEXTVALIDTIME:workhours:{0}$".format(dec_the_18_20h)
cc = CommandCall(self.conf.commands, dummy_call)
com = mr.resolve_command(cc, data)
print com
self.assertEqual('plugins/nothing 1418976000', com)
self.assertEqual('plugins/nothing {0}'.format(dec_the_19_9h), com)

# with bad timestamp
data = svc.get_data_for_checks()
Expand Down

0 comments on commit 079528d

Please sign in to comment.