Changeset e437d462c935dbd146a664ca0f0119405bf487dc for src
- Timestamp:
- 08/10/11 17:31:46 (2 years ago)
- git-parent:
- Files:
-
- src/modules/lua.c (modified) (6 diffs)
- src/noit_check.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
src/modules/lua.c
rf91ddca re437d46 249 249 } 250 250 static int 251 noit_lua_get_available(lua_State *L) { 252 char av[2] = { '\0', '\0' }; 253 noit_check_t *check; 254 noit_lua_check_info_t *ci; 255 if(lua_gettop(L)) luaL_error(L, "wrong number of arguments"); 256 check = lua_touserdata(L, lua_upvalueindex(1)); 257 av[0] = (char)check->stats.current.available; 258 lua_pushstring(L, av); 259 return 1; 260 } 261 static int 251 262 noit_lua_set_available(lua_State *L) { 252 263 noit_check_t *check; … … 257 268 ci->current.available = lua_tointeger(L, lua_upvalueindex(2)); 258 269 return 0; 270 } 271 static int 272 noit_lua_get_state(lua_State *L) { 273 char status[2] = { '\0', '\0' }; 274 noit_check_t *check; 275 noit_lua_check_info_t *ci; 276 if(lua_gettop(L)) luaL_error(L, "wrong number of arguments"); 277 check = lua_touserdata(L, lua_upvalueindex(1)); 278 status[0] = (char)check->stats.current.state; 279 lua_pushstring(L, status); 280 return 1; 259 281 } 260 282 static int … … 373 395 lua_pushcclosure(L, noit_lua_set_available, 2); 374 396 } 397 else if(!strcmp(k, "availability")) { 398 lua_pushlightuserdata(L, check); 399 lua_pushcclosure(L, noit_lua_get_available, 1); 400 } 375 401 else break; 376 402 return 1; … … 423 449 return 1; 424 450 case 's': 425 if(!strcmp(k, "status")) { 451 if(!strcmp(k, "state")) { 452 lua_pushlightuserdata(L, check); 453 lua_pushcclosure(L, noit_lua_get_state, 1); 454 } 455 else if(!strcmp(k, "status")) { 426 456 lua_pushlightuserdata(L, check); 427 457 lua_pushcclosure(L, noit_lua_set_status, 1); … … 612 642 ci->current.duration = duration.tv_sec * 1000 + duration.tv_usec / 1000; 613 643 614 noit_check_set_stats(self, check, &ci->current); 644 /* Only set out stats/log if someone has actually performed a check */ 645 if(ci->current.state != NP_UNKNOWN || 646 ci->current.available != NP_UNKNOWN) 647 noit_check_set_stats(self, check, &ci->current); 615 648 free(ci->current.status); 616 649 } … … 755 788 noit_lua_setup_module(ci->coro_state, ci->self); 756 789 noit_lua_setup_check(ci->coro_state, ci->check); 757 lua_pushnil(L); 790 if(cause) noit_lua_setup_check(ci->coro_state, ci->cause); 791 else lua_pushnil(L); 758 792 noit_lua_resume(ci, 3); 759 793 src/noit_check.c
r17461d6 re437d46 121 121 if(start_offset_ms == -1) 122 122 start_offset_ms = drand48() * noit_check_max_initial_stutter(); 123 if(!(check->flags & NP_TRANSIENT) ) {123 if(!(check->flags & NP_TRANSIENT) && check->period) { 124 124 max = noit_check_max_initial_stutter(); 125 125 offset = start_offset_ms + drand48() * 1000; … … 336 336 if(check->oncheck) { 337 337 /* This service is causally triggered by another service */ 338 uuid_t id; 338 339 char fullcheck[1024]; 339 340 char *name = check->oncheck; … … 341 342 342 343 noitL(noit_debug, "Searching for upstream trigger on %s\n", name); 344 parent = NULL; 345 if(uuid_parse(check->oncheck, id) == 0) { 346 target = ""; 347 parent = noit_poller_lookup(id); 348 } 343 349 if((target = strchr(check->oncheck, '`')) != NULL) { 344 strlcpy(fullcheck, check->oncheck, target - check->oncheck);350 strlcpy(fullcheck, check->oncheck, target + 1 - check->oncheck); 345 351 name = target + 1; 346 352 target = fullcheck; 353 parent = noit_poller_lookup_by_name(target, name); 347 354 } 348 else 349 target = check->target; 350 351 parent = noit_poller_lookup_by_name(target, name); 355 else { 356 target = check->target; 357 parent = noit_poller_lookup_by_name(target, name); 358 } 359 352 360 if(!parent) { 353 361 check->flags |= NP_DISABLED; … … 861 869 } 862 870 871 static int 872 bad_check_initiate(noit_module_t *self, noit_check_t *check, 873 int once, noit_check_t *cause) { 874 /* self is likely null here -- why it is bad, in fact */ 875 /* this is only suitable to call in one-offs */ 876 stats_t current; 877 char buff[256]; 878 if(!once) return -1; 879 if(!check) return -1; 880 assert(!(check->flags & NP_RUNNING)); 881 check->flags |= NP_RUNNING; 882 noit_check_stats_clear(¤t); 883 gettimeofday(¤t.whence, NULL); 884 current.duration = 0; 885 current.available = NP_UNKNOWN; 886 current.state = NP_UNKNOWN; 887 snprintf(buff, sizeof(buff), "check[%s] implementation offline", 888 check->module); 889 current.status = buff; 890 noit_check_set_stats(self, check, ¤t); 891 check->flags &= ~NP_RUNNING; 892 return 0; 893 } 863 894 void 864 895 noit_check_stats_clear(stats_t *s) { … … 1134 1165 noit_module_t *mod; 1135 1166 mod = noit_module_lookup(dep->check->module); 1136 assert(mod); 1137 noitL(noit_debug, "Firing %s`%s in response to %s`%s\n", 1138 dep->check->target, dep->check->name, 1139 check->target, check->name); 1140 if((dep->check->flags & NP_DISABLED) == 0) 1141 if(mod->initiate_check) 1142 mod->initiate_check(mod, dep->check, 1, check); 1167 if(!mod) { 1168 bad_check_initiate(mod, dep->check, 1, check); 1169 } 1170 else { 1171 noitL(noit_debug, "Firing %s`%s in response to %s`%s\n", 1172 dep->check->target, dep->check->name, 1173 check->target, check->name); 1174 if((dep->check->flags & NP_DISABLED) == 0) 1175 if(mod->initiate_check) 1176 mod->initiate_check(mod, dep->check, 1, check); 1177 } 1143 1178 } 1144 1179 }
