Allow check commands to be commandline escaped

If check commands are being used as arguments to notification
commands so that the user being notified can see exactly the
command that caused the state to change and that check command
has arguments containing single or double-quotes, there's no
sane way of using it as an argument without escaping it.

This patch allows such escaping for host and service check
commands, which should clear up the issue.

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

This deduplicates the algorithm used for calculating flapping states,
which was previously copy-pasted between hosts and services.

Instead it's broken out into a separate function of its own, which
returns the curved percent change-rate over the past 20 potential
state-changes we fit in our 21 slot long state history.

Functionally there's no change.

Signed-off-by: Andreas Ericsson <ae@op5.se>
Micro-optimize flapping detection

According to Nagios' documentation, flap_detection_options counts
which states we should care about when doing flapping detection.
Disregarding ignored states early means we can return earlier than
we would otherwise be able to (as states have to be tracked when
flapping is just disabled, but not when the object is in a state
that should be expressly ignored).

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

If we shouldn't update state history, we can bail out early and
save a few cycles, since we know the flapping state won't change
since last time we updated it and therefore can't trigger any
action anyway.

If flapping detection is disabled, either globally or for the object
in question (but not explicitly for the object's current state; See
previous commit), we bail out immediately after calculating the
flapping state, since we still have to present the correct figures
in the user interface, but don't have to bother with notifications
and suchlike.

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