test: Make test_timeperiods functional

I intend to refactor the time periods, and need a bit of encouragement
from something that tells me that everything is OK.

Signed-off-by: Robin Sonefors <robin.sonefors@op5.com>
utils: Refactor get_next_valid_time

There were several problems with how it worked, when faced with
exceptions and exclusions together with regular logic - Jean Gabes had
contributed several examples to the test_timeperiod suite that were
marked as TODO, that now passes just fine.

This code wraps the old logic in a loop. Once an exclusion hits, we
start over with checking for exceptions or weekday rules. If any rule
moves the match to tomorrow, we start over checking for new exclusions,
exceptions and weekday rules. Before, we didn't start over from scratch,
only on the "level" we had already reached.

Given that your timeperiod is crazy enough, or you use an empty
timeperiod to mean 24x7, nagios might spend slightly more time than
before figuring out your next valid time. The first case didn't behave
correctly before, so that's not a problem. For the second case, nagios
will only run it once, realize the check can't be scheduled, and leave
it alone, so that shouldn't affect things in practice.

The net line reduction comes from introducing a new helper, as
get_next_valid_time and check_time_against_period were using exactly the
same code to find rules to match against.

Signed-off-by: Robin Sonefors <robin.sonefors@op5.com>
test_timeperiods: Remove TODO, make output easier to understand

There are no more todos here - the tests pass. Their output was
very unhelpful, though, so making that more helpful as well.

Signed-off-by: Robin Sonefors <robin.sonefors@op5.com>
utils: Remove special handling for circular timeperiods

Nagios no longer loads them, so stop confusing the reader with this.

Signed-off-by: Robin Sonefors <robin.sonefors@op5.com>
utils: Make internal prototypes easier to use

There was a mention about the old prototype (for an internal method)
making the code easier to test - in fact, it didn't, it just made things
more awkward.

Signed-off-by: Robin Sonefors <robin.sonefors@op5.com>
test_timeperiods: Add new test that exercises get_next_invalid

In particular, that exercises its error path.

Signed-off-by: Robin Sonefors <robin.sonefors@op5.com>
xodtemplate: Don't use space as a delimiter in escalations

contact_names are allowed to have spaces in them, so using space as a
delimiter doesn't really work. Space is thus not a valid delimiter for
contacts anywhere, except in escalations, where it is only valid after
the first comma. So you could have one contact with a space in its name,
as long as you put it first - and no more than that!

This patch allows you to have as many contacts with as many spaces as
you want in your escalations.

This also makes things consistent with how we parse contactgroups for
hostescalations. That particular path did it right all along.

Signed-off-by: Robin Sonefors <robin.sonefors@op5.com>
Signed-off-by: Andreas Ericsson <ae@op5.se>
Give tests some love

We don't want to use absolute paths in tests when Nagios supports
relative ones just fine.

Signed-off-by: Andreas Ericsson <ae@op5.se>
Fix hosturgencies test

The objects.cache file it was supposed to link against didn't have
all the necessary hosts we were looking for. This patch adds them,
making the test pass just fine.

Signed-off-by: Andreas Ericsson <ae@op5.se>
Makefile: tests require nagios and cgis

Now all "normal" tests pass. The libtap tests are still in a sort
of screwed up state, since most of the core code has been overhauled
beyond recognition.

Signed-off-by: Andreas Ericsson <ae@op5.se>