tests: Add Check plumbing and (naemon) check regression tests

This patch adds autotools infrastructure for writing and running Check
test cases.

In preparation for refactoring, I've also added a number of test cases
for the plugin output parsing.

These tests found two peculiarities (read: bugs).

The first, demonstrated by the following test results:

test-checks.c:104:F:Output parsing:perfdata_only:0: Assertion
'""==short_output' failed: ""=="", short_output=="some=perfdata;"
test-checks.c:117:F:Output parsing:multiline_perfdata_only:0: Assertion
'""==short_output' failed: ""=="", short_output=="some=perfdata;"

shows that if you have a plugin that does not output any "regular" short
output, you will get any perfdata, that you might have in your
short_output buffer, and you'll be left without perf data. Now, this is
a bit of an edge case, of course, but the behaviour is nevertheless
highly unexpected.

The second, demonstrated by:
test-checks.c:134:E:Output parsing:no_plugin_output_on_first_line:0:
(after this point) Received signal 11 (Segmentation fault)

is somewhat more serious. I'm sure I don't have to expand on why.

Signed-off-by: Anton Lofgren <alofgren@op5.com>
checks: Be consistent in handling missing output

For service checks, we let the plugin_output be "(No output returned
from the plugin)" in case we get _no_(NULL) short output. For host
checks, this is also done when the output is empty("")(albeit with the
string "(No output returned from host check)" instead).

This patch changes the behaviour for host checks, so that we only
replace the output if it is NULL, since this signifies a fault.

If the output is an empty string, this is likely the intended - though,
one could argue, misdirected - behaviour by the plugin author, and I
don't think it's appropriate that we mess around with it.

Signed-off-by: Anton Lofgren <alofgren@op5.com>
checks: Refactor check output parsing

The check output/perfdata parsing is needlessly contrived (and
inefficient, though that is secondary.) This patch adds a cleaner
alternative interface to output parsing, makes better use of available
data structures and, presumably, improves performance. It also (imo)
makes the code a bit easier to follow.

Both ABI and API are preserved, through the parse_check_output
function.

Besides cleaning up the code, this patch also fixes two bugs mentioned
in GH pull request https://github.com/naemon/naemon-core/pull/26.

In other words, after merging this patch, the test cases added in PR 26
should all pass.

Signed-off-by: Anton Lofgren <alofgren@op5.com>
Makefile.am: Don't clobber AM_CPPFLAGS

Append, don't overwrite.

Also fixed a space/tab whitespace error.

Signed-off-by: Anton Lofgren <alofgren@op5.com>
add logrotate script

now that we removed logrotation from core, we can use standard logrotate
to rotate logs into the archive. Better not compress them and keep em for
10 years.
After rotation, send a USR1 signal so naemon can send broker events for backwards
compatibility.

Signed-off-by: Sven Nierlein <sven@consol.de>
naemon.cfg: Remove hyperbolic warning message

Do go ahead and overwrite the broker module while naemon is running -
that works fine.

Do not go ahead and replace random bytes in it - but why would you?

Signed-off-by: Robin Sonefors <ozamosi@flukkost.nu>
configure.ac: Define m4 directory

Libtool told me to.

Signed-off-by: Robin Sonefors <ozamosi@flukkost.nu>
configure: Make sure build dies if gperf missing

It just doesn't seem to want to otherwise, and I'm just fed up with
getting halfway through make before discovering that I forgot to install
it again.

Signed-off-by: Robin Sonefors <ozamosi@flukkost.nu>
Add autogen.sh script

While autoreconf these days is mostly good enough for most projects to
just use straight up, I became hardened in the bad, old days, when you
needed pages of random shell scripts to help it put a configure script
in place.

Fearing for the return of those days, I'm preemptively applying the
common workaround from those days: an autogen.sh script that invokes
autoreconf and any other relevant tools with all the necessary options -
whatever those turn out to be over time.

Signed-off-by: Robin Sonefors <ozamosi@flukkost.nu>
Merge branch 'catharsis-check-plumbing'
configure: Try more harder to find check

Check's suggested way to find build flags through autoconf is no longer
their own macro; instead, they use bog-standard pkg-config. Of course,
older versions of check don't ship the pkg-config file, so it's not
possible to exclusively rely on that.

Their old macro also has the downside of only really being available
when check is available, which means that the macro finding out that
check isn't installed is unlikely - use m4_ifdef to speak up when the
macro itself isn't found.

This still has limitations - one could argue that the absence of
pkg-config should trigger a similar message (but while my background is
in desktop coding where pkg-config originated, I've used it for close to
a decade), and one could argue that a failure to locate the test tool
shouldn't influence the build itself. One both those accounts, one'd be
correct, and I'll happily accept patches submitted by one.

Signed-off-by: Robin Sonefors <ozamosi@flukkost.nu>
Merge branch 'catharsis-refactor-parse-output'
checks: Fix C90 compatibility

Guh, why, exactly, do we not allow mixed declarations and code? Is it
because it makes life less horrible? But fine, I'll adapt, and now GCC
is happy again.

Signed-off-by: Robin Sonefors <ozamosi@flukkost.nu>
configure: Make the check library optional

To disable it, you need to provide --without-tests or equivalent to
configure, to make the check-using tests un-runnable. Making tests
un-runnable is in general a bad idea, so I'm complaining by default.

Signed-off-by: Robin Sonefors <ozamosi@flukkost.nu>
Makefile: Make gperf respect silence rules

Signed-off-by: Robin Sonefors <ozamosi@flukkost.nu>
Kick out logrotate code

It didn't work.

To be clear, despite my best efforts (which can be seen in 8a7ba31), I
seem to be too stupid to fix it, and nobody else really seem to want to
get into this mess either. After all, everyone else is using logrotate
for rotating logs, so why bother with a weird, un-flexible, non-standard
log rotation mechanism?

Naemon now instead listens for USR1 for knowing when to reopen its log,
which is what the logrotate script committed last night sends.

Unfortunately, my solution introduces Yet Another weird global variable
which triggers special event handling logic. I would have loved to be
able to tell the logging code that it needs to reopen its logs by
scheduling a log rotate event with now() as its deadline, but as
scheduling a new event is a long and complicated process which can
actually take code execution over to broker modules, I decided against
that for now - I don't want broker modules to run from within sighandler
context.

Signed-off-by: Robin Sonefors <ozamosi@flukkost.nu>
Merge branch 'catharsis-consistent-missing-output-handling'
Merge branch 'master' of ssh://github.com/naemon/naemon-core
utils: Actually setup the SIGUSR1 handler

Going back and forth on how to implement something can sometimes result
in you not implementing it at all.

Signed-off-by: Robin Sonefors <ozamosi@flukkost.nu>
removed duplicate rotate from logrotate config

also fixed archives path

Signed-off-by: Sven Nierlein <sven@consol.de>