Changeset 6e90b3f8072e3e74ee6b01f01b9b1be2e207738f

Show
Ignore:
Timestamp:
02/13/08 20:46:00 (10 years ago)
Author:
Theo Schlossnagle <jesus@omniti.com>
git-committer:
Theo Schlossnagle <jesus@omniti.com> 1202935560 +0000
git-parent:

[624c3f92779aef1df9d9b7eda05e93506a07e4cd]

git-author:
Theo Schlossnagle <jesus@omniti.com> 1202935560 +0000
Message:

support 'no check' on console to delete checks as well as 'reload' on console (currently only reloads checks)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • src/modules/http.c

    r87af809 r6e90b3f  
    339339  if(xpath_ctxt) xmlXPathFreeContext(xpath_ctxt); 
    340340} 
     341static void serf_check_info_cleanup(serf_check_info_t *ci) { 
     342  if(ci->connection) { 
     343    serf_connection_close(ci->connection); 
     344    ci->connection = NULL; 
     345  } 
     346  if(ci->fd_event) { 
     347    eventer_remove_fd(ci->fd_event->fd); 
     348    eventer_free(ci->fd_event); 
     349    ci->fd_event = NULL; 
     350  } 
     351  ci->timeout_event = NULL; 
     352  if(ci->pool) apr_pool_destroy(ci->pool); 
     353  memset(ci, 0, sizeof(*ci)); 
     354} 
    341355static int serf_complete(eventer_t e, int mask, 
    342356                         void *closure, struct timeval *now) { 
     
    345359 
    346360  noitLT(nldeb, now, "serf_complete(%s)\n", ccl->check->target); 
    347   generic_log_results(ccl->self, ccl->check); 
    348   if(ci->connection) { 
    349     serf_connection_close(ci->connection); 
    350     ci->connection = NULL; 
    351   } 
    352   if(ci->fd_event) { 
    353     eventer_remove_fd(ci->fd_event->fd); 
    354     eventer_free(ci->fd_event); 
    355     ci->fd_event = NULL; 
    356   } 
    357   ci->timeout_event = NULL; 
    358   apr_pool_destroy(ci->pool); 
    359   memset(ci, 0, sizeof(*ci)); 
     361  if(!NOIT_CHECK_DISABLED(ccl->check) && !NOIT_CHECK_KILLED(ccl->check)) { 
     362    generic_log_results(ccl->self, ccl->check); 
     363  } 
     364  serf_check_info_cleanup(ci); 
    360365  ccl->check->flags &= ~NP_RUNNING; 
    361366  free(ccl); 
     
    777782  return 0; 
    778783} 
     784static void serf_cleanup(noit_module_t *self, noit_check_t *check) { 
     785  serf_check_info_t *sci; 
     786  if(check->fire_event) { 
     787    eventer_remove(check->fire_event); 
     788    free(check->fire_event->closure); 
     789    eventer_free(check->fire_event); 
     790    check->fire_event = NULL; 
     791  } 
     792  sci = check->closure; 
     793  if(sci) { 
     794    serf_check_info_cleanup(sci); 
     795    free(sci); 
     796  } 
     797} 
    779798static int serf_initiate_check(noit_module_t *self, noit_check_t *check, 
    780799                               int once, noit_check_t *cause) { 
     
    808827} 
    809828 
     829static void resmon_cleanup(noit_module_t *self, noit_check_t *check) { 
     830  resmon_check_info_t *rci; 
     831  if(check->fire_event) { 
     832    eventer_remove(check->fire_event); 
     833    free(check->fire_event->closure); 
     834    eventer_free(check->fire_event); 
     835    check->fire_event = NULL; 
     836  } 
     837  rci = check->closure; 
     838  if(rci) { 
     839    if(rci->xpathexpr) free(rci->xpathexpr); 
     840    if(rci->resmod) free(rci->resmod); 
     841    if(rci->resserv) free(rci->resserv); 
     842    if(rci->xml_doc) xmlFreeDoc(rci->xml_doc); 
     843    serf_check_info_cleanup(&rci->serf); 
     844    free(rci); 
     845  } 
     846} 
    810847static int resmon_part_initiate_check(noit_module_t *self, noit_check_t *check, 
    811848                                      int once, noit_check_t *parent) { 
     
    813850  const char *resmod, *resserv; 
    814851  resmon_check_info_t *rci; 
     852 
     853  if(NOIT_CHECK_DISABLED(check) || NOIT_CHECK_KILLED(check)) return 0; 
    815854 
    816855  if(!check->closure) check->closure = calloc(1, sizeof(resmon_check_info_t)); 
     
    873912  serf_config, 
    874913  serf_init, 
    875   serf_initiate_check 
     914  serf_initiate_check, 
     915  serf_cleanup 
    876916}; 
    877917 
     
    884924  resmon_config, 
    885925  serf_init, 
    886   resmon_initiate_check 
     926  resmon_initiate_check, 
     927  resmon_cleanup 
    887928}; 
    888929 
     
    895936  resmon_config, 
    896937  serf_init, 
    897   resmon_part_initiate_check 
     938  resmon_part_initiate_check, 
     939  resmon_cleanup 
    898940}; 
    899941 
  • src/modules/ping_icmp.c

    r1d69a01 r6e90b3f  
    124124  struct ping_closure *pcl = (struct ping_closure *)closure; 
    125125  struct check_info *data; 
    126   ping_icmp_log_results(pcl->self, pcl->check); 
    127   data = (struct check_info *)pcl->check->closure; 
    128   data->timeout_event = NULL; 
     126  if(!NOIT_CHECK_KILLED(pcl->check) && !NOIT_CHECK_DISABLED(pcl->check)) { 
     127    ping_icmp_log_results(pcl->self, pcl->check); 
     128    data = (struct check_info *)pcl->check->closure; 
     129    data->timeout_event = NULL; 
     130  } 
    129131  pcl->check->flags &= ~NP_RUNNING; 
    130132  free(pcl); 
     
    324326  return 0; 
    325327} 
     328static void ping_check_cleanup(noit_module_t *self, noit_check_t *check) { 
     329  struct check_info *ci = (struct check_info *)check->closure; 
     330  if(check->fire_event) { 
     331    eventer_remove(check->fire_event); 
     332    free(check->fire_event->closure); 
     333    eventer_free(check->fire_event); 
     334    check->fire_event = NULL; 
     335  } 
     336  if(ci) { 
     337    if(ci->timeout_event) { 
     338      eventer_remove(ci->timeout_event); 
     339      free(ci->timeout_event->closure); 
     340      eventer_free(ci->timeout_event); 
     341      ci->timeout_event = NULL; 
     342    } 
     343    if(ci->turnaround) free(ci->turnaround); 
     344    free(ci); 
     345  } 
     346} 
    326347static int ping_icmp_send(noit_module_t *self, noit_check_t *check) { 
    327348  struct timeval when, p_int; 
     
    426447 
    427448  if(check->period == 0) return 0; 
     449  if(NOIT_CHECK_DISABLED(check) || NOIT_CHECK_KILLED(check)) return 0; 
    428450 
    429451  /* If we have an event, we know when we intended it to fire.  This means 
     
    456478                                   struct timeval *now) { 
    457479  struct ping_closure *cl = (struct ping_closure *)closure; 
     480  cl->check->fire_event = NULL; 
    458481  ping_icmp_schedule_next(cl->self, &e->whence, cl->check, now); 
    459482  ping_icmp_send(cl->self, cl->check); 
     
    535558  ping_icmp_config, 
    536559  ping_icmp_init, 
    537   ping_icmp_initiate_check 
     560  ping_icmp_initiate_check, 
     561  ping_check_cleanup 
    538562}; 
    539563 
  • src/noit_check.c

    r7a1324a r6e90b3f  
    8484} 
    8585void 
    86 noit_poller_process_checks(char *xpath) { 
     86noit_poller_process_checks(const char *xpath) { 
    8787  int i, cnt = 0; 
    8888  noit_conf_section_t *sec; 
     
    173173 
    174174void 
    175 noit_poller_load_checks() { 
    176   noit_poller_process_checks("/noit/checks//check"); 
    177 } 
    178  
    179 void 
    180175noit_poller_initiate() { 
    181176  noit_hash_iter iter = NOIT_HASH_ITER_ZERO; 
     
    209204  int klen; 
    210205  noit_check_t *check, *parent; 
     206 
     207  /* Cleanup any previous causal map */ 
     208  while(noit_hash_next(&polls, &iter, (const char **)key_id, &klen, 
     209                       (void **)&check)) { 
     210    dep_list_t *dep; 
     211    while((dep = check->causal_checks) != NULL) { 
     212      check->causal_checks = dep->next; 
     213      free(dep); 
     214    } 
     215  } 
     216 
     217  /* Walk all checks and add check dependencies to their parents */ 
    211218  while(noit_hash_next(&polls, &iter, (const char **)key_id, &klen, 
    212219                       (void **)&check)) { 
     
    244251} 
    245252void 
     253noit_poller_reload(const char *xpath) 
     254{ 
     255  noit_poller_process_checks(xpath ? xpath : "/noit/checks//check"); 
     256  noit_poller_make_causal_map(); 
     257  noit_poller_initiate(); 
     258} 
     259void 
    246260noit_poller_init() { 
    247261  noit_skiplist_init(&polls_by_name); 
    248262  noit_skiplist_set_compare(&polls_by_name, __check_name_compare, 
    249263                            __check_name_compare); 
    250   noit_poller_load_checks(); 
    251   noit_poller_make_causal_map(); 
    252264  register_console_check_commands(); 
    253   noit_poller_initiate(); 
     265  noit_poller_reload(NULL); 
    254266} 
    255267 
     
    356368noit_poller_deschedule(uuid_t in) { 
    357369  noit_check_t *checker; 
     370  noit_module_t *mod; 
    358371  if(noit_hash_retrieve(&polls, 
    359372                        (char *)in, UUID_SIZE, 
     
    366379  } 
    367380  checker->flags |= NP_KILLED; 
     381 
     382  noit_skiplist_remove(&polls_by_name, checker, NULL); 
     383  noit_hash_delete(&polls, (char *)in, UUID_SIZE, NULL, NULL); 
     384 
     385  mod = noit_module_lookup(checker->module); 
     386  mod->cleanup(mod, checker); 
    368387  if(checker->fire_event) { 
    369388     eventer_remove(checker->fire_event); 
     
    371390     checker->fire_event = NULL; 
    372391  } 
    373   noit_hash_delete(&polls, (char *)in, UUID_SIZE, free, free); 
    374392 
    375393  if(checker->target) free(checker->target); 
  • src/noit_check.h

    r7a1324a r6e90b3f  
    9696 
    9797#define NOIT_CHECK_LIVE(a) ((a)->fire_event != NULL) 
     98#define NOIT_CHECK_DISABLED(a) ((a)->flags & NP_DISABLED) 
     99#define NOIT_CHECK_RUNNING(a) ((a)->flags & NP_RUNNING) 
     100#define NOIT_CHECK_KILLED(a) ((a)->flags & NP_KILLED) 
    98101 
    99102API_EXPORT(void) noit_poller_init(); 
    100 API_EXPORT(void) noit_poller_load_checks(); 
    101 API_EXPORT(void) noit_poller_process_checks(char *xpath); 
     103API_EXPORT(void) noit_poller_reload(const char *xpath); /* NULL for all */ 
     104API_EXPORT(void) noit_poller_process_checks(const char *xpath); 
     105API_EXPORT(void) noit_poller_make_causal_map(); 
    102106 
    103107API_EXPORT(void) 
  • src/noit_conf.c

    rf4eb133 r6e90b3f  
    309309} 
    310310 
     311static int 
     312noit_console_config_nocheck(noit_console_closure_t ncct, 
     313                            int argc, char **argv, 
     314                            noit_console_state_t *state, void *closure) { 
     315  int i, cnt; 
     316  const char *err = "internal error"; 
     317  char argcopy[1024], *target, *name; 
     318  noit_conf_t_userdata_t *info; 
     319  xmlXPathObjectPtr pobj = NULL; 
     320  char xpath[1024]; 
     321 
     322  uuid_t checkid; 
     323  if(argc != 1) { 
     324    nc_printf(ncct, "requires one argument\n"); 
     325    return -1; 
     326  } 
     327 
     328  info = noit_console_userdata_get(ncct, NOIT_CONF_T_USERDATA); 
     329 
     330  strlcpy(argcopy, argv[0], sizeof(argcopy)); 
     331  if(uuid_parse(argcopy, checkid) == 0) { 
     332    /* If they kill by uuid, we'll seek and destroy -- find it anywhere */ 
     333    snprintf(xpath, sizeof(xpath), "/noit/checks//check[@uuid=\"%s\"]", 
     334             argcopy); 
     335  } 
     336  else if((name = strchr(argcopy, '`')) != NULL) { 
     337    noit_check_t *check; 
     338    char uuid_str[37]; 
     339    target = argcopy; 
     340    *name++ = '\0'; 
     341    check = noit_poller_lookup_by_name(target, name); 
     342    if(!check) { 
     343      nc_printf(ncct, "could not find check %s`%s\n", target, name); 
     344      return -1; 
     345    } 
     346    uuid_unparse_lower(check->checkid, uuid_str); 
     347    snprintf(xpath, sizeof(xpath), "/noit/checks//check[@uuid=\"%s\"]", 
     348             uuid_str); 
     349  } 
     350  else { 
     351    char *path = strcmp(info->path, "/") ? info->path : ""; 
     352    snprintf(xpath, sizeof(xpath), "/noit%s/%s[@uuid]", path, argv[0]); 
     353  } 
     354 
     355  pobj = xmlXPathEval((xmlChar *)xpath, xpath_ctxt); 
     356  if(!pobj || pobj->type != XPATH_NODESET || 
     357     xmlXPathNodeSetIsEmpty(pobj->nodesetval)) { 
     358    err = "no checks found"; 
     359    goto bad; 
     360  } 
     361  cnt = xmlXPathNodeSetGetLength(pobj->nodesetval); 
     362  for(i=0; i<cnt; i++) { 
     363    xmlNodePtr node; 
     364    char *uuid_conf; 
     365    node = (noit_conf_section_t)xmlXPathNodeSetItem(pobj->nodesetval, i); 
     366    uuid_conf = (char *)xmlGetProp(node, (xmlChar *)"uuid"); 
     367    if(!uuid_conf || uuid_parse(uuid_conf, checkid)) { 
     368      nc_printf(ncct, "%s has invalid or missing UUID!\n", 
     369                (char *)xmlGetNodePath(node) + strlen("/noit")); 
     370    } 
     371    else { 
     372      nc_printf(ncct, "descheduling %s\n", uuid_conf); 
     373      noit_poller_deschedule(checkid); 
     374      xmlUnlinkNode(node); 
     375    } 
     376  } 
     377  nc_printf(ncct, "rebuilding causal map...\n"); 
     378  noit_poller_make_causal_map(); 
     379  if(pobj) xmlXPathFreeObject(pobj); 
     380  return 0; 
     381 bad: 
     382  if(pobj) xmlXPathFreeObject(pobj); 
     383  nc_printf(ncct, "%s\n", err); 
     384  return -1; 
     385} 
    311386static int 
    312387noit_console_config_section(noit_console_closure_t ncct, 
     
    604679  return info->prompt; 
    605680} 
    606  
     681static int 
     682noit_conf_reload(noit_console_closure_t ncct, 
     683                 int argc, char **argv, 
     684                 noit_console_state_t *state, void *closure) { 
     685  if(noit_conf_load(master_config_file)) { 
     686    nc_printf(ncct, "error loading config\n"); 
     687    return -1; 
     688  } 
     689  noit_poller_reload(NULL); 
     690  return 0; 
     691
    607692static int 
    608693noit_console_write_xml(void *vncct, const char *buffer, int len) { 
     
    767852  if(!strcmp(path, "/")) path = ""; 
    768853 
     854  /* The first one is just a process_checks, the second is the reload. 
     855   * Reload does a lot of work and there is no need to do it twice. 
     856   */ 
    769857  snprintf(xpath, sizeof(xpath), "/noit/%s[@uuid]", path); 
    770858  noit_poller_process_checks(xpath); 
    771859  snprintf(xpath, sizeof(xpath), "/noit/%s//check[@uuid]", path); 
    772   noit_poller_process_checks(xpath); 
     860  noit_poller_reload(xpath); 
    773861} 
    774862int 
     
    869957  DELEGATE_CMD(_unset_state, "attribute", _uattr_state); 
    870958  ADD_CMD(_unset_state, "section", noit_console_config_section, NULL, (void *)1); 
     959  ADD_CMD(_unset_state, "check", noit_console_config_nocheck, NULL, NULL); 
    871960  
    872961  NEW_STATE(_conf_t_state);  
     
    885974  ADD_CMD(tl, "configure", noit_console_state_delegate, _conf_state, NULL); 
    886975  ADD_CMD(tl, "write", noit_console_state_delegate, _write_state, NULL); 
    887 
     976  ADD_CMD(tl, "reload", noit_conf_reload, NULL, NULL); 
     977
  • src/noit_module.h

    r57a3273 r6e90b3f  
    2424  int (*initiate_check)(struct _noit_module *, noit_check_t *check, 
    2525                        int once, noit_check_t *cause); 
     26  void (*cleanup)(struct _noit_module *, noit_check_t *); 
    2627  void *opaque_handle; 
    2728} noit_module_t;