root/src/noit_check.h

Revision b553f9a4d73487ee85e5cfedf2cd67352b4d5e6b, 8.7 kB (checked in by Theo Schlossnagle <jesus@omniti.com>, 3 years ago)

refs #340

This is a rather major change. Targets can now be hostnames in addition
to IP addresses so long as //checks/@resolve_targets is not false.

If a target is entered that does not look like an IP (inet_pton fails)
then the check is marked as needing resolution NP_RESOLVE.

A passive look-aside dns cache has been implemented in noit_check_resolver.c
that is used to power the whole system and some reasonably simply console
command have been provided:

show dns_cache [fqdn1 [fqdn2]] -- shows the state
dns_cache <fqdn> [fqdn2 [fqdn3]] -- submits for lookup
no dns_cache <fqdn> [fqdn2 [fqdn3]] -- purges from cache

The big change is that modules that relied on check->target to be an IP
address are going to explode when names are provided. Instead, modules
should now use target for the provided target (possibly a FQDN) and use
target_ip (check->target_ip or check.target_ip) for a resolved IP address
and also check for the case of empty string: (check->target_ip[0] == '\0')
for the case that resolution has failed. In lua, the target_ip will be
presented as nil in the case of failed name resolution.

I believe I've updated all necessary components of the system for this to
"just work" but people that have implemented their own check should update
them before they elect to use non-IP addresses as targets.

The dns subsystem supports both IPv4 and IPv6, but currently prefers IPv4
addresses if any are present.

  • 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_UNKNOWN '0'             /* stats_t.{available,state} */
