include/nebcallbacks: Reduce listed number of supported nebcallbacks

We really only support 26 (which fits nicely into 32 bit types) and
not 33, so we update the macro used for counting callbacks so we
can avoid wasting some memory.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2235 5f96b256-904b-4d8d-8c98-d829582c6739
Add alloc_nr() macro

This is useful when dynamically increasing an array where we don't
know how much larger it's going to get. The array will grow by
roughly 1.5 times its current size, but faster in the beginning.
Memory spill should be about 15-20% of total size needed, and we
can live with that for most arrays. Where the arrays are huge and
ultimately bounded by some size unknown at creation time, one can
always realloc() it down to its ultimate size.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2236 5f96b256-904b-4d8d-8c98-d829582c6739
Pass check result struct (when available) to event brokers

The check result struct contains a lot of useful information not
found in the host and service structs. This patch provides the
modules with that information for all occasions except on-demand
host checks, which are still special-cased.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2237 5f96b256-904b-4d8d-8c98-d829582c6739
Eventbroker API: Add support for built-in core modules

It's usually a good idea to eat ones own dogfood. It's also a
pretty good idea to be able to incorporate nifty modules directly
in to the core, should we decide to go that way.

With this patch, that becomes possible, since we can now add core
modules that can register callbacks and don't cause segfaults when
they're about to be unloaded, and soon that will become highly
useful.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2238 5f96b256-904b-4d8d-8c98-d829582c6739
Deprecate {HOST,SERVICE}_CHECK_{ACTIVE_PASSIVE}

Since the way things are checked doesn't differ between hosts and
services, it's just confusing to have two different macros that
mean the exact same thing.

Instead we introduce CHECK_TYPE_{ACTIVE,PASSIVE,PARENT,FILE,OTHER},
with ACTIVE and PASSIVE replacing the four previous similar ones.
CHECK_TYPE_PARENT means we've run an (active) check for the benefit
of an object that depends on the object we just checked. FILE means
we read the check result from a spooled file (which is deprecated
and should just go away as quickly as possible), and OTHER being a
catch-all to let modules set something that marks checks from them
as special.

We retain the old macros yet a while longer, but clearly mark them
as deprecated, and we get rid of them from the sources so others
don't use them by mistake.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2239 5f96b256-904b-4d8d-8c98-d829582c6739
lib/lnag-utils: Add ranged_urand()

Proper randomization is highly useful in algorithms where no good
solution exists, but it's boring to type and off-by-ones tend to
sneak in when coding at three in the morning. With this helper we
avoid such errors, which is a Good Thing(tm) since such bugs are
by their very definition impossible to reliably reproduce.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2240 5f96b256-904b-4d8d-8c98-d829582c6739
core: Run first check of objects within their max check delay

If the initially scheduled checks happen to end up too far into the
future we simply schedule them on a random slot within their
check window. The check_window() macro takes care of calculating the
max time we have, regardless of whether the host (or service) is in
soft or hard state.

This fixes issue 83.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2241 5f96b256-904b-4d8d-8c98-d829582c6739
xpd: Re-initialize perfdata_file_pipe vars to FALSE on reloads

Without this patch we would otherwise lose the ability to reconfigure
perfdata handling, leading us to lose performance data indefinitely.

This fixes issue 138.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2242 5f96b256-904b-4d8d-8c98-d829582c6739
base/checks: Stop being tricksy with orphan detection checks

