Changeset e64e042f4c61e4e3c50af3639e028056d8bbfa88

Show
Ignore:
Timestamp:
01/31/08 23:09:53 (7 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
  • src/modules/http.c

    r64e4b06 re64e042  
    7676  eventer_t fd_event; 
    7777  eventer_t timeout_event; 
    78 } check_info_t; 
     78} serf_check_info_t; 
     79 
     80typedef struct { 
     81  serf_check_info_t serf; 
     82  struct timeval xml_doc_time; 
     83  xmlDocPtr xml_doc; 
     84} resmon_check_info_t; 
    7985 
    8086typedef struct { 
     
    119125} 
    120126static 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; 
    122128  struct timeval duration; 
    123129  stats_t current; 
     
    149155} 
    150156static 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; 
    152159  struct timeval duration; 
    153160  stats_t current; 
    154   int expect_code = 200; 
    155161  int services = 0; 
    156   char *code_str; 
    157   char human_buffer[256], code[4], rt[14]; 
     162  char human_buffer[256], rt[14]; 
    158163  xmlDocPtr resmon_results = NULL; 
    159164  xmlXPathContextPtr xpath_ctxt = NULL; 
     
    172177  } 
    173178  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; 
    175184 
    176185  sub_timeval(ci->finish_time, check->last_fire_time, &duration); 
     
    194203                         void *closure, struct timeval *now) { 
    195204  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; 
    197206 
    198207  noitLT(nldeb, now, "serf_complete(%s)\n", ccl->check->target); 
     
    219228  apr_pollfd_t desc = { 0 }; 
    220229  serf_closure_t *sct = closure; 
    221   check_info_t *ci = sct->check->closure; 
     230  serf_check_info_t *ci = sct->check->closure; 
    222231 
    223232  desc.desc_type = APR_POLL_SOCKET; 
     
    303312  apr_status_t status; 
    304313  handler_baton_t *ctx = handler_baton; 
    305   check_info_t *ci = ctx->check->closure; 
     314  serf_check_info_t *ci = ctx->check->closure; 
    306315 
    307316  if(response == NULL) { 
     
    447456  if(pfd->reqevents & APR_POLLERR) e->mask |= EVENTER_EXCEPTION; 
    448457  if(newe) { 
    449     check_info_t *ci = sct->check->closure; 
     458    serf_check_info_t *ci = sct->check->closure; 
    450459    eventer_add(newe); 
    451460    ci->fd_event = newe; 
     
    461470                                        void *serf_baton) { 
    462471  serf_closure_t *sct = user_baton; 
    463   check_info_t *ci; 
     472  serf_check_info_t *ci; 
    464473  eventer_t e; 
    465474 
     
    476485static int serf_initiate(noit_module_t *self, noit_check_t check) { 
    477486  serf_closure_t *ccl; 
    478   check_info_t *ci; 
     487  serf_check_info_t *ci; 
    479488  struct timeval when, p_int; 
    480489  apr_status_t status; 
     
    484493 
    485494  mod_config = noit_module_get_userdata(self); 
    486   ci = (check_info_t *)check->closure; 
     495  ci = (serf_check_info_t *)check->closure; 
    487496  /* We cannot be running */ 
    488497  assert(!(check->flags & NP_RUNNING)); 
     
    629638  return 0; 
    630639} 
    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 
     640static 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
     652static 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 
    636665 
    637666static int serf_onload(noit_module_t *self) { 
     
    668697  resmon_config, 
    669698  serf_init, 
    670   serf_initiate_check 
     699  resmon_initiate_check 
    671700}; 
    672701 
  • src/modules/ping_icmp.c

    r1afde4e re64e042  
    313313  return 0; 
    314314} 
    315 static int ping_icmp_send(noit_module_t *self, noit_check_t check, 
    316                           int interval, int count) { 
     315static int ping_icmp_send(noit_module_t *self, noit_check_t check) { 
    317316  struct timeval when, p_int; 
    318317  struct icmp *icp; 
     
    322321  int packet_len, i; 
    323322  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); 
    324333 
    325334  check->flags |= NP_RUNNING; 
     
    436445  struct ping_closure *cl = (struct ping_closure *)closure; 
    437446  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); 
    439448  free(cl); 
    440449  return 0; 
    441450} 
    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); 
     451static 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); 
    445460  return 0; 
    446461} 
  • src/noit_module.h

    rb09f3a7 re64e042  
    2222  int (*config)(struct _noit_module *, noit_hash_table *options); 
    2323  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); 
    2525  void *opaque_handle; 
    2626} noit_module_t; 
  • src/noit_poller.c

    r1afde4e re64e042  
    1414#include "utils/noit_log.h" 
    1515#include "utils/noit_hash.h" 
     16#include "utils/noit_skiplist.h" 
    1617#include "noit_conf.h" 
    1718#include "noit_poller.h" 
     
    2021 
    2122static noit_hash_table polls = NOIT_HASH_EMPTY; 
     23static noit_skiplist polls_by_name = { 0 }; 
    2224static u_int32_t __config_load_generation = 0; 
    2325struct uuid_dummy { 
     
    4345  } 
    4446  return "???"; 
     47} 
     48static 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; 
    4555} 
    4656void 
     
    5565    char module[256]; 
    5666    char name[256]; 
    57     int period, timeout
     67    int period = 0, timeout = 0
    5868    uuid_t uuid, out_uuid; 
    5969    noit_hash_table *options; 
     
    119129    mod = noit_module_lookup(check->module); 
    120130    if(mod) { 
    121       mod->initiate_check(mod, check); 
     131      mod->initiate_check(mod, check, 0); 
    122132    } 
    123133    else { 
     
    129139void 
    130140noit_poller_init() { 
     141  noit_skiplist_init(&polls_by_name); 
     142  noit_skiplist_set_compare(&polls_by_name, __check_name_compare, 
     143                            __check_name_compare); 
    131144  noit_poller_load_checks(); 
    132145  noit_poller_initiate(); 
     
    192205                         (char *)new_check->checkid, UUID_SIZE, 
    193206                         new_check)); 
     207  noit_skiplist_insert(&polls_by_name, new_check); 
    194208  uuid_copy(out, new_check->checkid); 
    195209  return 0; 
     
    236250  } 
    237251  return NULL; 
     252} 
     253noit_check_t 
     254noit_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; 
    238262} 
    239263 
     
    259283    report_change = 1; 
    260284 
     285  noitL(noit_error, "%s/%s <- [%s]\n", check->target, check->module, 
     286        check->stats.current.status); 
    261287  if(report_change) { 
    262     noitL(noit_debug, "%s/%s -> [%s/%s]\n", 
     288    noitL(noit_error, "%s/%s -> [%s/%s]\n", 
    263289          check->target, check->module, 
    264290          __noit_check_available_string(check->stats.current.available), 
  • src/noit_poller.h

    rf59d8ed re64e042  
    9494  noit_poller_lookup(uuid_t in); 
    9595 
     96API_EXPORT(noit_check_t) 
     97  noit_poller_lookup_by_name(char *target, char *name); 
     98 
    9699API_EXPORT(void) 
    97100  noit_poller_set_state(noit_check_t check, stats_t *newstate);