Changeset 67a2095e250dc562985ebc225064b0ef2a68ba2f
- Timestamp:
- 02/11/08 20:32:47 (5 years ago)
- git-parent:
- Files:
-
- src/noit_check.c (modified) (4 diffs)
- src/noit_conf.c (modified) (5 diffs)
- src/noit_console.c (modified) (1 diff)
- src/sample.conf (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
src/noit_check.c
rb0614c3 r67a2095 94 94 char module[256]; 95 95 char name[256]; 96 char oncheck[1024] ;96 char oncheck[1024] = ""; 97 97 int no_period = 0; 98 98 int no_oncheck = 0; … … 101 101 noit_hash_table *options; 102 102 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))) { 105 109 noitL(noit_stderr, "check %d has no uuid\n", i+1); 106 110 continue; 107 111 } 112 108 113 if(uuid_parse(uuid_str, uuid)) { 109 114 noitL(noit_stderr, "check uuid: '%s' is invalid\n", uuid_str); 110 115 continue; 111 116 } 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))) 123 128 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) 126 131 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]) 130 134 no_oncheck = 1; 131 } 135 132 136 if(no_period && no_oncheck) { 133 137 noitL(noit_stderr, "check uuid: '%s' has neither period nor oncheck\n", … … 136 140 } 137 141 if(!(no_period || no_oncheck)) { 138 noitL(noit_stderr, "check uuid: '%s' has has oncheck and period.\n",142 noitL(noit_stderr, "check uuid: '%s' has oncheck and period.\n", 139 143 uuid_str); 140 144 continue; 141 145 } 142 if(! noit_conf_get_int(sec[i], "ancestor-or-self::node()/timeout", &timeout)) {146 if(!INHERIT(int, timeout, &timeout)) { 143 147 noitL(noit_stderr, "check uuid: '%s' has no timeout\n", uuid_str); 144 148 continue; … … 211 215 dep->next = parent->causal_checks; 212 216 parent->causal_checks = dep; 217 noitL(noit_debug, "Causal map %s`%s --> %s`%s\n", 218 parent->target, parent->name, check->target, check->name); 213 219 } 214 220 } src/noit_conf.c
r341415b r67a2095 362 362 noit_console_state_t *state, void *closure) { 363 363 int i, cnt, titled = 0, cliplen = 0; 364 const char *path ;364 const char *path, *basepath = NULL; 365 365 char xpath[1024]; 366 noit_conf_t_userdata_t *info ;366 noit_conf_t_userdata_t *info = NULL; 367 367 xmlXPathObjectPtr pobj = NULL; 368 368 xmlXPathContextPtr current_ctxt; … … 373 373 return -1; 374 374 } 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 386 390 if(!master_config) { 387 391 nc_printf(ncct, "no config\n"); … … 393 397 * Ever notice how it is hard to describe xpath in C comments? 394 398 */ 399 /* We don't want to show the root node */ 395 400 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); 402 410 403 411 current_ctxt = xpath_ctxt; … … 407 415 goto bad; 408 416 } 409 if(xmlXPathNodeSetIsEmpty(pobj->nodesetval)) {410 nc_printf(ncct, "empty\n");411 }412 417 cnt = xmlXPathNodeSetGetLength(pobj->nodesetval); 413 414 418 titled = 0; 415 419 for(i=0; i<cnt; i++) { … … 423 427 } 424 428 } 425 429 xmlXPathFreeObject(pobj); 430 431 /* _shorten string_ turning last { / @ * } to { / * } */ 432 strlcpy(xpath + strlen(xpath) - 2, "*", 2); 433 nc_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); 426 440 titled = 0; 427 441 for(i=0; i<cnt; i++) { src/noit_console.c
r1fe89bb r67a2095 237 237 else if(i<0) nc_printf(ncct, "Error at offset: %d\n", 0-i); 238 238 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 }243 239 } 244 240 src/sample.conf
rd936b80 r67a2095 39 39 </listeners> 40 40 <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> 89 73 </checks> 90 74 </noit>