The orphan detection logic might be doing it wrong with regards to
hosts (it looks correct, but that's no guarantee), but intentionally
fooling ourselves with a bug in one place to work around a bug in
another makes absolutely no sense what so ever.

This patch removes one such cover-up bug. If we get the bug with
orphaned host checks back (unlikely, as they're run by the worker
processes now), we can fix that properly instead of working around
it in such a hackish manner.

This fixes issue 270.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2243 5f96b256-904b-4d8d-8c98-d829582c6739
xod: Fix contact inheritance

According to the docs, contacts should only be inherited from host to
service if the service has no other contacts what so ever (and the
same goes for escalations), but the way the code worked was that it
handled contact_groups and contacts directives separately, meaning
services with only 'contacts' specified were still eligible for
inheriting 'contact_groups' from the host, leading to much confusion.

This patch fixes that, and thereby issue 314.

While we're at it, we re-organize the inheritance macros a bit and
make sure to use them for cross-object inheritance too.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2244 5f96b256-904b-4d8d-8c98-d829582c6739
Show the buildmachinery some love

The specfile now has support for the devel package and the init
script has sysconfig support with automagic ramdisk fiddling.

Patched-by: Daniel Wittenberg <dwittenberg2008@gmail.com>
Signed-off-by: Andreas Ericsson <ae@op5.se>

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2245 5f96b256-904b-4d8d-8c98-d829582c6739
Add NERD, the Nagios Event Radio Dispatcher

Yes, I came up with the acronym first and the name afterwards.

This is quite nifty though, as it provides external applications
with a way to obtain real-time data from Nagios without having
to resort to writing C-code or relying on other addons. There's
currently only two channels; hostchecks and servicechecks, and
only two commands; subscribe and unsubscribe, but since channels
can be added without any major fuzz that will most likely happen
whenever people need a new type of data.

It's also quite neat that eventbroker modules can create their
own channels and thereby set up "radio merlin", or whatever
takes ones fancy.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2246 5f96b256-904b-4d8d-8c98-d829582c6739
Make Nagios build properly on OpenBSD

OpenBSD apparently doesn't have ETIME, and dprintf() is available
only in posix 200809, which is much too recent to be widely
portable. We arrange it by removing the unused iobroker_print_set()
function and defininig ETIME to ETIMEDOUT if it's previously
undefined.

Patched-by: Armin Wolfermann <aw@osn.de>
Signed-off-by: Andreas Ericsson <ae@op5.se>

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2247 5f96b256-904b-4d8d-8c98-d829582c6739
Bring snprintf.o into libnagios

I'm not entirely certain this is a good idea, but without it it's
possible the library won't have access to vasprintf() and other
nifty string builders, so we do it anyway.

"It works on my system" isn't very reassuring here, since
snprintf.o is more or less empty on every modern system I can
think of. Thankfully though, modern systems (well, modern enough
to obey one of the simplest parts of C99) is our primary target
audience. We may have to fix it later though.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2248 5f96b256-904b-4d8d-8c98-d829582c6739
xpd: Fix "open(.., O_CREAT) with missing mode" warning

This only happens on some systems, but where it does it's usually a
hard error. We avoid it by specifying the mode we want for the pipe
in the call to open.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2249 5f96b256-904b-4d8d-8c98-d829582c6739
Properly handle check output when stdout is empty and stderr is not

The key/value vector we get from the worker always has values
for everything, so we must check for the nul string rather than
NULL when checking if there is output on stdout. This sets the
output from the check to this message:

 (No output on stdout) stderr: execvpe() failed. errno is %d: %s

where %s is ofcourse strerror(errno), usually letting people know
that the file they're trying to execute is missing, or that they
lack permissions to run the check.

Reported-by: Joerg Linge <pitchfork@ederdrom.de>
Signed-off-by: Andreas Ericsson <ae@op5.se>

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2250 5f96b256-904b-4d8d-8c98-d829582c6739
nerd: Fix include path to snprintf.h

Left-over in old location since before the move caused builds to
succeed even after the move. Grrmbl...

Reported-by: Daniel Wittenberg <dwittenberg2008@gmail.com>
Signed-off-by: Andreas Ericsson <ae@op5.se>

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2251 5f96b256-904b-4d8d-8c98-d829582c6739
core: Plug memory leak in command file worker

It's a one-time leak, only triggered when we shut down for good,
but even so it's good to get it fixed so valgrind shuts up.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2252 5f96b256-904b-4d8d-8c98-d829582c6739
Make headers C++ friendly

This change is conceptually larger than the deceptive subject line
hints at. We rename 'struct host_struct' to 'struct host', use the
'struct host' form in all header files (which may be included by
C++ modules) and deprecate the 'host *h' form of variable creation,
preparing to get rid of typedef's for common objects in Nagios 5.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2253 5f96b256-904b-4d8d-8c98-d829582c6739
lib/iobroker: Make iobroker compile nicely with non-glibc libs

The features.h header file is glibc specific and not present
everywhere, so include it conditionally.

Reported-by: Armin Wolfermann <aw@osn.de>
Signed-off-by: Andreas Ericsson <ae@op5.se>

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2254 5f96b256-904b-4d8d-8c98-d829582c6739