core: Remove reaper frequency hints from scheduling recommendations

Since we use worker processes, the check_result_reaper_frequency
variable only matters if addons are dropping check results in Nagios'
spool file directory, which we don't expect will happen so often that
the check_result_reaper_frequency actually matters one whit.

Signed-off-by: Andreas Ericsson <ae@op5.se>
core: Create scheduling queues when testing scheduling

It's needed to avoid getting a bazillion errors from initializing
the event loop.

Signed-off-by: Andreas Ericsson <ae@op5.se>
core: Avoid bus errors and sigsegvs on weird configurations

When servicedependencies are created with dependent_hostgroup_name
and/or hostgroup_name and the groups mentioned there are empty, we
could previously bomb out with an illegal memory access when verifying
cyclic dependency paths.

With this patch, we provide belts, suspenders, helmet and condoms to
protect against such mishaps. Firstly, we set object tables created
with zero elements to NULL instead of just returning blindly, thereby
avoiding memory taints.

We also iterate using the object count and the static table rather
than list pointers, avoiding memory taints (but not counting errors),
and finally we make sure the dependency type is within the valid
range before we attempt to assign an array for checking the invalid
dependency.

Many, many thanks to Daniel Wittenberg who was invaluable in tracking
down and debugging this problem.

Signed-off-by: Andreas Ericsson <ae@op5.se>
xdata/xodtemplate: Add some missing error messages

It appears as though processing group names could earlier lead to
errors when '*groups' directives were null (and void) in member
directives, and we didn't report where the error was, which is
very unfriendly, since users may have fairly huge configurations
to dig through to find the error.

This patch adds the missing error messages.

Again, many thanks to Daniel Wittenberg for assistance in debugging
this. He's now a certified gdb virtuoso ;)

Signed-off-by: Andreas Ericsson <ae@op5.se>
core: Fix a small compiler warning

When we have gnu getopt and are compiling with -ansi, we would get a
warning about declaration after statement. We fix that here, and
reduce the loc-count a little with a simple getopt() macro that
wraps getoptlong if it's available. This reduces the possibilities
of maintenance errors somewhat as there's only one optstring to take
care of.

Signed-off-by: Andreas Ericsson <ae@op5.se>
core: Make precaching work without -v or -s

The two execution paths for scheduling tests and config verification
are almost identical in setup, so by merging them and joining the
precache option path to them, we can get precaching to work without
having to swim through additional output. We will get error messages
though, and now we don't have to duplicate them for either of the
codepaths.

Signed-off-by: Andreas Ericsson <ae@op5.se>
xdata/xodtemplate: Unify slave object free()ing

Most slave objects (escalations and dependencies) had their variables
free()'d at the end, but it appears we free()'d the hostescalation
host_name and hostgroup_name twice, and we left a lot of dead memory
lying around when we didn't need to. With this patch, we unify the
logic and are once again free from "invalid free() / delete[]" from
valgrind.

Signed-off-by: Andreas Ericsson <ae@op5.se>
xdata/xodtemplate: Fix typo s/contactgroup/hostgroup

It's odd when you call functionlike macros with wrong arguments and
happen to end up getting it right when you do it wrong. This was one
of those times.

Signed-off-by: Andreas Ericsson <ae@op5.se>
common/objects: Don't copy "display_name" unnecessarily

In large configs this will be a huge waste of memory, so let's avoid
it whenever possible.

Signed-off-by: Andreas Ericsson <ae@op5.se>
core: Refactor object caching

With this patch it becomes absolutely trivial for modules and addons
to create partial object lists from Nagios' configuration, which is
something pretty much every kind of load-distribution system needs
desperately.

While the changes may look huge through diffstat's eyes, they were
actually relatively modest, owing to the great similarity that exists
between xodtemplate_* objects and "real" objects.

Among the benefits are included the fact that we no longer get members
duplicated in groups (which Nagios 3 did to an almost absurd level),
and we can re-create the cache at any time, should someone request it
of us.

