Changeset e01b3ad015472c9a83ced96738b07da543511a40
- Timestamp:
- 02/13/08 22:50:43 (5 years ago)
- git-parent:
- Files:
-
- src/noit_check.c (modified) (12 diffs)
- src/noit_check.h (modified) (4 diffs)
- src/noit_conf.c (modified) (4 diffs)
- src/sample.conf (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
src/noit_check.c
r6e90b3f re01b3ad 85 85 void 86 86 noit_poller_process_checks(const char *xpath) { 87 int i, cnt = 0;87 int i, flags, cnt = 0; 88 88 noit_conf_section_t *sec; 89 89 __config_load_generation++; … … 99 99 int no_oncheck = 0; 100 100 int period = 0, timeout = 0; 101 noit_conf_boolean disabled = noit_false ;101 noit_conf_boolean disabled = noit_false, busted = noit_false; 102 102 uuid_t uuid, out_uuid; 103 103 noit_hash_table *options; … … 120 120 if(!INHERIT(stringbuf, target, target, sizeof(target))) { 121 121 noitL(noit_stderr, "check uuid: '%s' has no target\n", uuid_str); 122 disabled = noit_true;122 busted = noit_true; 123 123 } 124 124 if(!INHERIT(stringbuf, module, module, sizeof(module))) { 125 125 noitL(noit_stderr, "check uuid: '%s' has no module\n", uuid_str); 126 disabled = noit_true;126 busted = noit_true; 127 127 } 128 128 … … 139 139 noitL(noit_stderr, "check uuid: '%s' has neither period nor oncheck\n", 140 140 uuid_str); 141 disabled = noit_true;141 busted = noit_true; 142 142 } 143 143 if(!(no_period || no_oncheck)) { 144 144 noitL(noit_stderr, "check uuid: '%s' has oncheck and period.\n", 145 145 uuid_str); 146 disabled = noit_true;146 busted = noit_true; 147 147 } 148 148 if(!INHERIT(int, timeout, &timeout)) { 149 149 noitL(noit_stderr, "check uuid: '%s' has no timeout\n", uuid_str); 150 disabled = noit_true;150 busted = noit_true; 151 151 } 152 152 if(!no_period && timeout >= period) { … … 155 155 } 156 156 options = noit_conf_get_hash(sec[i], "ancestor-or-self::node()/config/*"); 157 158 flags = 0; 159 if(busted) flags |= NP_UNCONFIG; 160 if(disabled) flags |= NP_DISABLED; 157 161 158 162 if(noit_hash_retrieve(&polls, (char *)uuid, UUID_SIZE, … … 160 164 noit_check_update(existing_check, target, name, options, 161 165 period, timeout, oncheck[0] ? oncheck : NULL, 162 disabled);166 flags); 163 167 noitL(noit_debug, "reloaded uuid: %s\n", uuid_str); 164 168 } … … 166 170 noit_poller_schedule(target, module, name, options, 167 171 period, timeout, oncheck[0] ? oncheck : NULL, 168 disabled, uuid, out_uuid);172 flags, uuid, out_uuid); 169 173 noitL(noit_debug, "loaded uuid: %s\n", uuid_str); 170 174 } … … 274 278 u_int32_t timeout, 275 279 const char *oncheck, 276 noit_conf_boolean disabled) {280 int flags) { 277 281 int8_t family; 278 282 int rv; 283 int mask = NP_DISABLED | NP_UNCONFIG; 279 284 union { 280 285 struct in_addr addr4; … … 291 296 noitL(noit_stderr, "Cannot translate '%s' to IP\n", target); 292 297 memset(&a, 0, sizeof(a)); 293 disabled = noit_true;298 flags |= (NP_UNCONFIG & NP_DISABLED); 294 299 } 295 300 } … … 319 324 new_check->timeout = timeout; 320 325 321 if(disabled) new_check->flags |= NP_DISABLED; 326 /* Unset what could be set.. then set what should be set */ 327 new_check->flags = (new_check->flags & ~mask) | flags; 322 328 323 329 /* This remove could fail -- no big deal */ … … 341 347 u_int32_t timeout, 342 348 const char *oncheck, 343 noit_conf_boolean disabled,349 int flags, 344 350 uuid_t in, 345 351 uuid_t out) { … … 356 362 357 363 noit_check_update(new_check, target, name, config, 358 period, timeout, oncheck, disabled);364 period, timeout, oncheck, flags); 359 365 assert(noit_hash_store(&polls, 360 366 (char *)new_check->checkid, UUID_SIZE, src/noit_check.h
r6e90b3f re01b3ad 37 37 #define NP_KILLED 0x00000002 38 38 #define NP_DISABLED 0x00000004 39 #define NP_UNCONFIG 0x00000008 39 40 40 41 #define NP_UNKNOWN 0 /* stats_t.{available,state} */ … … 97 98 #define NOIT_CHECK_LIVE(a) ((a)->fire_event != NULL) 98 99 #define NOIT_CHECK_DISABLED(a) ((a)->flags & NP_DISABLED) 100 #define NOIT_CHECK_CONFIGURED(a) (((a)->flags & NP_UNCONFIG) == 0) 99 101 #define NOIT_CHECK_RUNNING(a) ((a)->flags & NP_RUNNING) 100 102 #define NOIT_CHECK_KILLED(a) ((a)->flags & NP_KILLED) … … 118 120 u_int32_t timeout, 119 121 const char *oncheck, 120 noit_conf_boolean disabled,122 int flags, 121 123 uuid_t in, 122 124 uuid_t out); … … 130 132 u_int32_t timeout, 131 133 const char *oncheck, 132 noit_conf_boolean disabled);134 int flags); 133 135 134 136 API_EXPORT(int) src/noit_conf.c
r6e90b3f re01b3ad 308 308 return 0; 309 309 } 310 311 static int 312 noit_console_config_nocheck(noit_console_closure_t ncct, 313 int argc, char **argv, 314 noit_console_state_t *state, void *closure) { 315 int i, cnt; 316 const char *err = "internal error"; 310 static int 311 noit_console_mkcheck_xpath(char *xpath, int len, 312 noit_conf_t_userdata_t *info, 313 const char *arg) { 314 uuid_t checkid; 317 315 char argcopy[1024], *target, *name; 318 noit_conf_t_userdata_t *info; 319 xmlXPathObjectPtr pobj = NULL; 320 char xpath[1024]; 321 322 uuid_t checkid; 323 if(argc != 1) { 324 nc_printf(ncct, "requires one argument\n"); 325 return -1; 326 } 327 328 info = noit_console_userdata_get(ncct, NOIT_CONF_T_USERDATA); 329 330 strlcpy(argcopy, argv[0], sizeof(argcopy)); 316 317 strlcpy(argcopy, arg, sizeof(argcopy)); 331 318 if(uuid_parse(argcopy, checkid) == 0) { 332 319 /* If they kill by uuid, we'll seek and destroy -- find it anywhere */ 333 snprintf(xpath, sizeof(xpath), "/noit/checks//check[@uuid=\"%s\"]",320 snprintf(xpath, len, "/noit/checks//check[@uuid=\"%s\"]", 334 321 argcopy); 335 322 } … … 341 328 check = noit_poller_lookup_by_name(target, name); 342 329 if(!check) { 343 nc_printf(ncct, "could not find check %s`%s\n", target, name);344 330 return -1; 345 331 } 346 332 uuid_unparse_lower(check->checkid, uuid_str); 347 snprintf(xpath, sizeof(xpath), "/noit/checks//check[@uuid=\"%s\"]",333 snprintf(xpath, len, "/noit/checks//check[@uuid=\"%s\"]", 348 334 uuid_str); 349 335 } 350 336 else { 351 char *path = strcmp(info->path, "/") ? info->path : ""; 352 snprintf(xpath, sizeof(xpath), "/noit%s/%s[@uuid]", path, argv[0]); 353 } 354 337 char *path = (!info || !strcmp(info->path, "/")) ? "" : info->path; 338 snprintf(xpath, len, "/noit%s/%s[@uuid]", path, arg); 339 } 340 return 0; 341 } 342 static int 343 noit_console_check(noit_console_closure_t ncct, 344 int argc, char **argv, 345 noit_console_state_t *state, void *closure) { 346 int i, cnt; 347 noit_conf_t_userdata_t *info; 348 char xpath[1024]; 349 xmlXPathObjectPtr pobj = NULL; 350 351 if(argc > 1) { 352 nc_printf(ncct, "requires zero or one arguments\n"); 353 return -1; 354 } 355 356 info = noit_console_userdata_get(ncct, NOIT_CONF_T_USERDATA); 357 /* We many not be in conf-t mode -- that's fine */ 358 if(noit_console_mkcheck_xpath(xpath, sizeof(xpath), info, 359 argc ? argv[0] : ".")) { 360 nc_printf(ncct, "could not find check '%s'\n", argv[0]); 361 return -1; 362 } 363 364 pobj = xmlXPathEval((xmlChar *)xpath, xpath_ctxt); 365 if(!pobj || pobj->type != XPATH_NODESET || 366 xmlXPathNodeSetIsEmpty(pobj->nodesetval)) { 367 nc_printf(ncct, "no checks found\n"); 368 goto out; 369 } 370 cnt = xmlXPathNodeSetGetLength(pobj->nodesetval); 371 if(info && cnt != 1) { 372 nc_printf(ncct, "Ambiguous check specified\n"); 373 goto out; 374 } 375 for(i=0; i<cnt; i++) { 376 uuid_t checkid; 377 xmlNodePtr node; 378 char *uuid_conf; 379 380 node = (noit_conf_section_t)xmlXPathNodeSetItem(pobj->nodesetval, i); 381 if(info) { 382 if(info->path) free(info->path); 383 info->path = strdup((char *)xmlGetNodePath(node) + strlen("/noit")); 384 } 385 uuid_conf = (char *)xmlGetProp(node, (xmlChar *)"uuid"); 386 if(!uuid_conf || uuid_parse(uuid_conf, checkid)) { 387 nc_printf(ncct, "%s has invalid or missing UUID!\n", 388 (char *)xmlGetNodePath(node) + strlen("/noit")); 389 continue; 390 } 391 nc_printf(ncct, "==== %s ====\n", uuid_conf); 392 } 393 out: 394 if(pobj) xmlXPathFreeObject(pobj); 395 return 0; 396 } 397 static int 398 noit_console_config_nocheck(noit_console_closure_t ncct, 399 int argc, char **argv, 400 noit_console_state_t *state, void *closure) { 401 int i, cnt; 402 const char *err = "internal error"; 403 noit_conf_t_userdata_t *info; 404 xmlXPathObjectPtr pobj = NULL; 405 char xpath[1024]; 406 uuid_t checkid; 407 408 if(argc != 1) { 409 nc_printf(ncct, "requires one argument\n"); 410 return -1; 411 } 412 413 info = noit_console_userdata_get(ncct, NOIT_CONF_T_USERDATA); 414 if(noit_console_mkcheck_xpath(xpath, sizeof(xpath), info, argv[0])) { 415 nc_printf(ncct, "could not find check '%s'\n", argv[0]); 416 return -1; 417 } 355 418 pobj = xmlXPathEval((xmlChar *)xpath, xpath_ctxt); 356 419 if(!pobj || pobj->type != XPATH_NODESET || … … 934 997 static 935 998 void register_console_config_commands() { 999 cmd_info_t *showcmd; 936 1000 noit_console_state_t *tl, *_conf_state, *_conf_t_state, 937 1001 *_write_state, *_attr_state, … … 964 1028 ADD_CMD(_conf_t_state, "ls", noit_console_config_show, NULL, NULL); 965 1029 ADD_CMD(_conf_t_state, "cd", noit_console_config_cd, NULL, NULL); 1030 ADD_CMD(_conf_t_state, "check", noit_console_check, NULL, NULL); 966 1031 ADD_CMD(_conf_t_state, "section", noit_console_config_section, NULL, (void *)0); 1032 1033 showcmd = noit_console_state_get_cmd(tl, "show"); 1034 ADD_CMD(showcmd->dstate, "check", noit_console_check, NULL, NULL); 1035 967 1036 DELEGATE_CMD(_conf_t_state, "write", _write_state); 968 1037 DELEGATE_CMD(_conf_t_state, "attribute", _attr_state); src/sample.conf
r998fcf4 re01b3ad 39 39 </listeners> 40 40 <checks> 41 <check uuid="1b4e28ba-2fa1-11d2-883f-b9b761bde3fb" /> 41 42 <dc1 timeout="30000" period="60000"> 42 43 <icmp module="ping_icmp" timeout="12000">
