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_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);