mod_audit_status/mod_audit_status.lua
changeset 5844 bd0abf821cef
parent 5747 9944c6c3e914
equal deleted inserted replaced
5843:fba64b043c52 5844:bd0abf821cef
     7 
     7 
     8 local heartbeat_interval = module:get_option_number("audit_status_heartbeat_interval", 60);
     8 local heartbeat_interval = module:get_option_number("audit_status_heartbeat_interval", 60);
     9 
     9 
    10 local store = module:open_store(nil, "keyval+");
    10 local store = module:open_store(nil, "keyval+");
    11 
    11 
       
    12 -- This is global, to make it available to other modules
       
    13 crashed = false; --luacheck: ignore 131/crashed
       
    14 
    12 module:hook_global("server-started", function ()
    15 module:hook_global("server-started", function ()
    13 	local recorded_status = store:get();
    16 	local recorded_status = store:get();
    14 	if recorded_status and recorded_status.status == "started" then
    17 	if recorded_status and recorded_status.status == "started" then
    15 		module:audit(nil, "server-crashed", { timestamp = recorded_status.heartbeat });
    18 		module:audit(nil, "server-crashed", { timestamp = recorded_status.heartbeat });
       
    19 		crashed = true;
    16 	end
    20 	end
    17 	module:audit(nil, "server-started");
    21 	module:audit(nil, "server-started");
    18 	store:set_key(nil, "status", "started");
    22 	store:set_key(nil, "status", "started");
    19 end);
    23 end);
    20 
    24