diff mod_host_status_check/mod_host_status_check.lua @ 2219:5fcf9d558250

Three new modules: mod_host_status_check, mod_host_status_heartbeat and mod_http_host_status_check
author Matthew Wild <mwild1@gmail.com>
date Tue, 28 Jun 2016 22:33:13 +0100
parents
children 3d80f8dba886
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mod_host_status_check/mod_host_status_check.lua	Tue Jun 28 22:33:13 2016 +0100
@@ -0,0 +1,28 @@
+local time = require "socket".gettime;
+
+local heartbeats = module:shared("/*/host_status_check/heartbeats");
+local connection_events = module:shared("/*/host_status_check/connection_events");
+
+if prosody.hosts[module.host].type == "component" and module:get_option_string("component_module") == "component" then
+	module:hook("component-authenticated", function ()
+		connection_events[module.host] = { connected = true; timestamp = time() };
+	end);
+
+	-- Note: this event is not in 0.9, and requires a recent 0.10 or trunk build
+	module:hook("component-disconnected", function ()
+		connection_events[module.host] = { connected = false; timestamp = time() };
+	end);
+
+	module:hook("stanza/xmpp:prosody.im/heartbeat:heartbeat", function ()
+		heartbeats[module.host] = time();
+		return true;
+	end);
+else
+	connection_events[module.host] = { connected = true, timestamp = time() };
+	module:log("debug", "BLAH")
+end
+
+function module.unload()
+	connection_events[module.host] = { connected = false, timestamp = time() };
+	heartbeats[module.host] = nil;
+end