Changeset 129a0bae7c19dce74dfb70efd8e069b47209c6d8
- Timestamp:
- 02/14/08 23:09:07
(5 years ago)
- Author:
- Theo Schlossnagle <jesus@omniti.com>
- git-committer:
- Theo Schlossnagle <jesus@omniti.com> 1203030547 +0000
- git-parent:
[e01b3ad015472c9a83ced96738b07da543511a40]
- git-author:
- Theo Schlossnagle <jesus@omniti.com> 1203030547 +0000
- Message:
show checks
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| re01b3ad |
r129a0ba |
|
| 162 | 162 | return sections; |
|---|
| 163 | 163 | } |
|---|
| 164 | | int _noit_conf_get_string(noit_conf_section_t section, |
|---|
| | 164 | int _noit_conf_get_string(noit_conf_section_t section, xmlNodePtr *vnode, |
|---|
| 165 | 165 | const char *path, char **value) { |
|---|
| 166 | 166 | char *str; |
|---|
| … | … | |
| 183 | 183 | i = xmlXPathNodeSetGetLength(pobj->nodesetval); |
|---|
| 184 | 184 | node = xmlXPathNodeSetItem(pobj->nodesetval, i-1); |
|---|
| | 185 | if(vnode) *vnode = node; |
|---|
| 185 | 186 | *value = (char *)xmlXPathCastNodeToString(node); |
|---|
| 186 | 187 | break; |
|---|
| … | … | |
| 204 | 205 | const char *path, char **value) { |
|---|
| 205 | 206 | char *str; |
|---|
| 206 | | if(_noit_conf_get_string(section,path,&str)) { |
|---|
| | 207 | if(_noit_conf_get_string(section,NULL,path,&str)) { |
|---|
| 207 | 208 | *value = strdup(str); |
|---|
| 208 | 209 | return 1; |
|---|
| … | … | |
| 213 | 214 | const char *path, char *buf, int len) { |
|---|
| 214 | 215 | char *str; |
|---|
| 215 | | if(_noit_conf_get_string(section,path,&str)) { |
|---|
| | 216 | if(_noit_conf_get_string(section,NULL,path,&str)) { |
|---|
| 216 | 217 | strlcpy(buf, str, len); |
|---|
| 217 | 218 | return 1; |
|---|
| … | … | |
| 230 | 231 | char *str; |
|---|
| 231 | 232 | long longval; |
|---|
| 232 | | if(noit_conf_get_string(section,path,&str)) { |
|---|
| | 233 | if(_noit_conf_get_string(section,NULL,path,&str)) { |
|---|
| 233 | 234 | int base = 10; |
|---|
| 234 | 235 | if(str[0] == '0') { |
|---|
| … | … | |
| 237 | 238 | } |
|---|
| 238 | 239 | longval = strtol(str, NULL, base); |
|---|
| 239 | | free(str); |
|---|
| 240 | 240 | *value = (int)longval; |
|---|
| 241 | 241 | return 1; |
|---|
| … | … | |
| 252 | 252 | const char *path, float *value) { |
|---|
| 253 | 253 | char *str; |
|---|
| 254 | | if(noit_conf_get_string(section,path,&str)) { |
|---|
| | 254 | if(_noit_conf_get_string(section,NULL,path,&str)) { |
|---|
| 255 | 255 | *value = atof(str); |
|---|
| 256 | | free(str); |
|---|
| 257 | 256 | return 1; |
|---|
| 258 | 257 | } |
|---|
| … | … | |
| 268 | 267 | const char *path, noit_conf_boolean *value) { |
|---|
| 269 | 268 | char *str; |
|---|
| 270 | | if(noit_conf_get_string(section,path,&str)) { |
|---|
| | 269 | if(_noit_conf_get_string(section,NULL,path,&str)) { |
|---|
| 271 | 270 | if(!strcasecmp(str, "true")) *value = noit_true; |
|---|
| 272 | 271 | else *value = noit_false; |
|---|
| 273 | | free(str); |
|---|
| 274 | 272 | return 1; |
|---|
| 275 | 273 | } |
|---|
| … | … | |
| 340 | 338 | return 0; |
|---|
| 341 | 339 | } |
|---|
| | 340 | static void |
|---|
| | 341 | nc_attr_show(noit_console_closure_t ncct, const char *name, xmlNodePtr cnode, |
|---|
| | 342 | xmlNodePtr anode, const char *value) { |
|---|
| | 343 | const char *cpath, *apath; |
|---|
| | 344 | cpath = cnode ? (char *)xmlGetNodePath(cnode) : ""; |
|---|
| | 345 | apath = anode ? (char *)xmlGetNodePath(anode) : ""; |
|---|
| | 346 | nc_printf(ncct, " %s: %s", name, value ? value : "[undef]"); |
|---|
| | 347 | if(value && cpath && apath) { |
|---|
| | 348 | int clen = strlen(cpath); |
|---|
| | 349 | int plen = strlen("/noit/checks/"); |
|---|
| | 350 | if(!strncmp(cpath, apath, clen) && apath[clen] == '/') { |
|---|
| | 351 | /* we have a match, which means it isn't inherited */ |
|---|
| | 352 | } |
|---|
| | 353 | else { |
|---|
| | 354 | nc_printf(ncct, " [inherited from %s]", |
|---|
| | 355 | strlen(apath) > plen ? apath + plen : apath); |
|---|
| | 356 | } |
|---|
| | 357 | } |
|---|
| | 358 | nc_write(ncct, "\n", 1); |
|---|
| | 359 | } |
|---|
| 342 | 360 | static int |
|---|
| 343 | 361 | noit_console_check(noit_console_closure_t ncct, |
|---|
| … | … | |
| 375 | 393 | for(i=0; i<cnt; i++) { |
|---|
| 376 | 394 | uuid_t checkid; |
|---|
| 377 | | xmlNodePtr node; |
|---|
| | 395 | xmlNodePtr node, anode, mnode = NULL; |
|---|
| 378 | 396 | char *uuid_conf; |
|---|
| | 397 | char *module, *value; |
|---|
| 379 | 398 | |
|---|
| 380 | 399 | node = (noit_conf_section_t)xmlXPathNodeSetItem(pobj->nodesetval, i); |
|---|
| … | … | |
| 390 | 409 | } |
|---|
| 391 | 410 | nc_printf(ncct, "==== %s ====\n", uuid_conf); |
|---|
| | 411 | |
|---|
| | 412 | #define MYATTR(a,n,b) _noit_conf_get_string(node, &(n), "@" #a, &(b)) |
|---|
| | 413 | #define INHERIT(a,n,b) \ |
|---|
| | 414 | _noit_conf_get_string(node, &(n), "ancestor-or-self::node()/@" #a, &(b)) |
|---|
| | 415 | #define SHOW_ATTR(a) do { \ |
|---|
| | 416 | anode = NULL; \ |
|---|
| | 417 | value = NULL; \ |
|---|
| | 418 | INHERIT(a, anode, value); \ |
|---|
| | 419 | nc_attr_show(ncct, #a, node, anode, value); \ |
|---|
| | 420 | } while(0) |
|---|
| | 421 | |
|---|
| | 422 | if(!INHERIT(module, mnode, module)) module = NULL; |
|---|
| | 423 | if(MYATTR(name, anode, value)) |
|---|
| | 424 | nc_printf(ncct, " name: %s\n", value); |
|---|
| | 425 | else |
|---|
| | 426 | nc_printf(ncct, " name: %s [from module]\n", module ? module : "[undef]"); |
|---|
| | 427 | nc_attr_show(ncct, "module", node, mnode, module); |
|---|
| | 428 | SHOW_ATTR(target); |
|---|
| | 429 | SHOW_ATTR(period); |
|---|
| | 430 | SHOW_ATTR(timeout); |
|---|
| | 431 | SHOW_ATTR(oncheck); |
|---|
| 392 | 432 | } |
|---|
| 393 | 433 | out: |
|---|
| … | … | |
| 737 | 777 | if(path_len > max_len) |
|---|
| 738 | 778 | snprintf(info->prompt, sizeof(info->prompt), |
|---|
| 739 | | pfmt, "...", info->path + max_len - 3 /* ... */); |
|---|
| | 779 | pfmt, "...", info->path + path_len - max_len + 3 /* ... */); |
|---|
| 740 | 780 | else |
|---|
| 741 | 781 | snprintf(info->prompt, sizeof(info->prompt), pfmt, "", info->path); |
|---|