Changeset e64e042f4c61e4e3c50af3639e028056d8bbfa88
- Timestamp:
- 01/31/08 23:09:53
(5 years ago)
- Author:
- Theo Schlossnagle <jesus@omniti.com>
- git-committer:
- Theo Schlossnagle <jesus@omniti.com> 1201820993 +0000
- git-parent:
[64e4b06c954e1727bf19b222f32cea893b5cc4c1]
- git-author:
- Theo Schlossnagle <jesus@omniti.com> 1201820993 +0000
- Message:
fix up some apis, allow for firing checks only once
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r64e4b06 |
re64e042 |
|
| 76 | 76 | eventer_t fd_event; |
|---|
| 77 | 77 | eventer_t timeout_event; |
|---|
| 78 | | } check_info_t; |
|---|
| | 78 | } serf_check_info_t; |
|---|
| | 79 | |
|---|
| | 80 | typedef struct { |
|---|
| | 81 | serf_check_info_t serf; |
|---|
| | 82 | struct timeval xml_doc_time; |
|---|
| | 83 | xmlDocPtr xml_doc; |
|---|
| | 84 | } resmon_check_info_t; |
|---|
| 79 | 85 | |
|---|
| 80 | 86 | typedef struct { |
|---|
| … | … | |
| 119 | 125 | } |
|---|
| 120 | 126 | static void serf_log_results(noit_module_t *self, noit_check_t check) { |
|---|
| 121 | | check_info_t *ci = check->closure; |
|---|
| | 127 | serf_check_info_t *ci = check->closure; |
|---|
| 122 | 128 | struct timeval duration; |
|---|
| 123 | 129 | stats_t current; |
|---|
| … | … | |
| 149 | 155 | } |
|---|
| 150 | 156 | static void resmon_log_results(noit_module_t *self, noit_check_t check) { |
|---|
| 151 | | check_info_t *ci = check->closure; |
|---|
| | 157 | serf_check_info_t *ci = check->closure; |
|---|
| | 158 | resmon_check_info_t *rci = check->closure; |
|---|
| 152 | 159 | struct timeval duration; |
|---|
| 153 | 160 | stats_t current; |
|---|
| 154 | | int expect_code = 200; |
|---|
| 155 | 161 | int services = 0; |
|---|
| 156 | | char *code_str; |
|---|
| 157 | | char human_buffer[256], code[4], rt[14]; |
|---|
| | 162 | char human_buffer[256], rt[14]; |
|---|
| 158 | 163 | xmlDocPtr resmon_results = NULL; |
|---|
| 159 | 164 | xmlXPathContextPtr xpath_ctxt = NULL; |
|---|
| … | … | |
| 172 | 177 | } |
|---|
| 173 | 178 | if(xpath_ctxt) xmlXPathFreeContext(xpath_ctxt); |
|---|
| 174 | | if(resmon_results) xmlFreeDoc(resmon_results); |
|---|
| | 179 | |
|---|
| | 180 | /* Save out results for future dependent checks */ |
|---|
| | 181 | memcpy(&rci->xml_doc_time, &ci->finish_time, sizeof(ci->finish_time)); |
|---|
| | 182 | if(rci->xml_doc) xmlFreeDoc(rci->xml_doc); |
|---|
| | 183 | rci->xml_doc = resmon_results; |
|---|
| 175 | 184 | |
|---|
| 176 | 185 | sub_timeval(ci->finish_time, check->last_fire_time, &duration); |
|---|
| … | … | |
| 194 | 203 | void *closure, struct timeval *now) { |
|---|
| 195 | 204 | serf_closure_t *ccl = (serf_closure_t *)closure; |
|---|
| 196 | | check_info_t *ci = (check_info_t *)ccl->check->closure; |
|---|
| | 205 | serf_check_info_t *ci = (serf_check_info_t *)ccl->check->closure; |
|---|
| 197 | 206 | |
|---|
| 198 | 207 | noitLT(nldeb, now, "serf_complete(%s)\n", ccl->check->target); |
|---|
| … | … | |
| 219 | 228 | apr_pollfd_t desc = { 0 }; |
|---|
| 220 | 229 | serf_closure_t *sct = closure; |
|---|
| 221 | | check_info_t *ci = sct->check->closure; |
|---|
| | 230 | serf_check_info_t *ci = sct->check->closure; |
|---|
| 222 | 231 | |
|---|
| 223 | 232 | desc.desc_type = APR_POLL_SOCKET; |
|---|
| … | … | |
| 303 | 312 | apr_status_t status; |
|---|
| 304 | 313 | handler_baton_t *ctx = handler_baton; |
|---|
| 305 | | check_info_t *ci = ctx->check->closure; |
|---|
| | 314 | serf_check_info_t *ci = ctx->check->closure; |
|---|
| 306 | 315 | |
|---|
| 307 | 316 | if(response == NULL) { |
|---|
| … | … | |
| 447 | 456 | if(pfd->reqevents & APR_POLLERR) e->mask |= EVENTER_EXCEPTION; |
|---|
| 448 | 457 | if(newe) { |
|---|
| 449 | | check_info_t *ci = sct->check->closure; |
|---|
| | 458 | serf_check_info_t *ci = sct->check->closure; |
|---|
| 450 | 459 | eventer_add(newe); |
|---|
| 451 | 460 | ci->fd_event = newe; |
|---|
| … | … | |
| 461 | 470 | void *serf_baton) { |
|---|
| 462 | 471 | serf_closure_t *sct = user_baton; |
|---|
| 463 | | check_info_t *ci; |
|---|
| | 472 | serf_check_info_t *ci; |
|---|
| 464 | 473 | eventer_t e; |
|---|
| 465 | 474 | |
|---|
| … | … | |
| 476 | 485 | static int serf_initiate(noit_module_t *self, noit_check_t check) { |
|---|
| 477 | 486 | serf_closure_t *ccl; |
|---|
| 478 | | check_info_t *ci; |
|---|
| | 487 | serf_check_info_t *ci; |
|---|
| 479 | 488 | struct timeval when, p_int; |
|---|
| 480 | 489 | apr_status_t status; |
|---|
| … | … | |
| 484 | 493 | |
|---|
| 485 | 494 | mod_config = noit_module_get_userdata(self); |
|---|
| 486 | | ci = (check_info_t *)check->closure; |
|---|
| | 495 | ci = (serf_check_info_t *)check->closure; |
|---|
| 487 | 496 | /* We cannot be running */ |
|---|
| 488 | 497 | assert(!(check->flags & NP_RUNNING)); |
|---|
| … | … | |
| 629 | 638 | return 0; |
|---|
| 630 | 639 | } |
|---|
| 631 | | static int serf_initiate_check(noit_module_t *self, noit_check_t check) { |
|---|
| 632 | | check->closure = calloc(1, sizeof(check_info_t)); |
|---|
| 633 | | serf_schedule_next(self, NULL, check, NULL); |
|---|
| 634 | | return 0; |
|---|
| 635 | | } |
|---|
| | 640 | static int serf_initiate_check(noit_module_t *self, noit_check_t check, |
|---|
| | 641 | int once) { |
|---|
| | 642 | if(!check->closure) check->closure = calloc(1, sizeof(serf_check_info_t)); |
|---|
| | 643 | if(once) { |
|---|
| | 644 | serf_initiate(self, check); |
|---|
| | 645 | return 0; |
|---|
| | 646 | } |
|---|
| | 647 | /* If check->fire_event, we're already scheduled... */ |
|---|
| | 648 | if(!check->fire_event) |
|---|
| | 649 | serf_schedule_next(self, NULL, check, NULL); |
|---|
| | 650 | return 0; |
|---|
| | 651 | } |
|---|
| | 652 | static int resmon_initiate_check(noit_module_t *self, noit_check_t check, |
|---|
| | 653 | int once) { |
|---|
| | 654 | /* resmon_check_info_t gives us a bit more space */ |
|---|
| | 655 | if(!check->closure) check->closure = calloc(1, sizeof(resmon_check_info_t)); |
|---|
| | 656 | if(once) { |
|---|
| | 657 | serf_initiate(self, check); |
|---|
| | 658 | return 0; |
|---|
| | 659 | } |
|---|
| | 660 | if(!check->fire_event) |
|---|
| | 661 | serf_schedule_next(self, NULL, check, NULL); |
|---|
| | 662 | return 0; |
|---|
| | 663 | } |
|---|
| | 664 | |
|---|
| 636 | 665 | |
|---|
| 637 | 666 | static int serf_onload(noit_module_t *self) { |
|---|
| … | … | |
| 668 | 697 | resmon_config, |
|---|
| 669 | 698 | serf_init, |
|---|
| 670 | | serf_initiate_check |
|---|
| | 699 | resmon_initiate_check |
|---|
| 671 | 700 | }; |
|---|
| 672 | 701 | |
|---|
| r1afde4e |
re64e042 |
|
| 313 | 313 | return 0; |
|---|
| 314 | 314 | } |
|---|
| 315 | | static int ping_icmp_send(noit_module_t *self, noit_check_t check, |
|---|
| 316 | | int interval, int count) { |
|---|
| | 315 | static int ping_icmp_send(noit_module_t *self, noit_check_t check) { |
|---|
| 317 | 316 | struct timeval when, p_int; |
|---|
| 318 | 317 | struct icmp *icp; |
|---|
| … | … | |
| 322 | 321 | int packet_len, i; |
|---|
| 323 | 322 | eventer_t newe; |
|---|
| | 323 | const char *config_val; |
|---|
| | 324 | |
|---|
| | 325 | int interval = PING_INTERVAL; |
|---|
| | 326 | int count = PING_COUNT; |
|---|
| | 327 | if(noit_hash_retrieve(check->config, "interval", strlen("interval"), |
|---|
| | 328 | (void **)&config_val)) |
|---|
| | 329 | interval = atoi(config_val); |
|---|
| | 330 | if(noit_hash_retrieve(check->config, "count", strlen("count"), |
|---|
| | 331 | (void **)&config_val)) |
|---|
| | 332 | count = atoi(config_val); |
|---|
| 324 | 333 | |
|---|
| 325 | 334 | check->flags |= NP_RUNNING; |
|---|
| … | … | |
| 436 | 445 | struct ping_closure *cl = (struct ping_closure *)closure; |
|---|
| 437 | 446 | ping_icmp_schedule_next(cl->self, e, cl->check, now); |
|---|
| 438 | | ping_icmp_send(cl->self, cl->check, PING_INTERVAL, PING_COUNT); |
|---|
| | 447 | ping_icmp_send(cl->self, cl->check); |
|---|
| 439 | 448 | free(cl); |
|---|
| 440 | 449 | return 0; |
|---|
| 441 | 450 | } |
|---|
| 442 | | static int ping_icmp_initiate_check(noit_module_t *self, noit_check_t check) { |
|---|
| 443 | | check->closure = calloc(1, sizeof(struct check_info)); |
|---|
| 444 | | ping_icmp_schedule_next(self, NULL, check, NULL); |
|---|
| | 451 | static int ping_icmp_initiate_check(noit_module_t *self, noit_check_t check, |
|---|
| | 452 | int once) { |
|---|
| | 453 | if(!check->closure) check->closure = calloc(1, sizeof(struct check_info)); |
|---|
| | 454 | if(once) { |
|---|
| | 455 | ping_icmp_send(self, check); |
|---|
| | 456 | return 0; |
|---|
| | 457 | } |
|---|
| | 458 | if(!check->fire_event) |
|---|
| | 459 | ping_icmp_schedule_next(self, NULL, check, NULL); |
|---|
| 445 | 460 | return 0; |
|---|
| 446 | 461 | } |
|---|
| rb09f3a7 |
re64e042 |
|
| 22 | 22 | int (*config)(struct _noit_module *, noit_hash_table *options); |
|---|
| 23 | 23 | int (*init)(struct _noit_module *); |
|---|
| 24 | | int (*initiate_check)(struct _noit_module *, noit_check_t check); |
|---|
| | 24 | int (*initiate_check)(struct _noit_module *, noit_check_t check, int once); |
|---|
| 25 | 25 | void *opaque_handle; |
|---|
| 26 | 26 | } noit_module_t; |
|---|
| r1afde4e |
re64e042 |
|
| 14 | 14 | #include "utils/noit_log.h" |
|---|
| 15 | 15 | #include "utils/noit_hash.h" |
|---|
| | 16 | #include "utils/noit_skiplist.h" |
|---|
| 16 | 17 | #include "noit_conf.h" |
|---|
| 17 | 18 | #include "noit_poller.h" |
|---|
| … | … | |
| 20 | 21 | |
|---|
| 21 | 22 | static noit_hash_table polls = NOIT_HASH_EMPTY; |
|---|
| | 23 | static noit_skiplist polls_by_name = { 0 }; |
|---|
| 22 | 24 | static u_int32_t __config_load_generation = 0; |
|---|
| 23 | 25 | struct uuid_dummy { |
|---|
| … | … | |
| 43 | 45 | } |
|---|
| 44 | 46 | return "???"; |
|---|
| | 47 | } |
|---|
| | 48 | static int __check_name_compare(void *a, void *b) { |
|---|
| | 49 | noit_check_t ac = a; |
|---|
| | 50 | noit_check_t bc = b; |
|---|
| | 51 | int rv; |
|---|
| | 52 | if((rv = strcmp(ac->target, bc->target)) != 0) return rv; |
|---|
| | 53 | if((rv = strcmp(ac->name, bc->name)) != 0) return rv; |
|---|
| | 54 | return 0; |
|---|
| 45 | 55 | } |
|---|
| 46 | 56 | void |
|---|
| … | … | |
| 55 | 65 | char module[256]; |
|---|
| 56 | 66 | char name[256]; |
|---|
| 57 | | int period, timeout; |
|---|
| | 67 | int period = 0, timeout = 0; |
|---|
| 58 | 68 | uuid_t uuid, out_uuid; |
|---|
| 59 | 69 | noit_hash_table *options; |
|---|
| … | … | |
| 119 | 129 | mod = noit_module_lookup(check->module); |
|---|
| 120 | 130 | if(mod) { |
|---|
| 121 | | mod->initiate_check(mod, check); |
|---|
| | 131 | mod->initiate_check(mod, check, 0); |
|---|
| 122 | 132 | } |
|---|
| 123 | 133 | else { |
|---|
| … | … | |
| 129 | 139 | void |
|---|
| 130 | 140 | noit_poller_init() { |
|---|
| | 141 | noit_skiplist_init(&polls_by_name); |
|---|
| | 142 | noit_skiplist_set_compare(&polls_by_name, __check_name_compare, |
|---|
| | 143 | __check_name_compare); |
|---|
| 131 | 144 | noit_poller_load_checks(); |
|---|
| 132 | 145 | noit_poller_initiate(); |
|---|
| … | … | |
| 192 | 205 | (char *)new_check->checkid, UUID_SIZE, |
|---|
| 193 | 206 | new_check)); |
|---|
| | 207 | noit_skiplist_insert(&polls_by_name, new_check); |
|---|
| 194 | 208 | uuid_copy(out, new_check->checkid); |
|---|
| 195 | 209 | return 0; |
|---|
| … | … | |
| 236 | 250 | } |
|---|
| 237 | 251 | return NULL; |
|---|
| | 252 | } |
|---|
| | 253 | noit_check_t |
|---|
| | 254 | noit_poller_lookup_by_name(char *target, char *name) { |
|---|
| | 255 | noit_check_t check, tmp_check; |
|---|
| | 256 | tmp_check = calloc(1, sizeof(*tmp_check)); |
|---|
| | 257 | tmp_check->target = target; |
|---|
| | 258 | tmp_check->name = name; |
|---|
| | 259 | check = noit_skiplist_find(&polls_by_name, &tmp_check, NULL); |
|---|
| | 260 | free(tmp_check); |
|---|
| | 261 | return check; |
|---|
| 238 | 262 | } |
|---|
| 239 | 263 | |
|---|
| … | … | |
| 259 | 283 | report_change = 1; |
|---|
| 260 | 284 | |
|---|
| | 285 | noitL(noit_error, "%s/%s <- [%s]\n", check->target, check->module, |
|---|
| | 286 | check->stats.current.status); |
|---|
| 261 | 287 | if(report_change) { |
|---|
| 262 | | noitL(noit_debug, "%s/%s -> [%s/%s]\n", |
|---|
| | 288 | noitL(noit_error, "%s/%s -> [%s/%s]\n", |
|---|
| 263 | 289 | check->target, check->module, |
|---|
| 264 | 290 | __noit_check_available_string(check->stats.current.available), |
|---|
| rf59d8ed |
re64e042 |
|
| 94 | 94 | noit_poller_lookup(uuid_t in); |
|---|
| 95 | 95 | |
|---|
| | 96 | API_EXPORT(noit_check_t) |
|---|
| | 97 | noit_poller_lookup_by_name(char *target, char *name); |
|---|
| | 98 | |
|---|
| 96 | 99 | API_EXPORT(void) |
|---|
| 97 | 100 | noit_poller_set_state(noit_check_t check, stats_t *newstate); |
|---|