73 #define NP_AVAILABLE 'A'           /* stats_t.available */
74 #define NP_UNAVAILABLE 'U'         /* stats_t.available */
75 #define NP_BAD 'B'                 /* stats_t.state */
76 #define NP_GOOD 'G'                /* stats_t.state */
77
78 typedef enum {
79   METRIC_GUESS = '0',
80   METRIC_INT32 = 'i',
81   METRIC_UINT32 = 'I',
82   METRIC_INT64 = 'l',
83   METRIC_UINT64 = 'L',
84   METRIC_DOUBLE = 'n',
85   METRIC_STRING = 's'
86 } metric_type_t;
87
88 typedef struct {
89   char *metric_name;
90   metric_type_t metric_type;
91   union {
92     double *n;
93     int32_t *i;
94     u_int32_t *I;
95     int64_t *l;
96     u_int64_t *L;
97     char *s;
98     void *vp; /* used for clever assignments */
99   } metric_value;
100 } metric_t;
101
102 typedef struct {
103   struct timeval whence;
104   int8_t available;
105   int8_t state;
106   u_int32_t duration;
107   char *status;
108   noit_hash_table metrics;
109 } stats_t;
110
111 typedef struct dep_list {
112   struct noit_check *check;
113   struct dep_list *next;
114 } dep_list_t;
115
116 typedef struct noit_check {
117   uuid_t checkid;
118   int8_t target_family;
119   union {
120     struct in_addr addr;
121     struct in6_addr addr6;
122   } target_addr;
123   char *target;
124   char *module;
125   char *name;
126   char *filterset;
127   noit_hash_table *config;
128   char *oncheck;               /* target`name of the check that fires us */
129   u_int32_t period;            /* period of checks in milliseconds */
130   u_int32_t timeout;           /* timeout of check in milliseconds */
131   u_int32_t flags;             /* NP_KILLED, NP_RUNNING, NP_TRANSIENT */
132
133   dep_list_t *causal_checks;
134   eventer_t fire_event;
135   struct timeval last_fire_time;
136   struct {
137     stats_t current;
138     stats_t previous;
139   } stats;
140   u_int32_t generation;        /* This can roll, we don't care */
141   void *closure;
142
143   noit_skiplist *feeds;
144   char target_ip[INET6_ADDRSTRLEN];
145 } noit_check_t;
146
147 #define NOIT_CHECK_LIVE(a) ((a)->fire_event != NULL)
148 #define NOIT_CHECK_DISABLED(a) ((a)->flags & NP_DISABLED)
149 #define NOIT_CHECK_CONFIGURED(a) (((a)->flags & NP_UNCONFIG) == 0)
150 #define NOIT_CHECK_RUNNING(a) ((a)->flags & NP_RUNNING)
151 #define NOIT_CHECK_KILLED(a) ((a)->flags & NP_KILLED)
152 #define NOIT_CHECK_SHOULD_RESOLVE(a) ((a)->flags & NP_RESOLVE)
153 /* It is resolved if it is resolved or never needed to be resolved */
154 #define NOIT_CHECK_RESOLVED(a) (((a)->flags & NP_RESOLVED) || (((a)->flags & NP_RESOLVE) == 0))
155
156 API_EXPORT(void) noit_poller_init();
157 API_EXPORT(u_int64_t) noit_check_completion_count();
158 API_EXPORT(int) noit_poller_check_count();
159 API_EXPORT(int) noit_poller_transient_check_count();
160 API_EXPORT(void) noit_poller_reload(const char *xpath); /* NULL for all */
161 API_EXPORT(void) noit_poller_process_checks(const char *xpath);
162 API_EXPORT(void) noit_poller_make_causal_map();
163
164 API_EXPORT(void)
165   noit_check_fake_last_check(noit_check_t *check,
166                              struct timeval *lc, struct timeval *_now);
167 API_EXPORT(int) noit_check_max_initial_stutter();
168
169 API_EXPORT(int)
170   noit_poller_schedule(const char *target,
171                        const char *module,
172                        const char *name,
173                        const char *filterset,
174                        noit_hash_table *config,
175                        u_int32_t period,
176                        u_int32_t timeout,
177                        const char *oncheck,
178                        int flags,
179                        uuid_t in,
180                        uuid_t out);
181
182 API_EXPORT(int)
183   noit_check_resolve(noit_check_t *check);
184
185 API_EXPORT(int)
186   noit_check_update(noit_check_t *new_check,
187                     const char *target,
188                     const char *name,
189                     const char *filterset,
190                     noit_hash_table *config,
191                     u_int32_t period,
192                     u_int32_t timeout,
193                     const char *oncheck,
194                     int flags);
195
196 API_EXPORT(noit_boolean)
197   noit_check_is_valid_target(const char *str);
198
199 API_EXPORT(int)
200   noit_check_activate(noit_check_t *check);
201
202 API_EXPORT(int)
203   noit_poller_deschedule(uuid_t in);
204
205 API_EXPORT(noit_check_t *)
206   noit_poller_lookup(uuid_t in);
207
208 API_EXPORT(noit_check_t *)
209   noit_poller_lookup_by_name(char *target, char *name);
210
211 API_EXPORT(int)
212   noit_check_xpath(char *xpath, int len,
213                    const char *base, const char *arg);
214
215 API_EXPORT(void)
216   noit_check_stats_clear(stats_t *s);
217
218 struct _noit_module;
219 API_EXPORT(void)
220   noit_check_set_stats(struct _noit_module *self, noit_check_t *check,
221                         stats_t *newstate);
222
223 API_EXPORT(void)
224   noit_stats_set_metric(stats_t *, const char *, metric_type_t, void *);
225
226 API_EXPORT(const char *)
227   noit_check_available_string(int16_t available);
228 API_EXPORT(const char *)
229   noit_check_state_string(int16_t state);
230 API_EXPORT(int)
231   noit_stats_snprint_metric_value(char *b, int l, metric_t *m);
232 API_EXPORT(int)
233   noit_stats_snprint_metric(char *b, int l, metric_t *m);
234
235 API_EXPORT(noit_check_t *)
236   noit_check_clone(uuid_t in);
237 API_EXPORT(void)
238   noit_poller_free_check(noit_check_t *checker);
239 API_EXPORT(noit_check_t *)
240   noit_check_watch(uuid_t in, int period);
241 API_EXPORT(noit_check_t *)
242   noit_check_get_watch(uuid_t in, int period);
243 API_EXPORT(void)
244   noit_check_transient_add_feed(noit_check_t *check, const char *feed);
245 API_EXPORT(void)
246   noit_check_transient_remove_feed(noit_check_t *check, const char *feed);
247
248 /* These are from noit_check_log.c */
249 API_EXPORT(void) noit_check_log_check(noit_check_t *check);
250 API_EXPORT(void) noit_check_log_status(noit_check_t *check);
251 API_EXPORT(void) noit_check_log_metrics(noit_check_t *check);
252 API_EXPORT(void) noit_check_extended_id_split(const char *in, int len,
253                                               char *target, int target_len,
254                                               char *module, int module_len,
255                                               char *name, int name_len,
256                                               char *uuid, int uuid_len);
257
258
259 API_EXPORT(char *)
260   noit_console_check_opts(noit_console_closure_t ncct,
261                           noit_console_state_stack_t *stack,
262                           noit_console_state_t *dstate,
263                           int argc, char **argv, int idx);
264 API_EXPORT(char *)
265   noit_console_conf_check_opts(noit_console_closure_t ncct,
266                                noit_console_state_stack_t *stack,
267                                noit_console_state_t *dstate,
268                                int argc, char **argv, int idx);
269
270 #endif
Note: See TracBrowser for help on using the browser.