root/src/noit_check.h

Revision 212da6e4b6f6b0af9ea0a9ceba106f42a1ea04df, 10.0 kB (checked in by gdusbabek <gdusbabek@gmail.com>, 3 years ago)

apply resolve_rtype to check flags

  • 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_H
34 #define _NOIT_CHECK_H
35
36 #include "noit_defines.h"
37
38 #include <uuid/uuid.h>
39 #include <netinet/in.h>
40
41 #include "eventer/eventer.h"
42 #include "utils/noit_hash.h"
43 #include "utils/noit_skiplist.h"
44 #include "noit_conf.h"
45 #include "noit_console.h"
46
47 /*
48  * Checks:
49  *  attrs:
50  *   UUID
51  *   host (target)
52  *   check (module)
53  *   name (identifying the check to the user if
54  *         multiple checks of the same module are specified)
55  *   config (params for the module)
56  *   period (ms)
57  *   timeout (ms)
58  *  transient:
59  *   eventer_t (fire)
60  *   stats_t [inprogress, last]
61  *   closure
62  */
63
64 #define NP_RUNNING   0x00000001
65 #define NP_KILLED    0x00000002
66 #define NP_DISABLED  0x00000004
67 #define NP_UNCONFIG  0x00000008
68 #define NP_TRANSIENT 0x00000010
69 #define NP_RESOLVE   0x00000020
70 #define NP_RESOLVED  0x00000040
71
72 #define NP_SUPPRESS_STATUS  0x00001000
73 #define NP_SUPPRESS_METRICS 0x00002000
74
75 #define NP_PREFER_IPV6   0x00004000
76 #define NP_SINGLE_RESOLVE 0x00008000
77
78 #define PREFER_IPV4 "prefer-ipv4"
79 #define PREFER_IPV6 "prefer-ipv6"
80 #define FORCE_IPV4  "force-ipv4"
81 #define FORCE_IPV6  "force-ipv6"
82
83 #define NP_UNKNOWN '0'             /* stats_t.{available,state} */
84 #define NP_AVAILABLE 'A'           /* stats_t.available */
85 #define NP_UNAVAILABLE 'U'         /* stats_t.available */
86 #define NP_BAD 'B'                 /* stats_t.state */
87 #define NP_GOOD 'G'                /* stats_t.state */
88
89 typedef enum {
90   METRIC_GUESS = '0',
91   METRIC_INT32 = 'i',
92   METRIC_UINT32 = 'I',
93   METRIC_INT64 = 'l',
94   METRIC_UINT64 = 'L',
95   METRIC_DOUBLE = 'n',
96   METRIC_STRING = 's'
97 } metric_type_t;
98
99 typedef struct {
100   char *metric_name;
101   metric_type_t metric_type;
102   union {
103     double *n;
104     int32_t *i;
105     u_int32_t *I;
106     int64_t *l;
107     u_int64_t *L;
108     char *s;
109     void *vp; /* used for clever assignments */
110   } metric_value;
111 } metric_t;
112
113 typedef struct {
114   struct timeval whence;
115   int8_t available;
116   int8_t state;
117   u_int32_t duration;
118   char *status;
119   noit_hash_table metrics;
120 } stats_t;
121
122 typedef struct dep_list {
123   struct noit_check *check;
124   struct dep_list *next;
125 } dep_list_t;
126
127 typedef struct noit_check {
128   uuid_t checkid;
129   int8_t target_family;
130   union {
131     struct in_addr addr;
132     struct in6_addr addr6;
133   } target_addr;
134   char *target;
135   char *module;
136   char *name;
137   char *filterset;
138   noit_hash_table *config;
139   char *oncheck;               /* target`name of the check that fires us */
140   u_int32_t period;            /* period of checks in milliseconds */
141   u_int32_t timeout;           /* timeout of check in milliseconds */
142   u_int32_t flags;             /* NP_KILLED, NP_RUNNING, NP_TRANSIENT */
143
144   dep_list_t *causal_checks;
145   eventer_t fire_event;
146   struct timeval last_fire_time;
147   struct {
148     stats_t current;
149     stats_t previous;
150   } stats;
151   u_int32_t generation;        /* This can roll, we don't care */
152   void *closure;
153
154   noit_skiplist *feeds;
155   char target_ip[INET6_ADDRSTRLEN];
156 } noit_check_t;
157
158 #define NOIT_CHECK_LIVE(a) ((a)->fire_event != NULL)
159 #define NOIT_CHECK_DISABLED(a) ((a)->flags & NP_DISABLED)
160 #define NOIT_CHECK_CONFIGURED(a) (((a)->flags & NP_UNCONFIG) == 0)
161 #define NOIT_CHECK_RUNNING(a) ((a)->flags & NP_RUNNING)
162 #define NOIT_CHECK_KILLED(a) ((a)->flags & NP_KILLED)
163 #define NOIT_CHECK_SHOULD_RESOLVE(a) ((a)->flags & NP_RESOLVE)
164 /* It is resolved if it is resolved or never needed to be resolved */
165 #define NOIT_CHECK_RESOLVED(a) (((a)->flags & NP_RESOLVED) || (((a)->flags & NP_RESOLVE) == 0))
166 #define NOIT_CHECK_PREFER_V6(a) (((a)->flags & NP_PREFER_IPV6) == NP_PREFER_IPV6)
167 #define NOIT_CHECK_SINGLE_RESOLVE(a) (((a)->flags & NP_SINGLE_RESOLVE) == NP_SINGLE_RESOLVE)
168
169 API_EXPORT(void) noit_poller_init();
170 API_EXPORT(u_int64_t) noit_check_completion_count();
171 API_EXPORT(int) noit_poller_check_count();
172 API_EXPORT(int) noit_poller_transient_check_count();
173 API_EXPORT(void) noit_poller_reload(const char *xpath); /* NULL for all */
174 API_EXPORT(void) noit_poller_process_checks(const char *xpath);
175 API_EXPORT(void) noit_poller_make_causal_map();
176
177 API_EXPORT(void)
178   noit_check_fake_last_check(noit_check_t *check,
179                              struct timeval *lc, struct timeval *_now);
180 API_EXPORT(int) noit_check_max_initial_stutter();
181
182 API_EXPORT(int)
183   noit_poller_schedule(const char *target,
184                        const char *module,
185                        const char *name,
186                        const char *filterset,
187                        noit_hash_table *config,
188                        u_int32_t period,
189                        u_int32_t timeout,
190                        const char *oncheck,
191                        int flags,
192                        uuid_t in,
193                        uuid_t out);
194
195 API_EXPORT(int)
196   noit_check_resolve(noit_check_t *check);
197
198 API_EXPORT(int)
199   noit_check_update(noit_check_t *new_check,
200                     const char *target,
201                     const char *name,
202                     const char *filterset,
203                     noit_hash_table *config,
204                     u_int32_t period,
205                     u_int32_t timeout,
206                     const char *oncheck,
207                     int flags);
208
209 API_EXPORT(noit_boolean)
210   noit_check_is_valid_target(const char *str);
211
212 API_EXPORT(int)
213   noit_check_activate(noit_check_t *check);
214
215 API_EXPORT(int)
216   noit_poller_deschedule(uuid_t in);
217
218 API_EXPORT(noit_check_t *)
219   noit_poller_lookup(uuid_t in);
220
221 API_EXPORT(noit_check_t *)
222   noit_poller_lookup_by_name(char *target, char *name);
223
224 API_EXPORT(int)
225    noit_poller_target_do(char *target, int (*f)(noit_check_t *, void *),
226                          void *closure);
227
228 API_EXPORT(int)
229   noit_check_xpath(char *xpath, int len,
230                    const char *base, const char *arg);
231
232 API_EXPORT(void)
233   noit_check_stats_clear(stats_t *s);
234
235 struct _noit_module;
236 /* This if for modules (passive) than cannot be watched... */
237 API_EXPORT(void)
238   noit_check_passive_set_stats(struct _noit_module *self, noit_check_t *check,
239                                stats_t *newstate);
240 /* This is for normal (active) modules... */
241 API_EXPORT(void)
242   noit_check_set_stats(struct _noit_module *self, noit_check_t *check,
243                         stats_t *newstate);
244
245 API_EXPORT(void)
246   noit_stats_set_metric(stats_t *, const char *, metric_type_t, void *);
247
248 API_EXPORT(void)
249   noit_stats_log_immediate_metric(noit_check_t *check,
250                                   const char *name, metric_type_t type,
251                                   void *value);
252
253 API_EXPORT(const char *)
254   noit_check_available_string(int16_t available);
255 API_EXPORT(const char *)
256   noit_check_state_string(int16_t state);
257 API_EXPORT(int)
258   noit_stats_snprint_metric_value(char *b, int l, metric_t *m);
259 API_EXPORT(int)
260   noit_stats_snprint_metric(char *b, int l, metric_t *m);
261
262 API_EXPORT(noit_check_t *)
263   noit_check_clone(uuid_t in);
264 API_EXPORT(void)
265   noit_poller_free_check(noit_check_t *checker);
266 API_EXPORT(noit_check_t *)
267   noit_check_watch(uuid_t in, int period);
268 API_EXPORT(noit_check_t *)
269   noit_check_get_watch(uuid_t in, int period);
270 API_EXPORT(void)
271   noit_check_transient_add_feed(noit_check_t *check, const char *feed);
272 API_EXPORT(void)
273   noit_check_transient_remove_feed(noit_check_t *check, const char *feed);
274
275 /* These are from noit_check_log.c */
276 API_EXPORT(void) noit_check_log_check(noit_check_t *check);
277 API_EXPORT(void) noit_check_log_status(noit_check_t *check);
278 API_EXPORT(void) noit_check_log_delete(noit_check_t *check);
279 API_EXPORT(void) noit_check_log_bundle(noit_check_t *check);
280 API_EXPORT(void) noit_check_log_metrics(noit_check_t *check);
281 API_EXPORT(void) noit_check_log_metric(noit_check_t *check,
282                                        struct timeval *whence, metric_t *m);
283 API_EXPORT(void) noit_check_extended_id_split(const char *in, int len,
284                                               char *target, int target_len,
285                                               char *module, int module_len,
286                                               char *name, int name_len,
287                                               char *uuid, int uuid_len);
288
289
290 API_EXPORT(char *)
291   noit_console_check_opts(noit_console_closure_t ncct,
292                           noit_console_state_stack_t *stack,
293                           noit_console_state_t *dstate,
294                           int argc, char **argv, int idx);
295 API_EXPORT(char *)
296   noit_console_conf_check_opts(noit_console_closure_t ncct,
297                                noit_console_state_stack_t *stack,
298                                noit_console_state_t *dstate,
299                                int argc, char **argv, int idx);
300
301 #endif
Note: See TracBrowser for help on using the browser.