common/objects: Make 'address' optional for hosts

Many people put fully qualified dns names as host_names and
don't really need or want to put in an extra 'address' field.
We humor them with this patch, assigning the host_name to the
address field in case address isn't set.

While at it, we do the same for 'alias', which was previously
copied (rather than assigned), and naturally make sure that
all variables are free()'d safely or ignored correctly at cleanup
time.

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

It's been deprecated since 2008, so the gracetime was about three
years longer than anyone could possibly need.

Signed-off-by: Andreas Ericsson <ae@op5.se>
core: Restore -x, but as a noop with a deprecation notice

Some large users will have that in more than a few scripts, so we
play nice with them and give them a year or so so remove those
occurrences.

Signed-off-by: Andreas Ericsson <ae@op5.se>
core: Move the timing_point() calls somewhat

The previous output was somewhat confusing, as the time used
didn't show up on the line where the time was actually spent. By
moving the timing points to after the things they time, we get a
picture that's easier to understand.

While we're at it, we also print the number of objects we added
at each point.

Signed-off-by: Andreas Ericsson <ae@op5.se>
Fix small thinko in fcache_servicedependency()

We would previously print dependency_period even if it wasn't set.
This patch corrects that.

Signed-off-by: Andreas Ericsson <ae@op5.se>
xdata/xodtemplate: Fix typo causing segfaults with serviceescalations

Signed-off-by: Andreas Ericsson <ae@op5.se>
xdata/xodtemplate: Start counting escalations too

Since escalations can avoid skiplist insertions just as dependencies,
we have to count them manually as we duplicate them. We also add the
missing code to cound objects properly for the cgi's, which have been
a second class citizen up til now (actually, they still are, since I'm
not bothering with testing them until I'm done with the core).

Since we're now counting an awful lot of object types, we might as
well do so using an object_count struct and move all other counters
over to that one.

Signed-off-by: Andreas Ericsson <ae@op5.se>
xdata/xodtemplate: Honor exclusions when creating service lists

Everywhere else we're careful to create (and use) member maps when
creating lists of objects, but xodtemplate_create_service_list()
neglected to do that, causing servicedependencies like this:

  define servicedependency {
      hostgroup_name                 all-hosts
      service_description            agent
      dependent_hostgroup_name       all-hosts
      dependent_host_name            A,B,C
      dependent_service_description  PING,PONG,PANG,!PANG
      execution_failure_criteria     w,u,c
      notification_failure_criteria  w,u,c
  }

to result in multiple (identical) servicedependencies for all
hosts from all hosts (including explicitly rejected PANG service),
leading to potentially far more service dependencies than we
could sensibly handle.

With this patch, all services named PANG are completely excluded
from the created list, and each host gets exactly one dependency.

For our small test-config (with only 8 hosts and 24 services),
this means a reduction in dependencies from 912 to 640. For
larger networks, the savings will be much greater.

Signed-off-by: Andreas Ericsson <ae@op5.se>
core: Only warn about hosts with no services if verify_config >= 2

This is accomplished by giving -v twice (or more). "empty" hosts
are perfectly valid ever since active host checks were introduced,
so it's time we get these warnings a bit harder to come by.

Signed-off-by: Andreas Ericsson <ae@op5.se>
common/objects: Stash dependencies with their parents for cgi's too

Otherwise config.cgi won't be able to list them at all.

Signed-off-by: Andreas Ericsson <ae@op5.se>
xdata/xodtemplate: Update timing_point() messages

It's nifty to see how many objects were created with respect to how
many services there are, since that provides a meaningful context for
later errors.

While at it, we also add the missing message for when servicegroup
recombobulation is done and fix service counting so it's never tainted
by future cgi code.

Signed-off-by: Andreas Ericsson <ae@op5.se>
core: Speed up group registration considerable

Previously we'd engage in insertion-sorting the members into their
respective lists. That's fine and dandy when there's about five of
them, but with the massive member-lists found in large configs today
it's sheer murder to use an O(n^2) algorithm to do sorting. Until we
can be bothered to do an O(n lg n) algorithm for an unbound number of
members (heap-sort should work well), we simply stash the objects to
the front of the member list if large installation tweaks are enabled.

Signed-off-by: Andreas Ericsson <ae@op5.se>
common/objects: Revamp group member addition logic somewhat

I spotted this micro-optimization while doing the previous patch
and since it works nicely we might as well use it.

Signed-off-by: Andreas Ericsson <ae@op5.se>
xdata/xodtemplate.c: Make cgi's build again

bleh... Actually; bleh twice.

Many thanks to Daniel Wittenberg and his autobuild tests for noticing
this one.

Signed-off-by: Andreas Ericsson <ae@op5.se>
xdata/xodtemplate: Squelch a compiler warning

The cgi's never use the static xodtemplate_free_template_skiplists()
function, so we make it #ifndef NSCGI to shut the compiler up.

Signed-off-by: Andreas Ericsson <ae@op5.se>
common/objects: Fix servicegroup member registration speedup hack

Seems I forgot the early return last time around, thus making that
particular hack completely useless. *sigh*

Signed-off-by: Andreas Ericsson <ae@op5.se>
common/objects: Add prepend_unique_object_to_objectlist()

This is quite nifty when adding host and servicedependencies, which
can currently be duplicated (with identical values) any number of
times by having hosts join multiple hostgroups and assigning
dependencies to each of them. It might be too slow to bother with,
but services normally don't depend on more than one other service,
so it should be fairly quick.

Signed-off-by: Andreas Ericsson <ae@op5.se>
xdata/xodtemplate: Ignore 'n' option dependencies

We don't create dependencies that are missing one (or more) of the
listed options, but we do create dependencies that have the 'n'
option as its sole failure criteria, which is essentially the same
as no criteria, except it's more verbose and more likely that a user
has no idea it will sit in RAM and consume memory while doing
absolutely nothing. With this patch, such dependencies will no longer
be created. This lets us save a smallish amount of time during config
loading.

Signed-off-by: Andreas Ericsson <ae@op5.se>
commono/objects: Only allow unique dependencies to be registered

"unique" here means differing in at least one byte of their fully
filled out definition, since multiple identical definitions just
wastes both cpu and memory.

Signed-off-by: Andreas Ericsson <ae@op5.se>
xdata/xodtemplate: Register dependencies ad-hoc

By registering dependencies as we encounter them, we can ensure
that there are no duplicates and that we never waste memory storing
any duplicates. This comes at the expense of us having to allocate
the objects on the fly (which is slower than chunk-allocating, but a
lot faster than swapping), and not being able to assign id fields
until after all config is read (since we need to compare the deps
with each other).

There's a lot of fallout from this conceptually simple patch, so I
hope I got everything right.

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