root/src/noit_check.h

Revision 2ff4db5a6730270eb30827e23883ed354c42ddf6, 14.8 kB (checked in by Phil Maddox <philip.maddox@circonus.com>, 1 week ago)

Explicitly Initialize Mtev Hash Tables

Rather than using MTEV_HASH_EMPTY or not calling any initialization at
all, explicitly initialize hash tables.

  • Property mode set to 100644
Line 
1 /*
2  * Copyright (c) 2007, OmniTI Computer Consulting, Inc.
3  * All rights reserved.
4  * Copyright (c) 2013-2015, Circonus, Inc. All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are
8  * met:
9  *
10  *     * Redistributions of source code must retain the above copyright
11  *       notice, this list of conditions and the following disclaimer.
12  *     * Redistributions in binary form must reproduce the above
13  *       copyright notice, this list of conditions and the following
14  *       disclaimer in the documentation and/or other materials provided
15  *       with the distribution.
16  *     * Neither the name OmniTI Computer Consulting, Inc. nor the names
17  *       of its contributors may be used to endorse or promote products
18  *       derived from this software without specific prior written
19  *       permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33
34 #ifndef _NOIT_CHECK_H
35 #define _NOIT_CHECK_H
36
37 #include <mtev_defines.h>
38
39 #include <uuid/uuid.h>
40 #include <netinet/in.h>
41
42 #include <eventer/eventer.h>
43 #include <mtev_hash.h>
44 #include <mtev_skiplist.h>
45 #include <mtev_hooks.h>
46 #include <mtev_conf.h>
47 #include <mtev_console.h>
48
49 #include "noit_metric.h"
50
51 /*
52  * Checks:
53  *  attrs:
54  *   UUID
55  *   host (target)
56  *   check (module)
57  *   name (identifying the check to the user if
58  *         multiple checks of the same module are specified)
59  *   config (params for the module)
60  *   period (ms)
61  *   timeout (ms)
62  *  transient:
63  *   eventer_t (fire)
64  *   stats_t [inprogress, current, previous]
65  *   closure
66  */
67
68 /* The check is currently in-flight (running) */
69 #define NP_RUNNING               0x00000001
70 /* The check has been killed by the scheduling system */
71 #define NP_KILLED                0x00000002
72 /* The check is disable and should not be run */
73 #define NP_DISABLED              0x00000004
74 /* The check is not sufficiently configured to operate */
75 #define NP_UNCONFIG              0x00000008
76 /* The check is a transient copy of another check */
77 #define NP_TRANSIENT             0x00000010
78 /* The check requires name service resolution */
79 #define NP_RESOLVE               0x00000020
80 /* Name service resolution has been compelted for the check */
81 #define NP_RESOLVED              0x00000040
82 /* This check should have 'S' lines suppressed from logging */
83 #define NP_SUPPRESS_STATUS       0x00001000
84 /* This check should have 'M' lines suppressed from logging */
85 #define NP_SUPPRESS_METRICS      0x00002000
86 /* The check should lookup IPv6 records before IPv4 */
87 #define NP_PREFER_IPV6           0x00004000
88 /* Do no fallback to IPv6 from IPv4 and vice versa */
89 #define NP_SINGLE_RESOLVE        0x00008000
90 /* Indicates that the check is receiving data passively
91  * and it does not do anything during invocation to collect metrics
92  */
93 #define NP_PASSIVE_COLLECTION    0x00010000
94
95 #define PREFER_IPV4 "prefer-ipv4"
96 #define PREFER_IPV6 "prefer-ipv6"
97 #define FORCE_IPV4  "force-ipv4"
98 #define FORCE_IPV6  "force-ipv6"
99
100 #define NP_UNKNOWN '0'             /* stats_t.{available,state} */
101 #define NP_AVAILABLE 'A'           /* stats_t.available */
102 #define NP_UNAVAILABLE 'U'         /* stats_t.available */
103 #define NP_BAD 'B'                 /* stats_t.state */
104 #define NP_GOOD 'G'                /* stats_t.state */
105
106 typedef struct stats_t stats_t;
107
108 typedef struct dep_list {
109   struct noit_check *check;
110   struct dep_list *next;
111 } dep_list_t;
112
113 typedef struct noit_check {
114   uuid_t checkid;
115   int8_t target_family;
116   union {
117     struct in_addr addr;
118     struct in6_addr addr6;
119   } target_addr;
120   char *target;
121   char *module;
122   char *name;
123   char *filterset;
124   mtev_hash_table *config;
125   char *oncheck;               /* target`name of the check that fires us */
126   u_int32_t period;            /* period of checks in milliseconds */
127   u_int32_t timeout;           /* timeout of check in milliseconds */
128   u_int32_t flags;             /* NP_KILLED, NP_RUNNING, NP_TRANSIENT */
129
130   dep_list_t *causal_checks;
131   eventer_t fire_event;
132   struct timeval last_fire_time;
133   u_int32_t generation;        /* This can roll, we don't care */
134   void *closure;
135
136   mtev_skiplist *feeds;
137   char target_ip[INET6_ADDRSTRLEN];
138   void **module_metadata;
139   mtev_hash_table **module_configs;
140   struct timeval initial_schedule_time;
141   int64_t config_seq;          /* If non-zero, must increase */
142
143   void *statistics;
144 } noit_check_t;
145
146 #define NOIT_CHECK_LIVE(a) ((a)->fire_event != NULL)
147 #define NOIT_CHECK_DISABLED(a) ((a)->flags & NP_DISABLED)
148 #define NOIT_CHECK_CONFIGURED(a) (((a)->flags & NP_UNCONFIG) == 0)
149 #define NOIT_CHECK_RUNNING(a) ((a)->flags & NP_RUNNING)
150 #define NOIT_CHECK_KILLED(a) ((a)->flags & NP_KILLED)
151 #define NOIT_CHECK_SHOULD_RESOLVE(a) ((a)->flags & NP_RESOLVE)
152 /* It is resolved if it is resolved or never needed to be resolved */
153 #define NOIT_CHECK_RESOLVED(a) (((a)->flags & NP_RESOLVED) || (((a)->flags & NP_RESOLVE) == 0))
154 #define NOIT_CHECK_PREFER_V6(a) ((a)->flags & NP_PREFER_IPV6)
155 #define NOIT_CHECK_SINGLE_RESOLVE(a) ((a)->flags & NP_SINGLE_RESOLVE)
156
157 API_EXPORT(void) noit_poller_init();
158 API_EXPORT(u_int64_t) noit_check_completion_count();
159 API_EXPORT(u_int64_t) noit_check_metric_count();
160 API_EXPORT(void) noit_check_metric_count_add(int);
161 API_EXPORT(int) noit_poller_check_count();
162 API_EXPORT(int) noit_poller_transient_check_count();
163 API_EXPORT(void) noit_poller_reload(const char *xpath); /* NULL for all */
164 API_EXPORT(void) noit_poller_process_checks(const char *xpath);
165 API_EXPORT(void) noit_poller_make_causal_map();
166 API_EXPORT(void) noit_check_dns_ignore_tld(const char* extension, const char* ignore);
167
168 API_EXPORT(void)
169   noit_check_fake_last_check(noit_check_t *check,
170                              struct timeval *lc, struct timeval *_now);
171
172 API_EXPORT(int)
173   noit_poller_schedule(const char *target,
174                        const char *module,
175                        const char *name,
176                        const char *filterset,
177                        mtev_hash_table *config,
178                        mtev_hash_table **mconfig,
179                        u_int32_t period,
180                        u_int32_t timeout,
181                        const char *oncheck,
182                        int64_t seq,
183                        int flags,
184                        uuid_t in,
185                        uuid_t out);
186
187 API_EXPORT(int)
188   noit_check_resolve(noit_check_t *check);
189
190 API_EXPORT(int)
191   noit_check_update(noit_check_t *new_check,
192                     const char *target,
193                     const char *name,
194                     const char *filterset,
195                     mtev_hash_table *config,
196                     mtev_hash_table **mconfig,
197                     u_int32_t period,
198                     u_int32_t timeout,
199                     const char *oncheck,
200                     int64_t seq,
201                     int flags);
202
203 API_EXPORT(mtev_boolean)
204   noit_check_is_valid_target(const char *str);
205
206 API_EXPORT(int)
207   noit_check_activate(noit_check_t *check);
208
209 API_EXPORT(int)
210   noit_poller_deschedule(uuid_t in, mtev_boolean log);
211
212 API_EXPORT(noit_check_t *)
213   noit_poller_lookup(uuid_t in);
214
215 API_EXPORT(noit_check_t *)
216   noit_poller_lookup_by_name(char *target, char *name);
217
218 API_EXPORT(int)
219   noit_poller_lookup_by_ip_module(const char *ip, const char *mod,
220                                   noit_check_t **checks, int nchecks);
221
222 API_EXPORT(int)
223    noit_poller_target_ip_do(const char *target,
224                             int (*f)(noit_check_t *, void *),
225                             void *closure);
226
227 API_EXPORT(int)
228    noit_poller_target_do(const char *target,
229                          int (*f)(noit_check_t *, void *),
230                          void *closure);
231
232 API_EXPORT(int)
233    noit_poller_do(int (*f)(noit_check_t *, void *),
234                   void *closure);
235
236 API_EXPORT(int)
237   noit_check_xpath(char *xpath, int len,
238                    const char *base, const char *arg);
239
240 struct _noit_module;
241
242 stats_t *
243 noit_check_get_stats_inprogress(noit_check_t *c);
244 stats_t *
245 noit_check_get_stats_current(noit_check_t *c);
246 stats_t *
247 noit_check_get_stats_previous(noit_check_t *c);
248
249 /* This if for modules (passive) than cannot be watched... */
250 API_EXPORT(void)
251   noit_check_passive_set_stats(noit_check_t *check);
252
253 /* This is for normal (active) modules... */
254 API_EXPORT(void)
255   noit_check_set_stats(noit_check_t *check);
256
257 API_EXPORT(void)
258   noit_stats_set_whence(noit_check_t *check, struct timeval *t);
259 API_EXPORT(void)
260   noit_stats_set_duration(noit_check_t *check, u_int32_t t);
261 API_EXPORT(void)
262   noit_stats_set_available(noit_check_t *check, int8_t t);
263 API_EXPORT(void)
264   noit_stats_set_state(noit_check_t *check, int8_t t);
265 API_EXPORT(void)
266   noit_stats_set_status(noit_check_t *check, const char *t);
267
268 API_EXPORT(metric_t *)
269   noit_stats_get_metric(noit_check_t *check, stats_t *, const char *);
270
271 API_EXPORT(void)
272   noit_stats_set_metric(noit_check_t *check,
273                         const char *, metric_type_t, const void *);
274
275 API_EXPORT(void)
276   noit_stats_set_metric_coerce(noit_check_t *check,
277                                const char *, metric_type_t,
278                                const char *);
279
280 API_EXPORT(void)
281   noit_stats_log_immediate_metric(noit_check_t *check,
282                                   const char *name, metric_type_t type,
283                                   const void *value);
284
285 API_EXPORT(const char *)
286   noit_check_available_string(int16_t available);
287 API_EXPORT(const char *)
288   noit_check_state_string(int16_t state);
289 API_EXPORT(int)
290   noit_calc_rtype_flag(char *resolve_rtype);
291 API_EXPORT(int)
292   noit_stats_snprint_metric_value(char *b, int l, metric_t *m);
293 API_EXPORT(int)
294   noit_stats_snprint_metric(char *b, int l, metric_t *m);
295
296 API_EXPORT(noit_check_t *)
297   noit_check_clone(uuid_t in);
298 API_EXPORT(void)
299   noit_poller_free_check(noit_check_t *checker);
300 API_EXPORT(noit_check_t *)
301   noit_check_watch(uuid_t in, int period);
302 API_EXPORT(noit_check_t *)
303   noit_check_get_watch(uuid_t in, int period);
304 API_EXPORT(void)
305   noit_check_transient_add_feed(noit_check_t *check, const char *feed);
306 API_EXPORT(void)
307   noit_check_transient_remove_feed(noit_check_t *check, const char *feed);
308
309 /* Register your module */
310 API_EXPORT(int)
311   noit_check_register_module(const char *);
312 /* Find a registered module's id */
313 API_EXPORT(int)
314   noit_check_registered_module_by_name(const char *name);
315 /* Get the count of registered modules */
316 API_EXPORT(int)
317   noit_check_registered_module_cnt();
318 /* Get a registered module name by id */
319 API_EXPORT(const char *)
320   noit_check_registered_module(int);
321
322 API_EXPORT(int)
323   noit_check_validate_target(const char *);
324 API_EXPORT(int)
325   noit_check_validate_name(const char *);
326
327 API_EXPORT(void)
328   noit_check_set_module_metadata(noit_check_t *, int, void *, void (*freefunc)(void *));
329 API_EXPORT(void)
330   noit_check_set_module_config(noit_check_t *, int, mtev_hash_table *);
331 API_EXPORT(void *)
332   noit_check_get_module_metadata(noit_check_t *, int);
333 API_EXPORT(mtev_hash_table *)
334   noit_check_get_module_config(noit_check_t *, int);
335
336 /* These are from noit_check_log.c */
337 API_EXPORT(void) noit_check_log_check(noit_check_t *check);
338 API_EXPORT(void) noit_filterset_log_auto_add(char *filter, noit_check_t *check,
339                                              metric_t *m, mtev_boolean allow);
340 API_EXPORT(void) noit_check_log_status(noit_check_t *check);
341 API_EXPORT(void) noit_check_log_delete(noit_check_t *check);
342 API_EXPORT(void) noit_check_log_bundle(noit_check_t *check);
343 API_EXPORT(void) noit_check_log_metrics(noit_check_t *check);
344 API_EXPORT(void) noit_check_log_metric(noit_check_t *check,
345                                        struct timeval *whence, metric_t *m);
346 API_EXPORT(void) noit_check_extended_id_split(const char *in, int len,
347                                               char *target, int target_len,
348                                               char *module, int module_len,
349                                               char *name, int name_len,
350                                               char *uuid, int uuid_len);
351
352
353 API_EXPORT(char *)
354   noit_console_check_opts(mtev_console_closure_t ncct,
355                           mtev_console_state_stack_t *stack,
356                           mtev_console_state_t *dstate,
357                           int argc, char **argv, int idx);
358 API_EXPORT(char *)
359   noit_console_conf_check_opts(mtev_console_closure_t ncct,
360                                mtev_console_state_stack_t *stack,
361                                mtev_console_state_t *dstate,
362                                int argc, char **argv, int idx);
363
364 API_EXPORT(void) check_slots_inc_tv(struct timeval *tv);
365 API_EXPORT(void) check_slots_dec_tv(struct timeval *tv);
366
367 API_EXPORT(struct timeval *)
368   noit_check_stats_whence(stats_t *s, struct timeval *n);
369 API_EXPORT(int8_t)
370   noit_check_stats_available(stats_t *s, int8_t *n);
371 API_EXPORT(int8_t)
372   noit_check_stats_state(stats_t *s, int8_t *n);
373 API_EXPORT(u_int32_t)
374   noit_check_stats_duration(stats_t *s, u_int32_t *n);
375 API_EXPORT(const char *)
376   noit_check_stats_status(stats_t *s, const char *n);
377 API_EXPORT(mtev_hash_table *)
378   noit_check_stats_metrics(stats_t *s);
379 API_EXPORT(void)
380   noit_check_init_globals(void);
381
382 MTEV_HOOK_PROTO(check_config_fixup,
383                 (noit_check_t *check),
384                 void *, closure,
385                 (void *closure, noit_check_t *check))
386
387 MTEV_HOOK_PROTO(check_stats_set_metric,
388                 (noit_check_t *check, stats_t *stats, metric_t *m),
389                 void *, closure,
390                 (void *closure, noit_check_t *check, stats_t *stats, metric_t *m))
391
392 MTEV_HOOK_PROTO(check_stats_set_metric_coerce,
393                 (noit_check_t *check, stats_t *stats, const char *name,
394                  metric_type_t type, const char *v, mtev_boolean success),
395                 void *, closure,
396                 (void *closure, noit_check_t *check, stats_t *stats, const char *name,
397                  metric_type_t type, const char *v, mtev_boolean success))
398
399 MTEV_HOOK_PROTO(check_passive_log_stats,
400                 (noit_check_t *check),
401                 void *, closure,
402                 (void *closure, noit_check_t *check))
403
404 MTEV_HOOK_PROTO(check_set_stats,
405                 (noit_check_t *check),
406                 void *, closure,
407                 (void *closure, noit_check_t *check))
408
409 MTEV_HOOK_PROTO(check_log_stats,
410                 (noit_check_t *check),
411                 void *, closure,
412                 (void *closure, noit_check_t *check))
413
414 #endif
Note: See TracBrowser for help on using the browser.