root/src/noit_check_tools.h

Revision 7def515c85f3f80b0e47eb92ddaaf60800a52439, 6.7 kB (checked in by Theo Schlossnagle <jesus@omniti.com>, 2 months ago)

make this a macro for reuse

  • Property mode set to 100644
Line 
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 #define CHOOSE_EVENTER_THREAD_FOR_CHECK(check) \
67   eventer_choose_owner(((int)(((vpsized_int)(check))/sizeof(*(check))))*2654435761)
68
69 /*#* DOCBOOK
70  * <section><title>Check Hooks</title>
71  *   <section><title>check_stats_set_metric</title>
72  *   <programlisting>
73  *     noit_hook_return_t (*f)(void *closure, noit_check_t *check, metric_t *m);
74  *   </programlisting>
75  *   <para>the check_stats_set_metric hook is invoked each time a check is
76  *   run and an individual metric is identified and inserted into
77  *   the running status.
78  *   </para>
79  *   </section>
80  *   <section><title>check_preflight</title>
81  *   <programlisting>
82  *     noit_hook_return_t (*f)(void *closure, noit_module_t *self,
83  *                             noit_check_t *check, noit_check_t *cause);
84  *   </programlisting>
85  *   <para>the check_preflight hook is invoked immediately prior to every
86  *   check being performed.  The actual invocation of the check can be
87  *   avoided by returning NOIT_HOOK_DONE instead of NOIT_HOOK_CONTINUE.
88  *   </para>
89  *   <para>The arguments to this function are the module of the check
90  *   the check itself and the causal check (NULL if this check was not
91  *   induced by the completion of another check), respectively.</para>
92  *   <para>This instrumentation point can be used to audit intended check
93  *   activity or prevent a check from running (such as an ACL).</para>
94  *   </section>
95  *   <section><title>check_postflight</title>
96  *   <programlisting>
97  *     noit_hook_return_t (*f)(void *closure, noit_module_t *self,
98  *                             noit_check_t *check, noit_check_t *cause);
99  *   </programlisting>
100  *   <para>The check_postflight hook is invoked immediately subsequent to
101  *   a check being commenced.  Note that due to the asynchronous nature
102  *   of Reconnoiter, it is highly unlikely that the check will have
103  *   completed by this time.</para>
104  *   <para>The arguments to this function are the module of the check,
105  *   the check itself and the causal check (NULL if this check was not
106  *   induced by the completion of another check), respectively.</para>
107  *   <para>Returning NOIT_HOOK_CONTINUE and NOIT_HOOK_DONE have the same
108  *   effect for this instrumentation point.</para>
109  *   </section>
110  *   <section><title>check_log_stats</title>
111  *   <programlisting>
112  *     noit_hook_return_t (*f)(void *closure, noit_check_t *check);
113  *   </programlisting>
114  *   <para>The check_log_stats is called when a check logs a metrics
115  *   bundle.</para>
116  *   <para>If NOIT_HOOK_DONE is returned, normal logging is averted.</para>
117  *   </section>
118  *   <section><title>check_passive_log_stats</title>
119  *   <programlisting>
120  *     noit_hook_return_t (*f)(void *closure, noit_check_t *check);
121  *   </programlisting>
122  *   <para>The check_passive_log_stats is called when a check logs a
123  *   metric immediately.</para>
124  *   <para>If NOIT_HOOK_DONE is returned, normal logging is averted.</para>
125  *   </section>
126  * </section>
127  */
128 NOIT_HOOK_PROTO(check_preflight,
129                 (noit_module_t *self, noit_check_t *check, noit_check_t *cause),
130                 void *, closure,
131                 (void *closure, noit_module_t *self, noit_check_t *check, noit_check_t *cause))
132 NOIT_HOOK_PROTO(check_postflight,
133                 (noit_module_t *self, noit_check_t *check, noit_check_t *cause),
134                 void *, closure,
135                 (void *closure, noit_module_t *self, noit_check_t *check, noit_check_t *cause))
136
137 #define BAIL_ON_RUNNING_CHECK(check) do { \
138   if(check->flags & NP_RUNNING) { \
139     noitL(noit_error, "Check %s is still running!\n", check->name); \
140     return -1; \
141   } \
142 } while(0)
143
144 #define INITIATE_CHECK(func, self, check, cause) do { \
145   if(once) { \
146     if(NOIT_HOOK_CONTINUE == \
147        check_preflight_hook_invoke(self, check, cause)) \
148       func(self, check, cause); \
149     check_postflight_hook_invoke(self, check, cause); \
150   } \
151   else if(!check->fire_event) { \
152     struct timeval epoch = { 0L, 0L }; \
153     noit_check_fake_last_check(check, &epoch, NULL); \
154     noit_check_schedule_next(self, &epoch, check, NULL, func, cause); \
155   } \
156 } while(0)
157
158 #endif
159
Note: See TracBrowser for help on using the browser.