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>
Remove Nagios-beta.png reference from spec file

The file cannot be found, and rpm will not build with an invalid
source reference.

Signed-off-by: Daniel Wittenberg <dwittenberg2008@gmail.com>
Signed-off-by: Andreas Ericsson <ae@op5.se>
core: Avoid running checks when they're globally disabled

Previously we would execute implicit host dependency checks (for
child and parent hosts) when we received a passive host check
result for either the parent or the child, and and the same went
for both types of host and service dependencies, even though the
check type in question was globally disabled (either by config or
by external command).

This patch alters the behaviour so that disabling checks really
disables them (which I assume is desired), but also means that
submitting passive service checks to hosts and services that in
some way depend upon or are depended upon by other objects can
result in the wrong type of notification being sent out (ie,
"DOWN" instead of "UNREACHABLE" for hosts).

There's nothing we can do about that if we really want to follow
the users wishes, but it's quite a lot easier to explain why
dependency checks aren't working properly when checks are
globally disabled than it is to explain why checks are being
executed.

Signed-off-by: Andreas Ericsson <ae@op5.se>
Remove tinderbox build-script

The location it's pointing to doesn't exist, and insofar as I know
we have no tinderbox build servers anywhere, so it's just dead
code.

Signed-off-by: Andreas Ericsson <ae@op5.se>
core: Add perfect-hash sources to version control

It's stupid and useless to have them sitting on my laptop, and it's
even dumber to not use gperf output as-is. This patch fixes both
those issues, allowing anyone to easily extend the types and names
of variables we can get from our worker-processes.

We do check in the output of the gperf run though, as we'd otherwise
introduce a new dependency into the build. Only people who want to
add variables to the worker processes need to bother with the new
dependency.

Signed-off-by: Andreas Ericsson <ae@op5.se>
core: Don't free the lock file path too soon

It's used after the main loop ends in the main function to remove the
lock file once we're shut down.

As the variable was already freed and pointed to NULL, unlink would not
remove the lock file, but instead return EFAULT. This is not how daemons
are supposed to behave.

Signed-off-by: Robin Sonefors <robin.sonefors@op5.com>
core: Fix checkresult spool reaping

Not that it's used anymore (except as a deprecated legacy interface
for passing passive checkresults to Nagios), but we really shouldn't
bomb out before we've even started parsing results.

Signed-off-by: Andreas Ericsson <ae@op5.se>
core: Fix checkresult sourcename assignment

Since we parse sourcename as a const char pointer if no engine is
set, we can make this really easy by just not setting the engine
and just have Nagios return the string for us.

Signed-off-by: Andreas Ericsson <ae@op5.se>
core: Avoid running dependency host checks when globally disabled

When we receive non-OK service checks we'd otherwise end up running
host checks, even though they're disabled. Since global commands
really are meant to be honored, we do that with this patch.

Signed-off-by: Andreas Ericsson <ae@op5.se>
Updated version for 4.0.0-beta1 release
xod: Stop leaking memory when using precached objects

Even though *using* precached objects is a pretty dumb idea nowadays,
we still support it and shouldn't leak memory when it's used.

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