Changeset 67a2095e250dc562985ebc225064b0ef2a68ba2f

Show
Ignore:
Timestamp:
02/11/08 20:32:47 (6 years ago)
Author:
Theo Schlossnagle <jesus@omniti.com>
git-committer:
Theo Schlossnagle <jesus@omniti.com> 1202761967 +0000
git-parent:

[341415bb3a391e0f7d77ab9be37c158397b5c0aa]

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

convert elements to attributes... it seems more appropriate

Files:

Legend:

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

    rb0614c3 r67a2095  
    9494    char module[256]; 
    9595    char name[256]; 
    96     char oncheck[1024]
     96    char oncheck[1024] = ""
    9797    int no_period = 0; 
    9898    int no_oncheck = 0; 
     
    101101    noit_hash_table *options; 
    102102 
    103     if(!noit_conf_get_stringbuf(sec[i], "@uuid", 
    104                                 uuid_str, sizeof(uuid_str))) { 
     103#define NEXT(...) noitL(noit_stderr, __VA_ARGS__); continue 
     104#define MYATTR(type,a,...) noit_conf_get_##type(sec[i], "@" #a, __VA_ARGS__) 
     105#define INHERIT(type,a,...) \ 
     106  noit_conf_get_##type(sec[i], "ancestor-or-self::node()/@" #a, __VA_ARGS__) 
     107 
     108    if(!MYATTR(stringbuf, uuid, uuid_str, sizeof(uuid_str))) { 
    105109      noitL(noit_stderr, "check %d has no uuid\n", i+1); 
    106110      continue; 
    107111    } 
     112 
    108113    if(uuid_parse(uuid_str, uuid)) { 
    109114      noitL(noit_stderr, "check uuid: '%s' is invalid\n", uuid_str); 
    110115      continue; 
    111116    } 
    112     if(!noit_conf_get_stringbuf(sec[i], "ancestor-or-self::node()/target", target, sizeof(target))) { 
    113       noitL(noit_stderr, "check uuid: '%s' has no target\n", 
    114             uuid_str); 
    115       continue; 
    116     } 
    117     if(!noit_conf_get_stringbuf(sec[i], "ancestor-or-self::node()/module", module, sizeof(module))) { 
    118       noitL(noit_stderr, "check uuid: '%s' has no module\n", 
    119             uuid_str)
    120       continue; 
    121     } 
    122     if(!noit_conf_get_stringbuf(sec[i], "name", name, sizeof(name))) { 
     117 
     118    if(!INHERIT(stringbuf, target, target, sizeof(target))) { 
     119      noitL(noit_stderr, "check uuid: '%s' has no target\n", uuid_str); 
     120      continue; 
     121    } 
     122    if(!INHERIT(stringbuf, module, module, sizeof(module))) { 
     123      noitL(noit_stderr, "check uuid: '%s' has no module\n", uuid_str); 
     124      continue
     125    } 
     126 
     127    if(!MYATTR(stringbuf, name, name, sizeof(name))) 
    123128      strlcpy(name, module, sizeof(name)); 
    124     } 
    125     if(!noit_conf_get_int(sec[i], "ancestor-or-self::node()/period", &period)) { 
     129 
     130    if(!INHERIT(int, period, &period) || period == 0) 
    126131      no_period = 1; 
    127     } 
    128     if(!noit_conf_get_stringbuf(sec[i], "ancestor-or-self::node()/oncheck", oncheck, sizeof(oncheck))) { 
    129       oncheck[0] = '\0'; 
     132 
     133    if(!INHERIT(stringbuf, oncheck, oncheck, sizeof(oncheck)) || !oncheck[0]) 
    130134      no_oncheck = 1; 
    131     } 
     135 
    132136    if(no_period && no_oncheck) { 
    133137      noitL(noit_stderr, "check uuid: '%s' has neither period nor oncheck\n", 
     
    136140    } 
    137141    if(!(no_period || no_oncheck)) { 
    138       noitL(noit_stderr, "check uuid: '%s' has has on check and period.\n", 
     142      noitL(noit_stderr, "check uuid: '%s' has oncheck and period.\n", 
    139143            uuid_str); 
    140144      continue; 
    141145    } 
    142     if(!noit_conf_get_int(sec[i], "ancestor-or-self::node()/timeout", &timeout)) { 
     146    if(!INHERIT(int, timeout, &timeout)) { 
    143147      noitL(noit_stderr, "check uuid: '%s' has no timeout\n", uuid_str); 
    144148      continue; 
     
    211215        dep->next = parent->causal_checks; 
    212216        parent->causal_checks = dep; 
     217        noitL(noit_debug, "Causal map %s`%s --> %s`%s\n", 
     218              parent->target, parent->name, check->target, check->name); 
    213219      } 
    214220    } 
  • src/noit_conf.c

    r341415b r67a2095  
    362362                         noit_console_state_t *state, void *closure) { 
    363363  int i, cnt, titled = 0, cliplen = 0; 
    364   const char *path
     364  const char *path, *basepath = NULL
    365365  char xpath[1024]; 
    366   noit_conf_t_userdata_t *info
     366  noit_conf_t_userdata_t *info = NULL
    367367  xmlXPathObjectPtr pobj = NULL; 
    368368  xmlXPathContextPtr current_ctxt; 
     
    373373    return -1; 
    374374  } 
    375   if(argc == 1) { 
    376     path = argv[0]; 
    377   } 
    378   else { 
    379     info = noit_console_userdata_get(ncct, NOIT_CONF_T_USERDATA); 
    380     if(!info) { 
    381       nc_printf(ncct, "argument required when not in configuration mode\n"); 
    382       return -1; 
    383     } 
    384     path = info->path; 
    385   } 
     375 
     376  info = noit_console_userdata_get(ncct, NOIT_CONF_T_USERDATA); 
     377  if(info) path = basepath = info->path; 
     378  if(!info && argc == 0) { 
     379    nc_printf(ncct, "argument required when not in configuration mode\n"); 
     380    return -1; 
     381  } 
     382 
     383  if(argc == 1) path = argv[0]; 
     384  if(!basepath) basepath = path; 
     385 
     386  /* { / } is a special case */ 
     387  if(!strcmp(basepath, "/")) basepath = ""; 
     388  if(!strcmp(path, "/")) path = ""; 
     389 
    386390  if(!master_config) { 
    387391    nc_printf(ncct, "no config\n"); 
     
    393397   * Ever notice how it is hard to describe xpath in C comments? 
    394398   */ 
     399  /* We don't want to show the root node */ 
    395400  cliplen = strlen("/noit/"); 
    396   if(!strcmp(path, "/")) 
    397     snprintf(xpath, sizeof(xpath), "/noit/*"); 
    398   else { 
    399     if(argc == 0) cliplen = strlen("/noit/") + strlen(path); 
    400     snprintf(xpath, sizeof(xpath), "/noit%s/*", path); 
    401   } 
     401 
     402  /* If we are in configuration mode 
     403   * and we are without an argument or the argument is absolute, 
     404   * clip the current path off */ 
     405  if(info && (argc == 0 || path[0] != '/')) cliplen += strlen(basepath); 
     406  if(!path[0] || path[0] == '/') /* base only, or absolute path requested */ 
     407    snprintf(xpath, sizeof(xpath), "/noit%s/@*", path); 
     408  else 
     409    snprintf(xpath, sizeof(xpath), "/noit%s/%s/@*", basepath, path); 
    402410 
    403411  current_ctxt = xpath_ctxt; 
     
    407415    goto bad; 
    408416  } 
    409   if(xmlXPathNodeSetIsEmpty(pobj->nodesetval)) { 
    410     nc_printf(ncct, "empty\n"); 
    411   } 
    412417  cnt = xmlXPathNodeSetGetLength(pobj->nodesetval); 
    413  
    414418  titled = 0; 
    415419  for(i=0; i<cnt; i++) { 
     
    423427    } 
    424428  } 
    425  
     429  xmlXPathFreeObject(pobj); 
     430 
     431  /* _shorten string_ turning last { / @ * } to { / * } */ 
     432  strlcpy(xpath + strlen(xpath) - 2, "*", 2); 
     433nc_printf(ncct, "Looking up path '%s'\n", xpath); 
     434  pobj = xmlXPathEval((xmlChar *)xpath, current_ctxt); 
     435  if(!pobj || pobj->type != XPATH_NODESET) { 
     436    nc_printf(ncct, "no such object\n"); 
     437    goto bad; 
     438  } 
     439  cnt = xmlXPathNodeSetGetLength(pobj->nodesetval); 
    426440  titled = 0; 
    427441  for(i=0; i<cnt; i++) { 
  • src/noit_console.c

    r1fe89bb r67a2095  
    237237  else if(i<0) nc_printf(ncct, "Error at offset: %d\n", 0-i); 
    238238  else noit_console_state_do(ncct, cnt, cmds); 
    239   for(i=0;i<cnt;i++) { 
    240     nc_printf(ncct, "[%d] '%s'\n", i, cmds[i]); 
    241     free(cmds[i]); 
    242   } 
    243239} 
    244240 
  • src/sample.conf

    rd936b80 r67a2095  
    3939  </listeners> 
    4040  <checks> 
    41     <checkgroup> 
    42       <module>ping_icmp</module> 
    43       <period>30000</period> 
    44       <timeout>20000</timeout> 
    45       <check uuid="1b4e28ba-2fa1-11d2-883f-b9a761bde3fb"> 
    46         <target>66.225.209.7</target> 
    47       </check> 
    48     </checkgroup> 
    49     <checkgroup> 
    50       <module>http</module> 
    51       <period>30000</period> 
    52       <timeout>5000</timeout> 
    53       <check uuid="1b4e28ba-2fa1-11d2-883f-b9a761bde3fc"> 
    54         <target>66.225.209.31</target> 
    55         <config> 
    56           <url>http://ngm.nationalgeographic.com/ngm/ngm.html</url> 
    57           <code>302</code> 
    58         </config> 
    59       </check> 
    60       <check uuid="1b4e28ba-2fa1-11d2-883f-b9a761bde3ff"> 
    61         <target>8.8.38.59</target> 
    62         <config> 
    63           <url>https://taskman.omniti.com/</url> 
    64           <code>200</code> 
    65         </config> 
    66       </check> 
    67     </checkgroup> 
    68     <checkgroup> 
    69       <module>resmon</module> 
    70       <period>30000</period> 
    71       <timeout>5000</timeout> 
    72       <check uuid="1b4e28ba-2fa1-11d2-883f-b9a761bde3fd"> 
    73         <target>10.225.209.36</target> 
    74         <timeout>2000</timeout> 
    75       </check> 
    76     </checkgroup> 
    77     <checkgroup> 
    78       <module>resmon_part</module> 
    79       <timeout>1000</timeout> 
    80       <oncheck>resmon</oncheck> 
    81       <check uuid="1b4e28ba-2fa1-11d2-883f-b9a761bde3fe"> 
    82         <target>10.225.209.36</target> 
    83         <config> 
    84           <resmon_module>FAULTS</resmon_module> 
    85           <resmon_service>hardware</resmon_service> 
    86         </config> 
    87       </check> 
    88     </checkgroup> 
     41    <dc1 timeout="30000" period="60000"> 
     42      <icmp module="ping_icmp" timeout="12000"> 
     43        <check uuid="1b4e28ba-2fa1-11d2-883f-b9a761bde3fb" target="66.225.509.7" /> 
     44      </icmp> 
     45      <web module="http" timeout="8000"> 
     46        <check uuid="1b4e28ba-2fa1-11d2-883f-b9a761bde3fc" target="66.225.209.31"> 
     47          <config> 
     48            <url>http://ngm.nationalgeographic.com/ngm/ngm.html</url> 
     49            <code>302</code> 
     50          </config> 
     51        </check> 
     52        <check uuid="1b4e28ba-2fa1-11d2-883f-b9a761bde3ff" target="8.8.38.59"> 
     53          <config> 
     54            <url>https://taskman.omniti.com/</url> 
     55            <code>200</code> 
     56          </config> 
     57        </check> 
     58      </web> 
     59      <resmon module="resmon" period="30000" timeout="5000"> 
     60        <check uuid="1b4e28ba-2fa1-11d2-883f-b9a761bde3fd" 
     61               timeout="2000" target="10.225.209.36" /> 
     62        <parts module="resmon_part" period="0" timeout="1000" oncheck="resmon"> 
     63          <check uuid="1b4e28ba-2fa1-11d2-883f-b9a761bde3fe" 
     64                 target="10.225.209.36"> 
     65            <config> 
     66              <resmon_module>FAULTS</resmon_module> 
     67              <resmon_service>hardware</resmon_service> 
     68            </config> 
     69          </check> 
     70        </parts> 
     71      </resmon> 
     72    </dc1> 
    8973  </checks> 
    9074</noit>