Mercurial > prosody-modules
comparison mod_host_status_heartbeat/mod_host_status_heartbeat.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 | 7f955f92bbbb |
comparison
equal
deleted
inserted
replaced
2218:0ca0fdad3b2c | 2219:5fcf9d558250 |
---|---|
1 local st = require "util.stanza"; | |
2 local time = require "socket".gettime; | |
3 | |
4 local heartbeat_interval = module:get_option_number("status_check_heartbeat_interval", 5); | |
5 local heartbeat_mode = module:get_option_string("status_check_heartbeat_mode", "remote"); | |
6 | |
7 local local_heartbeats = module:shared("/*/host_status_check/heartbeats"); | |
8 | |
9 local heartbeat_methods = { | |
10 ["local"] = function() | |
11 module:log("debug", "Local heartbeat"); | |
12 local_heartbeats[module.host] = time(); | |
13 return heartbeat_interval; | |
14 end; | |
15 | |
16 ["remote"] = function () | |
17 module:fire_event("route/remote", { | |
18 origin = prosody.hosts[module.host]; | |
19 stanza = st.stanza("heartbeat", { xmlns = "xmpp:prosody.im/heartbeat" }); | |
20 }); | |
21 return heartbeat_interval; | |
22 end; | |
23 } | |
24 | |
25 local send_heartbeat = assert(heartbeat_methods[heartbeat_mode], "Unknown heartbeat_mode: "..heartbeat_mode); | |
26 | |
27 --FIXME: Commented for testing!!! :) | |
28 module:add_timer(0, send_heartbeat); |