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(stats_t *s, const char *json_str, int len); |
---|
64 |
|
---|
65 |
/*#* DOCBOOK |
---|
66 |
* <section><title>Check Hooks</title> |
---|
67 |
* <section><title>check_preflight</title> |
---|
68 |
* <programlisting> |
---|
69 |
* noit_hook_return_t (*f)(void *closure, noit_module_t *self, |
---|
70 |
* noit_check_t *check, noit_check_t *cause); |
---|
71 |
* </programlisting> |
---|
72 |
* <para>the check_preflight hook is invoked immediately prior to every |
---|
73 |
* check being performed. The actual invocation of the check can be |
---|
74 |
* avoided by returning NOIT_HOOK_DONE instead of NOIT_HOOK_CONTINUE. |
---|
75 |
* </para> |
---|
76 |
* <para>The arguments to this function are the module of the check |
---|
77 |
* the check itself and the causal check (NULL if this check was not |
---|
78 |
* induced by the completion of another check), respectively.</para> |
---|
79 |
* <para>This instrumentation point can be used to audit intended check |
---|
80 |
* activity or prevent a check from running (such as an ACL).</para> |
---|
81 |
* </section> |
---|
82 |
* <section><title>check_postflight</title> |
---|
83 |
* <programlisting> |
---|
84 |
* noit_hook_return_t (*f)(void *closure, noit_module_t *self, |
---|
85 |
* noit_check_t *check, noit_check_t *cause); |
---|
86 |
* </programlisting> |
---|
87 |
* <para>The check_postflight hook is invoked immediately subsequent to |
---|
88 |
* a check being commenced. Note that due to the asynchronous nature |
---|
89 |
* of Reconnoiter, it is highly unlikely that the check will have |
---|
90 |
* completed by this time.</para> |
---|
91 |
* <para>The arguments to this function are the module of the check, |
---|
92 |
* the check itself and the causal check (NULL if this check was not |
---|
93 |
* induced by the completion of another check), respectively.</para> |
---|
94 |
* <para>Returning NOIT_HOOK_CONTINUE and NOIT_HOOK_DONE have the same |
---|
95 |
* effect for this instrumentation point.</para> |
---|
96 |
* </section> |
---|
97 |
* </section> |
---|
98 |
*/ |
---|
99 |
NOIT_HOOK_PROTO(check_preflight, |
---|
100 |
(noit_module_t *self, noit_check_t *check, noit_check_t *cause), |
---|
101 |
void *, closure, |
---|
102 |
(void *closure, noit_module_t *self, noit_check_t *check, noit_check_t *cause)) |
---|
103 |
NOIT_HOOK_PROTO(check_postflight, |
---|
104 |
(noit_module_t *self, noit_check_t *check, noit_check_t *cause), |
---|
105 |
void *, closure, |
---|
106 |
(void *closure, noit_module_t *self, noit_check_t *check, noit_check_t *cause)) |
---|
107 |
|
---|
108 |
#define INITIATE_CHECK(func, self, check, cause) do { \ |
---|
109 |
if(once) { \ |
---|
110 |
if(NOIT_HOOK_CONTINUE == \ |
---|
111 |
check_preflight_hook_invoke(self, check, cause)) \ |
---|
112 |
func(self, check, cause); \ |
---|
113 |
check_postflight_hook_invoke(self, check, cause); \ |
---|
114 |
} \ |
---|
115 |
else if(!check->fire_event) { \ |
---|
116 |
struct timeval epoch = { 0L, 0L }; \ |
---|
117 |
noit_check_fake_last_check(check, &epoch, NULL); \ |
---|
118 |
noit_check_schedule_next(self, &epoch, check, NULL, func, cause); \ |
---|
119 |
} \ |
---|
120 |
} while(0) |
---|
121 |
|
---|
122 |
#endif |
---|
123 |
|
---|