rework shadownaemon downtime/comment synchronisation

removed the downtime/comment synchronisation based on the last highest id. That
way sometimes lead to situations where the host had still
scheduled_downtime_depth > 0 set but no belonging downtimes exists which broke
nagvis and thruk and probably others too.

Instead we now check all downtime/comment ids all the time and synchronize them one
by one by fetching the required data when its missing. In addition we force updating
the corresponding host and service when removing/adding downtimes/comments.

Signed-off-by: Sven Nierlein <sven@nierlein.de>
buildsystem: Use non-recursive make

I'm not going to argue why here. Instead I'm going to assume
everyone (who would have an opinion on the matter) is familiar
with Peter Miller's classic paper Recursive Make Considered Harmful'.

This patch also adds a bit more structure to the project in general -
beyond the call of duty, if you will - by properly separating the lib
and src trees and *preparing* for a saner approach to binary
namespacing.

We'll want to actually do the namespacing at some point as well (like,
let shadownaemon/naemonstats/... all have their own subdirectory in the
source tree) but this patch has gotten enough of a "THIS CHANGES
EVERYTHING" vibe to it already.

All test-suite related stuff is now tracked in tests.mk in the root.

Change-Id: I4d47d56c7cce2198418b571936f820325416eb23
Signed-off-by: Anton Lofgren <alofgren@op5.com>
Signed-off-by: Andreas Ericsson <ae@op5.se>
xodtemplate: Avoid a ton of unnecessary strcmp()s

I know this won't make much of a difference, but I noticed the code, and
I couldn't help myself:

We first have this one, massive if () that checks if the define is any
of the valid object types, and if it isn't, we print an error, and exit.
Then, we loop over the valid object types, and check which one of them
it is.

Unless I'm crazy-ignorant about preschool math, if you already handle
all the valid cases, and you're left with another case, that's your
invalid case right there, without any extra checking of anything.

Change-Id: Ic00d2580602a8a195150f611daab973c2e3fecd7
Signed-off-by: Robin Sonefors <robin.sonefors@op5.com>
events: Allow running checks at the time they're supposed to run

Whenever an event was scheduled for *now*, we refused to run the check,
opting to wait for at least one millisecond.

Pointless fix, but it just looked silly.

Change-Id: I182f73194ee87872375c228a78b0c0766ad058f4
Signed-off-by: Robin Sonefors <robin.sonefors@op5.com>
workers: Log when notification command failed

There are very few things that make users as annoyed as missing
notifications - after all, if nagios doesn't notify, what good is it?
- so we really need to tell the user when the notification failed.

Ideally, this would be done through a notification. As we just
determined notifications doesn't work, we'll just have to log it
instead - perhaps you could monitor the log file and send a different
notification that works based on that?

This fixes bug op5#9353.

Change-Id: I9a5e19cc59d202189bb40e7cf43330017a3dcf06
Signed-off-by: Robin Sonefors <robin.sonefors@op5.com>
logging: Make debug logging of output more visible

It's highly useful to know what the check actually said.

Change-Id: I36f48ddcb8df826351775fa906325b487a541063
Signed-off-by: Robin Sonefors <robin.sonefors@op5.com>
Move uninterrupted_write to nsock

Also rename it to nsock_write_all, because it's not uninterrupted: it
just resumes after interruptions. Until all the data has been written,
or there's been an error.

Change-Id: I2e002f6ddfe5c822ccf1d7aa4166878d85f6493c
Signed-off-by: Robin Sonefors <robin.sonefors@op5.com>
iocache: Make iocache_sendto actually work

It really, really didn't - whenever I tried to use it, it kept
corrupting my queues:

 - iocache_add replaced the current write head, not the current
   buffer head. So, whenever it was called, and the queue wasn't
   completely empty, everything became corrupt.
 - We sometimes appended the cache with the data we were currently
   writing. We sometimes adjusted the write pointer when we were
   done. we did not do these things under the exact same situations.

And while we're at it, why don't we write a loop around it, to try to
get to push as much data as possible towards the other end -
Interrupts Happen, as I like to say.

Change-Id: I37e7157eed794eb72a7706a931f92f47329eb658
Signed-off-by: Robin Sonefors <robin.sonefors@op5.com>
worker: Remove memory error

kill_job calls check_completion. Sometimes, check_completion calls
kill_job, and sometimes, that kill_job frees the job, which makes the outer
kill_job try to access the just-freed memory to log a message that,
essentially, the memory was just freed.

Don't do that.

Change-Id: I22e900970938819679636347d86311d40af71876
Signed-off-by: Robin Sonefors <robin.sonefors@op5.com>
checks: Fix next check handling for unchecked checks

When a check hadn't been checked before, the next check macro would
say that the next check time is 0 + check_interval. So all unchecked
checks would be attempted to be scheduled for the 1970's (this, of
course, fails, because we nudge the check to now(), so nothing
actually looks suspicious in the scheduling queue).

Now, at startup, we give all checks a different next check time, so
after they have been checked, this case will not trigger.

Unless, that is, the check wasn't/couldn't be completed, in which case
we would retry it instantly. The check would, most likely, fail again
- it is, after all, the same check that failed the last time - leading
to frequent and hard-to explain infinite loops where naemon would
insist on using 100% CPU, without doing anything.

Let's push it one check interval into the future. Even if it will
still fail then, at least other checks will have a chance to run in
the meantime.

And if check intervals are 0, still do not schedule it any more
recently than 1 interval_length into the future. Yield, you
uncooperative event, yield!

While at it, remove the next_host_check and next_service_check
variables we used to have, since they're not used anymore.

Commit-message-poetry-by: Robin Sonefors <robin.sonefors@op5.com>
Signed-off-by: Andreas Ericsson <ae@op5.se>
Stop using HOST_{UP,DOWN,UNREACHABLE} macros

We've kept them around for legacy reasons (and because some
modules have been using them). It's time we stop using them
ourselves though, as they add nothing and only serve to
confuse with their inconsistent naming.

Instead, we use the STATE_{UP,DOWN,UNREACHABLE} macros,
which serve the same purpose but are more aptly named.

Signed-off-by: Andreas Ericsson <ae@op5.se>
buildsystem: Program directory namespacing

To make things more explicit directory-structure-wise, this patch places
each program into its own subdirectory. While this does not give us any
significant, direct gain it makes thing a little bit neater. It also
makes cross-program dependencies that much clearer, which might be
helpful if we wish to clean up the "naemon-as-a-library" part of things
at some point.

Original-patch-by: Anton Löfgren <alofgren@op5.com>
Signed-off-by: Andreas Ericsson <ae@op5.se>
.gitignore all unignored buildproducts

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