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