Changeset e01b3ad015472c9a83ced96738b07da543511a40

Show
Ignore:
Timestamp:
02/13/08 22:50:43 (6 years ago)
Author:
Theo Schlossnagle <jesus@omniti.com>
git-committer:
Theo Schlossnagle <jesus@omniti.com> 1202943043 +0000
git-parent:

[6e90b3f8072e3e74ee6b01f01b9b1be2e207738f]

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

check, check, 1, 2, 3

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • src/noit_check.c

    r6e90b3f re01b3ad  
    8585void 
    8686noit_poller_process_checks(const char *xpath) { 
    87   int i, cnt = 0; 
     87  int i, flags, cnt = 0; 
    8888  noit_conf_section_t *sec; 
    8989  __config_load_generation++; 
     
    9999    int no_oncheck = 0; 
    100100    int period = 0, timeout = 0; 
    101     noit_conf_boolean disabled = noit_false
     101    noit_conf_boolean disabled = noit_false, busted = noit_false
    102102    uuid_t uuid, out_uuid; 
    103103    noit_hash_table *options; 
     
    120120    if(!INHERIT(stringbuf, target, target, sizeof(target))) { 
    121121      noitL(noit_stderr, "check uuid: '%s' has no target\n", uuid_str); 
    122       disabled = noit_true; 
     122      busted = noit_true; 
    123123    } 
    124124    if(!INHERIT(stringbuf, module, module, sizeof(module))) { 
    125125      noitL(noit_stderr, "check uuid: '%s' has no module\n", uuid_str); 
    126       disabled = noit_true; 
     126      busted = noit_true; 
    127127    } 
    128128 
     
    139139      noitL(noit_stderr, "check uuid: '%s' has neither period nor oncheck\n", 
    140140            uuid_str); 
    141       disabled = noit_true; 
     141      busted = noit_true; 
    142142    } 
    143143    if(!(no_period || no_oncheck)) { 
    144144      noitL(noit_stderr, "check uuid: '%s' has oncheck and period.\n", 
    145145            uuid_str); 
    146       disabled = noit_true; 
     146      busted = noit_true; 
    147147    } 
    148148    if(!INHERIT(int, timeout, &timeout)) { 
    149149      noitL(noit_stderr, "check uuid: '%s' has no timeout\n", uuid_str); 
    150       disabled = noit_true; 
     150      busted = noit_true; 
    151151    } 
    152152    if(!no_period && timeout >= period) { 
     
    155155    } 
    156156    options = noit_conf_get_hash(sec[i], "ancestor-or-self::node()/config/*"); 
     157 
     158    flags = 0; 
     159    if(busted) flags |= NP_UNCONFIG; 
     160    if(disabled) flags |= NP_DISABLED; 
    157161 
    158162    if(noit_hash_retrieve(&polls, (char *)uuid, UUID_SIZE, 
     
    160164      noit_check_update(existing_check, target, name, options, 
    161165                           period, timeout, oncheck[0] ? oncheck : NULL, 
    162                            disabled); 
     166                           flags); 
    163167      noitL(noit_debug, "reloaded uuid: %s\n", uuid_str); 
    164168    } 
     
    166170      noit_poller_schedule(target, module, name, options, 
    167171                           period, timeout, oncheck[0] ? oncheck : NULL, 
    168                            disabled, uuid, out_uuid); 
     172                           flags, uuid, out_uuid); 
    169173      noitL(noit_debug, "loaded uuid: %s\n", uuid_str); 
    170174    } 
     
    274278                  u_int32_t timeout, 
    275279                  const char *oncheck, 
    276                   noit_conf_boolean disabled) { 
     280                  int flags) { 
    277281  int8_t family; 
    278282  int rv; 
     283  int mask = NP_DISABLED | NP_UNCONFIG; 
    279284  union { 
    280285    struct in_addr addr4; 
     
    291296      noitL(noit_stderr, "Cannot translate '%s' to IP\n", target); 
    292297      memset(&a, 0, sizeof(a)); 
    293       disabled = noit_true
     298      flags |= (NP_UNCONFIG & NP_DISABLED)
    294299    } 
    295300  } 
     
    319324  new_check->timeout = timeout; 
    320325 
    321   if(disabled) new_check->flags |= NP_DISABLED; 
     326  /* Unset what could be set.. then set what should be set */ 
     327  new_check->flags = (new_check->flags & ~mask) | flags; 
    322328 
    323329  /* This remove could fail -- no big deal */ 
     
    341347                     u_int32_t timeout, 
    342348                     const char *oncheck, 
    343                      noit_conf_boolean disabled
     349                     int flags
    344350                     uuid_t in, 
    345351                     uuid_t out) { 
     
    356362 
    357363  noit_check_update(new_check, target, name, config, 
    358                     period, timeout, oncheck, disabled); 
     364                    period, timeout, oncheck, flags); 
    359365  assert(noit_hash_store(&polls, 
    360366                         (char *)new_check->checkid, UUID_SIZE, 
  • src/noit_check.h

    r6e90b3f re01b3ad  
    3737#define NP_KILLED   0x00000002 
    3838#define NP_DISABLED 0x00000004 
     39#define NP_UNCONFIG 0x00000008 
    3940 
    4041#define NP_UNKNOWN 0               /* stats_t.{available,state} */ 
     
    9798#define NOIT_CHECK_LIVE(a) ((a)->fire_event != NULL) 
    9899#define NOIT_CHECK_DISABLED(a) ((a)->flags & NP_DISABLED) 
     100#define NOIT_CHECK_CONFIGURED(a) (((a)->flags & NP_UNCONFIG) == 0) 
    99101#define NOIT_CHECK_RUNNING(a) ((a)->flags & NP_RUNNING) 
    100102#define NOIT_CHECK_KILLED(a) ((a)->flags & NP_KILLED) 
     
    118120                       u_int32_t timeout, 
    119121                       const char *oncheck, 
    120                        noit_conf_boolean disabled
     122                       int flags
    121123                       uuid_t in, 
    122124                       uuid_t out); 
     
    130132                    u_int32_t timeout, 
    131133                    const char *oncheck, 
    132                     noit_conf_boolean disabled); 
     134                    int flags); 
    133135 
    134136API_EXPORT(int) 
  • src/noit_conf.c

    r6e90b3f re01b3ad  
    308308  return 0; 
    309309} 
    310  
    311 static int 
    312 noit_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"; 
     310static int 
     311noit_console_mkcheck_xpath(char *xpath, int len, 
     312                           noit_conf_t_userdata_t *info, 
     313                           const char *arg) { 
     314  uuid_t checkid; 
    317315  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)); 
     316 
     317  strlcpy(argcopy, arg, sizeof(argcopy)); 
    331318  if(uuid_parse(argcopy, checkid) == 0) { 
    332319    /* If they kill by uuid, we'll seek and destroy -- find it anywhere */ 
    333     snprintf(xpath, sizeof(xpath), "/noit/checks//check[@uuid=\"%s\"]", 
     320    snprintf(xpath, len, "/noit/checks//check[@uuid=\"%s\"]", 
    334321             argcopy); 
    335322  } 
     
    341328    check = noit_poller_lookup_by_name(target, name); 
    342329    if(!check) { 
    343       nc_printf(ncct, "could not find check %s`%s\n", target, name); 
    344330      return -1; 
    345331    } 
    346332    uuid_unparse_lower(check->checkid, uuid_str); 
    347     snprintf(xpath, sizeof(xpath), "/noit/checks//check[@uuid=\"%s\"]", 
     333    snprintf(xpath, len, "/noit/checks//check[@uuid=\"%s\"]", 
    348334             uuid_str); 
    349335  } 
    350336  else { 
    351     char *path = strcmp(info->path, "/") ? info->path : ""; 
    352     snprintf(xpath, sizeof(xpath), "/noit%s/%s[@uuid]", path, argv[0]); 
    353   } 
    354  
     337    char *path = (!info || !strcmp(info->path, "/")) ? "" : info->path; 
     338    snprintf(xpath, len, "/noit%s/%s[@uuid]", path, arg); 
     339  } 
     340  return 0; 
     341
     342static int 
     343noit_console_check(noit_console_closure_t ncct, 
     344                   int argc, char **argv, 
     345                   noit_console_state_t *state, void *closure) { 
     346  int i, cnt; 
     347  noit_conf_t_userdata_t *info; 
     348  char xpath[1024]; 
     349  xmlXPathObjectPtr pobj = NULL; 
     350 
     351  if(argc > 1) { 
     352    nc_printf(ncct, "requires zero or one arguments\n"); 
     353    return -1; 
     354  } 
     355 
     356  info = noit_console_userdata_get(ncct, NOIT_CONF_T_USERDATA); 
     357  /* We many not be in conf-t mode -- that's fine */ 
     358  if(noit_console_mkcheck_xpath(xpath, sizeof(xpath), info, 
     359                                argc ? argv[0] : ".")) { 
     360    nc_printf(ncct, "could not find check '%s'\n", argv[0]); 
     361    return -1; 
     362  } 
     363 
     364  pobj = xmlXPathEval((xmlChar *)xpath, xpath_ctxt); 
     365  if(!pobj || pobj->type != XPATH_NODESET || 
     366     xmlXPathNodeSetIsEmpty(pobj->nodesetval)) { 
     367    nc_printf(ncct, "no checks found\n"); 
     368    goto out; 
     369  } 
     370  cnt = xmlXPathNodeSetGetLength(pobj->nodesetval); 
     371  if(info && cnt != 1) { 
     372    nc_printf(ncct, "Ambiguous check specified\n"); 
     373    goto out; 
     374  } 
     375  for(i=0; i<cnt; i++) { 
     376    uuid_t checkid; 
     377    xmlNodePtr node; 
     378    char *uuid_conf; 
     379 
     380    node = (noit_conf_section_t)xmlXPathNodeSetItem(pobj->nodesetval, i); 
     381    if(info) { 
     382      if(info->path) free(info->path); 
     383      info->path = strdup((char *)xmlGetNodePath(node) + strlen("/noit")); 
     384    } 
     385    uuid_conf = (char *)xmlGetProp(node, (xmlChar *)"uuid"); 
     386    if(!uuid_conf || uuid_parse(uuid_conf, checkid)) { 
     387      nc_printf(ncct, "%s has invalid or missing UUID!\n", 
     388                (char *)xmlGetNodePath(node) + strlen("/noit")); 
     389      continue; 
     390    } 
     391    nc_printf(ncct, "==== %s ====\n", uuid_conf); 
     392  } 
     393 out: 
     394  if(pobj) xmlXPathFreeObject(pobj); 
     395  return 0; 
     396
     397static int 
     398noit_console_config_nocheck(noit_console_closure_t ncct, 
     399                            int argc, char **argv, 
     400                            noit_console_state_t *state, void *closure) { 
     401  int i, cnt; 
     402  const char *err = "internal error"; 
     403  noit_conf_t_userdata_t *info; 
     404  xmlXPathObjectPtr pobj = NULL; 
     405  char xpath[1024]; 
     406  uuid_t checkid; 
     407 
     408  if(argc != 1) { 
     409    nc_printf(ncct, "requires one argument\n"); 
     410    return -1; 
     411  } 
     412 
     413  info = noit_console_userdata_get(ncct, NOIT_CONF_T_USERDATA); 
     414  if(noit_console_mkcheck_xpath(xpath, sizeof(xpath), info, argv[0])) { 
     415    nc_printf(ncct, "could not find check '%s'\n", argv[0]); 
     416    return -1; 
     417  } 
    355418  pobj = xmlXPathEval((xmlChar *)xpath, xpath_ctxt); 
    356419  if(!pobj || pobj->type != XPATH_NODESET || 
     
    934997static 
    935998void register_console_config_commands() { 
     999  cmd_info_t *showcmd; 
    9361000  noit_console_state_t *tl, *_conf_state, *_conf_t_state, 
    9371001                       *_write_state, *_attr_state, 
     
    9641028  ADD_CMD(_conf_t_state, "ls", noit_console_config_show, NULL, NULL); 
    9651029  ADD_CMD(_conf_t_state, "cd", noit_console_config_cd, NULL, NULL); 
     1030  ADD_CMD(_conf_t_state, "check", noit_console_check, NULL, NULL); 
    9661031  ADD_CMD(_conf_t_state, "section", noit_console_config_section, NULL, (void *)0); 
     1032 
     1033  showcmd = noit_console_state_get_cmd(tl, "show"); 
     1034  ADD_CMD(showcmd->dstate, "check", noit_console_check, NULL, NULL); 
     1035 
    9671036  DELEGATE_CMD(_conf_t_state, "write", _write_state); 
    9681037  DELEGATE_CMD(_conf_t_state, "attribute", _attr_state); 
  • src/sample.conf

    r998fcf4 re01b3ad  
    3939  </listeners> 
    4040  <checks> 
     41    <check uuid="1b4e28ba-2fa1-11d2-883f-b9b761bde3fb" /> 
    4142    <dc1 timeout="30000" period="60000"> 
    4243      <icmp module="ping_icmp" timeout="12000">