| 1 |
/* |
|---|
| 2 |
* Copyright (c) 2007, OmniTI Computer Consulting, Inc. |
|---|
| 3 |
* All rights reserved. |
|---|
| 4 |
* |
|---|
| 5 |
* Redistribution and use in source and binary forms, with or without |
|---|
| 6 |
* modification, are permitted provided that the following conditions are |
|---|
| 7 |
* met: |
|---|
| 8 |
* |
|---|
| 9 |
* * Redistributions of source code must retain the above copyright |
|---|
| 10 |
* notice, this list of conditions and the following disclaimer. |
|---|
| 11 |
* * Redistributions in binary form must reproduce the above |
|---|
| 12 |
* copyright notice, this list of conditions and the following |
|---|
| 13 |
* disclaimer in the documentation and/or other materials provided |
|---|
| 14 |
* with the distribution. |
|---|
| 15 |
* * Neither the name OmniTI Computer Consulting, Inc. nor the names |
|---|
| 16 |
* of its contributors may be used to endorse or promote products |
|---|
| 17 |
* derived from this software without specific prior written |
|---|
| 18 |
* permission. |
|---|
| 19 |
* |
|---|
| 20 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|---|
| 21 |
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|---|
| 22 |
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|---|
| 23 |
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|---|
| 24 |
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|---|
| 25 |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|---|
| 26 |
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|---|
| 27 |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|---|
| 28 |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|---|
| 29 |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|---|
| 30 |
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|---|
| 31 |
*/ |
|---|
| 32 |
|
|---|
| 33 |
#ifndef _NOIT_CHECK_TOOLS_H |
|---|
| 34 |
#define _NOIT_CHECK_TOOLS_H |
|---|
| 35 |
|
|---|
| 36 |
#include "noit_defines.h" |
|---|
| 37 |
#include "eventer/eventer.h" |
|---|
| 38 |
#include "noit_module.h" |
|---|
| 39 |
#include "noit_check.h" |
|---|
| 40 |
#include "utils/noit_hash.h" |
|---|
| 41 |
#include "utils/noit_hooks.h" |
|---|
| 42 |
#include "noit_check_tools_shared.h" |
|---|
| 43 |
|
|---|
| 44 |
typedef int (*dispatch_func_t)(noit_module_t *, noit_check_t *, |
|---|
| 45 |
noit_check_t *); |
|---|
| 46 |
|
|---|
| 47 |
API_EXPORT(void) |
|---|
| 48 |
noit_check_tools_init(); |
|---|
| 49 |
|
|---|
| 50 |
API_EXPORT(int) |
|---|
| 51 |
noit_check_schedule_next(noit_module_t *self, |
|---|
| 52 |
struct timeval *last_check, noit_check_t *check, |
|---|
| 53 |
struct timeval *now, dispatch_func_t recur, |
|---|
| 54 |
noit_check_t *cause); |
|---|
| 55 |
|
|---|
| 56 |
API_EXPORT(void) |
|---|
| 57 |
noit_check_run_full_asynch_opts(noit_check_t *check, eventer_func_t callback, |
|---|
| 58 |
int mask); |
|---|
| 59 |
API_EXPORT(void) |
|---|
| 60 |
noit_check_run_full_asynch(noit_check_t *check, eventer_func_t callback); |
|---|
| 61 |
|
|---|
| 62 |
API_EXPORT(int) |
|---|
| 63 |
noit_check_stats_from_json_str(noit_check_t *check, stats_t *s, |
|---|
| 64 |
const char *json_str, int len); |
|---|
| 65 |
|
|---|
| 66 |
/*#* DOCBOOK |
|---|
| 67 |
* <section><title>Check Hooks</title> |
|---|
| 68 |
* <section><title>check_stats_set_metric</title> |
|---|
| 69 |
* <programlisting> |
|---|
| 70 |
* noit_hook_return_t (*f)(void *closure, noit_check_t *check, metric_t *m); |
|---|
| 71 |
* </programlisting> |
|---|
| 72 |
* <para>the check_stats_set_metric hook is invoked each time a check is |
|---|
| 73 |
* run and an individual metric is identified and inserted into |
|---|
| 74 |
* the running status. |
|---|
| 75 |
* </para> |
|---|
| 76 |
* </section> |
|---|
| 77 |
* <section><title>check_preflight</title> |
|---|
| 78 |
* <programlisting> |
|---|
| 79 |
* noit_hook_return_t (*f)(void *closure, noit_module_t *self, |
|---|
| 80 |
* noit_check_t *check, noit_check_t *cause); |
|---|
| 81 |
* </programlisting> |
|---|
| 82 |
* <para>the check_preflight hook is invoked immediately prior to every |
|---|
| 83 |
* check being performed. The actual invocation of the check can be |
|---|
| 84 |
* avoided by returning NOIT_HOOK_DONE instead of NOIT_HOOK_CONTINUE. |
|---|
| 85 |
* </para> |
|---|
| 86 |
* <para>The arguments to this function are the module of the check |
|---|
| 87 |
* the check itself and the causal check (NULL if this check was not |
|---|
| 88 |
* induced by the completion of another check), respectively.</para> |
|---|
| 89 |
* <para>This instrumentation point can be used to audit intended check |
|---|
| 90 |
* activity or prevent a check from running (such as an ACL).</para> |
|---|
| 91 |
* </section> |
|---|
| 92 |
* <section><title>check_postflight</title> |
|---|
| 93 |
* <programlisting> |
|---|
| 94 |
* noit_hook_return_t (*f)(void *closure, noit_module_t *self, |
|---|
| 95 |
* noit_check_t *check, noit_check_t *cause); |
|---|
| 96 |
* </programlisting> |
|---|
| 97 |
* <para>The check_postflight hook is invoked immediately subsequent to |
|---|
| 98 |
* a check being commenced. Note that due to the asynchronous nature |
|---|
| 99 |
* of Reconnoiter, it is highly unlikely that the check will have |
|---|
| 100 |
* completed by this time.</para> |
|---|
| 101 |
* <para>The arguments to this function are the module of the check, |
|---|
| 102 |
* the check itself and the causal check (NULL if this check was not |
|---|
| 103 |
* induced by the completion of another check), respectively.</para> |
|---|
| 104 |
* <para>Returning NOIT_HOOK_CONTINUE and NOIT_HOOK_DONE have the same |
|---|
| 105 |
* effect for this instrumentation point.</para> |
|---|
| 106 |
* </section> |
|---|
| 107 |
* <section><title>check_log_stats</title> |
|---|
| 108 |
* <programlisting> |
|---|
| 109 |
* noit_hook_return_t (*f)(void *closure, noit_check_t *check); |
|---|
| 110 |
* </programlisting> |
|---|
| 111 |
* <para>The check_log_stats is called when a check logs a metrics |
|---|
| 112 |
* bundle.</para> |
|---|
| 113 |
* <para>If NOIT_HOOK_DONE is returned, normal logging is averted.</para> |
|---|
| 114 |
* </section> |
|---|
| 115 |
* <section><title>check_passive_log_stats</title> |
|---|
| 116 |
* <programlisting> |
|---|
| 117 |
* noit_hook_return_t (*f)(void *closure, noit_check_t *check); |
|---|
| 118 |
* </programlisting> |
|---|
| 119 |
* <para>The check_passive_log_stats is called when a check logs a |
|---|
| 120 |
* metric immediately.</para> |
|---|
| 121 |
* <para>If NOIT_HOOK_DONE is returned, normal logging is averted.</para> |
|---|
| 122 |
* </section> |
|---|
| 123 |
* </section> |
|---|
| 124 |
*/ |
|---|
| 125 |
NOIT_HOOK_PROTO(check_preflight, |
|---|
| 126 |
(noit_module_t *self, noit_check_t *check, noit_check_t *cause), |
|---|
| 127 |
void *, closure, |
|---|
| 128 |
(void *closure, noit_module_t *self, noit_check_t *check, noit_check_t *cause)) |
|---|
| 129 |
NOIT_HOOK_PROTO(check_postflight, |
|---|
| 130 |
(noit_module_t *self, noit_check_t *check, noit_check_t *cause), |
|---|
| 131 |
void *, closure, |
|---|
| 132 |
(void *closure, noit_module_t *self, noit_check_t *check, noit_check_t *cause)) |
|---|
| 133 |
|
|---|
| 134 |
#define BAIL_ON_RUNNING_CHECK(check) do { \ |
|---|
| 135 |
if(check->flags & NP_RUNNING) { \ |
|---|
| 136 |
noitL(noit_error, "Check %s is still running!\n", check->name); \ |
|---|
| 137 |
return -1; \ |
|---|
| 138 |
} \ |
|---|
| 139 |
} while(0) |
|---|
| 140 |
|
|---|
| 141 |
#define INITIATE_CHECK(func, self, check, cause) do { \ |
|---|
| 142 |
if(once) { \ |
|---|
| 143 |
if(NOIT_HOOK_CONTINUE == \ |
|---|
| 144 |
check_preflight_hook_invoke(self, check, cause)) \ |
|---|
| 145 |
func(self, check, cause); \ |
|---|
| 146 |
check_postflight_hook_invoke(self, check, cause); \ |
|---|
| 147 |
} \ |
|---|
| 148 |
else if(!check->fire_event) { \ |
|---|
| 149 |
struct timeval epoch = { 0L, 0L }; \ |
|---|
| 150 |
noit_check_fake_last_check(check, &epoch, NULL); \ |
|---|
| 151 |
noit_check_schedule_next(self, &epoch, check, NULL, func, cause); \ |
|---|
| 152 |
} \ |
|---|
| 153 |
} while(0) |
|---|
| 154 |
|
|---|
| 155 |
#endif |
|---|
| 156 |
|
|---|