Changeset b4b4512db2476f47ce8397f57987a0597fb911c3

Show
Ignore:
Timestamp:
05/15/08 21:57:18 (11 years ago)
Author:
Theo Schlossnagle <jesus@omniti.com>
git-committer:
Theo Schlossnagle <jesus@omniti.com> 1210888638 +0000
git-parent:

[1f7cb6fc7d8ef26f3708152ed497a3d3dfaeb168]

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

progress (perhaps complete) work on check enhancements, refs #18

Files:

Legend:

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

    r2ccf5eb rb4b4512  
    152152} 
    153153static int 
     154noit_config_check_update_attrs(xmlNodePtr node, int argc, char **argv) { 
     155  int i, error = 0; 
     156  if(argc % 2) return -1; 
     157 
     158  for(i=0; i<argc; i+=2) { 
     159    struct _valid_attr_t *attrinfo; 
     160    char *attr = argv[i], *val = NULL; 
     161    if(!strcasecmp(argv[i], "no")) attr = argv[i+1]; 
     162    else val = argv[i+1]; 
     163    if(!noit_hash_retrieve(&check_attrs, attr, strlen(attr), 
     164                           (void **)&attrinfo)) { 
     165      error = 1; 
     166      break; 
     167    } 
     168    /* The fixation stuff doesn't matter here, this check is brand-new */ 
     169    xmlUnsetProp(node, (xmlChar *)attrinfo->name); 
     170    if(val) 
     171      xmlSetProp(node, (xmlChar *)attrinfo->name, (xmlChar *)val); 
     172  } 
     173  return error; 
     174} 
     175 
     176static int 
    154177noit_conf_mkcheck_under(const char *ppath, int argc, char **argv, uuid_t out) { 
    155   int i, error = 0, rv = -1; 
     178  int rv = -1; 
    156179  const char *path; 
    157180  char xpath[1024]; 
     
    180203 
    181204    /* No risk of running off the end (we checked this above) */ 
    182     for(i=0; i<argc; i+=2) { 
    183       struct _valid_attr_t *attrinfo; 
    184       char *attr = argv[i], *val = NULL; 
    185       if(!strcasecmp(argv[i], "no")) attr = argv[i+1]; 
    186       else val = argv[i+1]; 
    187       if(!noit_hash_retrieve(&check_attrs, attr, strlen(attr), 
    188                              (void **)&attrinfo)) { 
    189         error = 1; 
    190         break; 
    191       } 
    192       /* The fixation stuff doesn't matter here, this check is brand-new */ 
    193       xmlUnsetProp(newnode, (xmlChar *)attrinfo->name); 
    194       if(val) 
    195         xmlSetProp(newnode, (xmlChar *)attrinfo->name, (xmlChar *)val); 
    196     } 
    197     if(error) { 
     205    if(noit_config_check_update_attrs(newnode, argc, argv)) { 
    198206      /* Something went wrong, remove the node */ 
    199207      xmlUnlinkNode(newnode); 
     
    231239    return -1; 
    232240  } 
     241  if(argc % 2 == 0) { 
     242    nc_printf(ncct, "wrong number of arguments\n"); 
     243    return -1; 
     244  }  
    233245 
    234246  info = noit_console_userdata_get(ncct, NOIT_CONF_T_USERDATA); 
    235   wanted = argc == 1 ? argv[0] : NULL; 
    236   if(!wanted) { 
     247  wanted = strcmp(argv[0], "new") ? argv[0] : NULL; 
     248  if(info && !wanted) { 
    237249    /* We are creating a new node */ 
    238250    uuid_t out; 
    239251    creating_new = noit_true; 
    240     if(noit_conf_mkcheck_under(info->path, argc, argv, out)) { 
     252    if(noit_conf_mkcheck_under(info->path, argc - 1, argv + 1, out)) { 
    241253      nc_printf(ncct, "Error creating new check\n"); 
    242254      return -1; 
     
    270282    goto out; 
    271283  } 
     284  if(argc > 1 && !creating_new) 
     285    if(noit_config_check_update_attrs(node, argc - 1, argv + 1)) 
     286      nc_printf(ncct, "Partially successful, error setting some attributes\n"); 
     287 
    272288  if(info) { 
    273289    if(info->path) free(info->path); 
    274290    info->path = strdup((char *)xmlGetNodePath(node) + strlen("/noit")); 
    275291    uuid_copy(info->current_check, checkid); 
    276     if(creating_new) refresh_subchecks(ncct, info); 
     292    if(argc > 1) refresh_subchecks(ncct, info); 
    277293    if(state) { 
    278294      noit_console_state_push_state(ncct, state); 
     
    404420 
    405421  noit_conf_xml_xpath(NULL, &xpath_ctxt); 
    406   if(argc != 1) { 
     422  if(argc < 1) { 
    407423    nc_printf(ncct, "requires one argument\n"); 
    408424    return -1; 
     
    431447    } 
    432448    else { 
    433       nc_printf(ncct, "descheduling %s\n", uuid_conf); 
    434       noit_poller_deschedule(checkid); 
    435       xmlUnlinkNode(node); 
    436     } 
     449      if(argc > 1) { 
     450        int j; 
     451        for(j=1;j<argc;j++) 
     452          xmlUnsetProp(node, (xmlChar *)argv[j]); 
     453      } else { 
     454        nc_printf(ncct, "descheduling %s\n", uuid_conf); 
     455        noit_poller_deschedule(checkid); 
     456        xmlUnlinkNode(node); 
     457      } 
     458    } 
     459  } 
     460  if(argc > 1) { 
     461    noit_poller_process_checks(xpath); 
     462    noit_poller_reload(xpath); 
    437463  } 
    438464  nc_printf(ncct, "rebuilding causal map...\n");