sample-config: Update with new options for Nagios 4

Most people tend to look at the sample configuration when setting up
their nagios configurations. This patch makes it passably simple for
them to find and get a brief description of all the various options,
although some of them are experimental and shouldn't really be used.

Message-by: Andreas Ericsson <ae@op5.se>
Signed-off-by: Daniel.Wittenberg <Daniel.Wittenberg@ipsoft.com>
Signed-off-by: Andreas Ericsson <ae@op5.se>
common/downtime: Simplify a few functions

In preparation for a large-scale refactoring, this is the kind of
boilerplate crap I rather not be distracted by.

Signed-off-by: Andreas Ericsson <ae@op5.se>
core: Replace half of xdata/xdddefault.c with a 5-line helper

It's mostly useless, and the half-dozen or so other downtime adding
functions can surely pick up the slack, should there be any.

Signed-off-by: Andreas Ericsson <ae@op5.se>
downtime: Make downtime lookups a 16384 times more efficient

For a given value of "efficient" at least. Since we're using a fanout
table, we'll be using some memory in exchange for the fewer operations,
but at least lookup operations have decent practical performance now.

While at it, we sneak in the embryo of an API, which we can build on
later when refactoring the code into something sensible.

Signed-off-by: Andreas Ericsson <ae@op5.se>
downtime: Simplify the insertion sort somewhat

If scheduled_downtime_list is NULL, there's no need for us to enter
the iteration loop, so we can handle it the same we would as if we
were deferring downtime sorting and just prepend the downtime to
the (empty) scheduled_downtime_list.

We can do the same trick if the downtime_compar() function tells us
that the new downtime sorts before the first entry in the list.

Signed-off-by: Andreas Ericsson <ae@op5.se>
downtime: Use downtime_compar() when insert-sorting downtime

It's important that we maintain the sort order when we're inserting
downtime, or we'll end up with inconsistent states if we sometimes
sort using qsort() and downtime_compar(), and other times by using
a different comparison function.

Signed-off-by: Andreas Ericsson <ae@op5.se>
downtime: Refactor delete_downtime()

The only error condition we can run into is when we don't find the
downtime we're supposed to delete, so return ERROR immediately if
that happens and avoid some unnecessary indentation and a (very)
long if() clause.

Signed-off-by: Andreas Ericsson <ae@op5.se>
downtime: Make the downtime list a doubly-linked one

This makes the algorithms for insertion and removal a lot more
pleasant, as we can abuse find_downtime() without having to bother
about locating the previous entry for efficient removals.

Signed-off-by: Andreas Ericsson <ae@op5.se>
downtime: Handle scheduled_downtime_list from downtime_{add,remove}

It makes a lot more sense to handle all storage from the API-ish
functions that we can test separately, so refactor stuff so they
end up there so we can test the storage system.

Signed-off-by: Andreas Ericsson <ae@op5.se>
downtime: Handle error checking in downtime_add()

We're supposed to have all the information we need there, so we might
as well do all error checking there and get rid of the validation
routine in xdata/xdddefault.c, which is then reduced to setting
next_downtime_id = 1 in case nothing else sets it when we initialize.

Moving that small task to common/downtime.c as well means we can get
rid of the entire xdata/xdddefault.c, which is a very nice bonus.

Signed-off-by: Andreas Ericsson <ae@op5.se>
downtime: Ensure that scheduled_downtime_depth never drops below zero

If it does, subsequent downtimes may cause the depth to be bumped up
to zero, which will cause the notification machinery to not consider
the host or service to be in downtime at all, which in turn means
that notifications will be sent out while downtime is actually in
effect. It's unclear how one triggers this without modifying the
retention data file, but it has happened a few times in the wild,
and this rather simple patch efficiently protects against it.

Signed-off-by: Anton Lofgren <alofgren@op5.com>
Signed-off-by: Andreas Ericsson <ae@op5.se>