Changeset 4dccf830640c308658d62f7896f78488734381bc

Show
Ignore:
Timestamp:
02/24/08 16:05:26 (6 years ago)
Author:
Theo Schlossnagle <jesus@omniti.com>
git-committer:
Theo Schlossnagle <jesus@omniti.com> 1203869126 +0000
git-parent:

[c04dcf560cc5f0df021d665247f1b6d34352c166]

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

xpointer-esque inheritence... actually quite neat

Files:

Legend:

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

    rf1a1f36 r4dccf83  
    158158      timeout = period/2; 
    159159    } 
    160     options = noit_conf_get_hash(sec[i], "ancestor-or-self::node()/config/*"); 
     160    options = noit_conf_get_hash(sec[i], "config"); 
    161161 
    162162    INHERIT(boolean, disable, &disabled); 
  • src/noit_conf.c

    ra136e61 r4dccf83  
    7676} 
    7777 
    78 noit_hash_table *noit_conf_get_hash(noit_conf_section_t section, 
    79                                     const char *path) { 
     78void noit_conf_get_elements_into_hash(noit_conf_section_t section, 
     79                                      const char *path, 
     80                                      noit_hash_table *table) { 
    8081  int i, cnt; 
    81   noit_hash_table *table = NULL; 
    8282  xmlXPathObjectPtr pobj = NULL; 
    8383  xmlXPathContextPtr current_ctxt; 
     
    9494  if(pobj->type != XPATH_NODESET) goto out; 
    9595  if(xmlXPathNodeSetIsEmpty(pobj->nodesetval)) goto out; 
    96   table = calloc(1, sizeof(*table)); 
    9796  cnt = xmlXPathNodeSetGetLength(pobj->nodesetval); 
    9897  for(i=0; i<cnt; i++) { 
     
    108107  if(current_ctxt && current_ctxt != xpath_ctxt) 
    109108    xmlXPathFreeContext(current_ctxt); 
     109} 
     110void noit_conf_get_into_hash(noit_conf_section_t section, 
     111                             const char *path, 
     112                             noit_hash_table *table) { 
     113  int cnt; 
     114  xmlXPathObjectPtr pobj = NULL; 
     115  xmlXPathContextPtr current_ctxt; 
     116  xmlNodePtr current_node = (xmlNodePtr)section; 
     117  xmlNodePtr node, parent_node; 
     118  char xpath_expr[1024]; 
     119  char *inheritid; 
     120 
     121  current_ctxt = xpath_ctxt; 
     122  if(current_node) { 
     123    current_ctxt = xmlXPathNewContext(master_config); 
     124    current_ctxt->node = current_node; 
     125  } 
     126  if(path[0] == '/') 
     127    strlcpy(xpath_expr, path, sizeof(xpath_expr)); 
     128  else 
     129    snprintf(xpath_expr, sizeof(xpath_expr), 
     130             "ancestor-or-self::node()/%s", path); 
     131  pobj = xmlXPathEval((xmlChar *)xpath_expr, current_ctxt); 
     132  if(!pobj) goto out; 
     133  if(pobj->type != XPATH_NODESET) goto out; 
     134  if(xmlXPathNodeSetIsEmpty(pobj->nodesetval)) goto out; 
     135  cnt = xmlXPathNodeSetGetLength(pobj->nodesetval); 
     136  /* These are in the order of root to leaf 
     137   * We want to recurse... apply: 
     138   *   1. our parent's config 
     139   *   2. our "inherit" config if it exists. 
     140   *   3. our config. 
     141   */ 
     142  node = xmlXPathNodeSetItem(pobj->nodesetval, cnt-1); 
     143  /* 1. */ 
     144  if(cnt > 1) { 
     145    parent_node = xmlXPathNodeSetItem(pobj->nodesetval, cnt-2); 
     146    noit_conf_get_into_hash(parent_node, (const char *)node->name, table); 
     147  } 
     148  /* 2. */ 
     149  inheritid = (char *)xmlGetProp(node, (xmlChar *)"inherit"); 
     150  if(inheritid) { 
     151    snprintf(xpath_expr, sizeof(xpath_expr), "//*[@id=\"%s\"]", inheritid); 
     152    noit_conf_get_into_hash(NULL, xpath_expr, table); 
     153  } 
     154  /* 3. */ 
     155  noit_conf_get_elements_into_hash(node, "*", table); 
     156 
     157 out: 
     158  if(pobj) xmlXPathFreeObject(pobj); 
     159  if(current_ctxt && current_ctxt != xpath_ctxt) 
     160    xmlXPathFreeContext(current_ctxt); 
     161} 
     162noit_hash_table *noit_conf_get_hash(noit_conf_section_t section, 
     163                                    const char *path) { 
     164  noit_hash_table *table = NULL; 
     165 
     166  table = calloc(1, sizeof(*table)); 
     167  noit_conf_get_into_hash(section, path, table); 
    110168  return table; 
    111169} 
     
    12961354    } 
    12971355 
    1298     noitL(noit_debug, "[%d] configuring log %s[%s:%s]\n", i, name, type, path); 
    1299  
    13001356    if(noit_conf_get_boolean(log_configs[i], 
    13011357                             "ancestor-or-self::node()/@disabled", 
  • src/noit_listener.c

    ra136e61 r4dccf83  
    294294      backlog = 5; 
    295295 
    296     sslconfig = noit_conf_get_hash(listener_configs[i], "sslconfig/*"); 
    297     config = noit_conf_get_hash(listener_configs[i], "config/*"); 
     296    sslconfig = noit_conf_get_hash(listener_configs[i], "sslconfig"); 
     297    config = noit_conf_get_hash(listener_configs[i], "config"); 
    298298 
    299299    noit_listener(address, port, SOCK_STREAM, backlog, 
  • src/noit_module.c

    r8a88818 r4dccf83  
    104104      continue; 
    105105    } 
    106     config = noit_conf_get_hash(sections[i], "ancestor-or-self::node()/config/*"); 
     106    config = noit_conf_get_hash(sections[i], "config"); 
    107107    module = noit_module_lookup(module_name); 
    108108    if(module->config && module->config(module, config)) { 
  • src/noitd.c

    ra136e61 r4dccf83  
    3939  int rv = 0; 
    4040  noit_hash_table *table; 
    41   table = noit_conf_get_hash(NULL, "/noit/eventer/config/*"); 
     41  table = noit_conf_get_hash(NULL, "/noit/eventer/config"); 
    4242  if(table) { 
    4343    noit_hash_iter iter = NOIT_HASH_ITER_ZERO; 
  • src/sample.conf

    rc04dcf5 r4dccf83  
    8282      </resmon> 
    8383      <switches module="snmp" period="30000"> 
    84         <config> 
     84        <config inherit="SwitchPort" /> 
     85        <switch target="10.80.116.3"> 
     86          <check uuid="1b4e28ba-2fa1-11d2-883f-e9b761bde3fb" name="1" /> 
     87          <check uuid="1b4e28ba-3fa1-11d2-883f-e9b761bde3fb" name="2" /> 
     88          <check uuid="1b4e29ba-3fa1-11d2-883f-e9b761bde3fb" name="3" /> 
     89        </switch> 
     90      </switches> 
     91    </dc1> 
     92  </checks> 
     93  <config_templates> 
     94    <config id="SwitchPort"> 
    8595          <oid_description>IF-MIB::ifDescr.%[name]</oid_description> 
    8696          <oid_alias>IF-MIB::ifAlias.%[name]</oid_alias> 
     
    98108          <oid_innucastpkts>IF-MIB::ifInNUcastPkts.%[name]</oid_innucastpkts> 
    99109          <oid_outnucastpkts>IF-MIB::ifOutNUcastPkts.%[name]</oid_outnucastpkts> 
    100         </config> 
    101         <switch target="10.80.116.3"> 
    102           <check uuid="1b4e28ba-2fa1-11d2-883f-e9b761bde3fb" name="1" /> 
    103           <check uuid="1b4e28ba-3fa1-11d2-883f-e9b761bde3fb" name="2" /> 
    104           <check uuid="1b4e29ba-3fa1-11d2-883f-e9b761bde3fb" name="3" /> 
    105         </switch> 
    106       </switches> 
    107     </dc1> 
    108   </checks> 
     110    </config> 
     111  </config_templates> 
    109112</noit>