Among the drawbacks is that we now print twice as many escalation
objects, since each configured escalation object expands to at least
two new ones no matter what one does. On the up-side, people can now
see the exact config Nagios uses internally, which should be somewhat
comforting.

Signed-off-by: Andreas Ericsson <ae@op5.se>
core: Avoid caching objects if cache file is '/dev/null'

There are plenty of other ways for people to obtain status data
from Nagios now adays, so keeping an objects.cache file is kinda
pointless for them and only wastes startup time and disk space.

With this patch, they no longer have to, although it'll be a nice
little easter egg to reveal at some conference somewhere where
people ask why Nagios has to do that. Then I can tell them to
go read the commit log. Mwahahaha...

Signed-off-by: Andreas Ericsson <ae@op5.se>
Move the timing_point() macro to include/shared.h

And also make it easier to activate so it actually does something.
It's not very useful so long as it just lives inside my head.

Signed-off-by: Andreas Ericsson <ae@op5.se>
cgis: Fix a few compile errors

There are legions more, I'm sure. I really need to try to give them
some attention from time to time.

Signed-off-by: Andreas Ericsson <ae@op5.se>
xdata/xodtemplate: Merge extinfo objects as we duplicate them

It makes absolutely no sense to stash them just to merge them later
and then free them in a third loop over all of them. The fact that
we're removing 250 lines more than we add ist just a happy bonus.

Signed-off-by: Andreas Ericsson <ae@op5.se>
Get rid of more differences between hosts and services

Hosts and services both had an "accept_passive_checks" flag, but
differently named, so that "host->accept_passive_host_checks" mapped
to "service->accept_passive_service_checks". In the interest of
merging the two objects, we're far better off unifying the name in
both object declarations and in code.

Signed-off-by: Andreas Ericsson <ae@op5.se>
Clean up global variables somewhat

The extemely lengthy lists of 'extern this and that' at the top of
every file was error prone and hard to maintain. Having the variable
definitions stored in base/nagios.c also made it nigh-impossible to
link the sources to another main() routine without creating several
stub variables that were never used.

The largest common denominator for core-only variables seems to be
base/utils.c (since that's where reset_variables() lives), so we
move the definitions there, and put core-only declarations in
include/nagios.h. Variables shared between core and cgi's are
defined in common/shared.c and declared in include/common.h.

The same work could be done for cgi's, but the savings would be
considerably smaller there, so I refrained.

Signed-off-by: Andreas Ericsson <ae@op5.se>
Fix adding timeranges to timeperiods

Previously we tried to be clever and skip the first timeperiod entry
when we knew we couldn't break out of the loop early, but that failed
pretty hard when multiple timeranges were given in sorted order, since
we never even entered the loop in such cases.

This patch corrects it and makes sure we run the loop at least once
for every non-first timerange we add.

Signed-off-by: Andreas Ericsson <ae@op5.se>
Remove dead or unnecessary command-line options

Since we're now really really fast at checking dependencies for cyclic
path, we remove the -x option that let users skip such checks earlier.
We also remove the dead -o option, which was previously used to avoid
checking object relationships, since object relationships are always
checked nowadays and the option didn't even set its flag.

Signed-off-by: Andreas Ericsson <ae@op5.se>
core: Suppress printing objectfiles unless -v is given at least twice

It gets quite annoying when trying to do timing-debug of the config
and a list of 940-ish config files keep zooming past the screen for
every run. Since it's fairly useless information for most people, we
suppress it unless -v is given multiple times.

The patch looks bigger than it is, since the 'x == TRUE' idiom only
works with booleans and not counters.

Signed-off-by: Andreas Ericsson <ae@op5.se>
Add and use the timing_point() thing properly

Previously this was just a macro which had to be enabled explicitly,
but it's highly useful in finding out where some particularly weird
configuration gets stuck or runs amok on memory usage, so we implement
it properly and give it a command-line flag that makes it super-simple
to enable at will, like a sort of poor-mans profiling and printf()
debug tool combined.

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