Mercurial > prosody-modules
annotate mod_host_status_heartbeat/mod_host_status_heartbeat.lua @ 4838:fd2e48d4ac94
mod_bookmarks2: Advertise XEP-0049 support
In the case mod_private isn’t loaded, some clients (like poezio) won’t even
attempt to use Private XML Storage unless this feature is advertised. This is
on the domain JID and not on the account JID!
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Sun, 26 Dec 2021 14:51:35 +0100 |
parents | 7f955f92bbbb |
children |
rev | line source |
---|---|
2219
5fcf9d558250
Three new modules: mod_host_status_check, mod_host_status_heartbeat and mod_http_host_status_check
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1 local st = require "util.stanza"; |
5fcf9d558250
Three new modules: mod_host_status_check, mod_host_status_heartbeat and mod_http_host_status_check
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2 local time = require "socket".gettime; |
5fcf9d558250
Three new modules: mod_host_status_check, mod_host_status_heartbeat and mod_http_host_status_check
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 |
5fcf9d558250
Three new modules: mod_host_status_check, mod_host_status_heartbeat and mod_http_host_status_check
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
4 local heartbeat_interval = module:get_option_number("status_check_heartbeat_interval", 5); |
5fcf9d558250
Three new modules: mod_host_status_check, mod_host_status_heartbeat and mod_http_host_status_check
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
5 local heartbeat_mode = module:get_option_string("status_check_heartbeat_mode", "remote"); |
5fcf9d558250
Three new modules: mod_host_status_check, mod_host_status_heartbeat and mod_http_host_status_check
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 |
5fcf9d558250
Three new modules: mod_host_status_check, mod_host_status_heartbeat and mod_http_host_status_check
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
7 local local_heartbeats = module:shared("/*/host_status_check/heartbeats"); |
5fcf9d558250
Three new modules: mod_host_status_check, mod_host_status_heartbeat and mod_http_host_status_check
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 |
5fcf9d558250
Three new modules: mod_host_status_check, mod_host_status_heartbeat and mod_http_host_status_check
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 local heartbeat_methods = { |
5fcf9d558250
Three new modules: mod_host_status_check, mod_host_status_heartbeat and mod_http_host_status_check
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 ["local"] = function() |
5fcf9d558250
Three new modules: mod_host_status_check, mod_host_status_heartbeat and mod_http_host_status_check
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 module:log("debug", "Local heartbeat"); |
5fcf9d558250
Three new modules: mod_host_status_check, mod_host_status_heartbeat and mod_http_host_status_check
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 local_heartbeats[module.host] = time(); |
5fcf9d558250
Three new modules: mod_host_status_check, mod_host_status_heartbeat and mod_http_host_status_check
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
13 return heartbeat_interval; |
5fcf9d558250
Three new modules: mod_host_status_check, mod_host_status_heartbeat and mod_http_host_status_check
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 end; |
5fcf9d558250
Three new modules: mod_host_status_check, mod_host_status_heartbeat and mod_http_host_status_check
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 |
5fcf9d558250
Three new modules: mod_host_status_check, mod_host_status_heartbeat and mod_http_host_status_check
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 ["remote"] = function () |
5fcf9d558250
Three new modules: mod_host_status_check, mod_host_status_heartbeat and mod_http_host_status_check
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 module:fire_event("route/remote", { |
5fcf9d558250
Three new modules: mod_host_status_check, mod_host_status_heartbeat and mod_http_host_status_check
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 origin = prosody.hosts[module.host]; |
5fcf9d558250
Three new modules: mod_host_status_check, mod_host_status_heartbeat and mod_http_host_status_check
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 stanza = st.stanza("heartbeat", { xmlns = "xmpp:prosody.im/heartbeat" }); |
5fcf9d558250
Three new modules: mod_host_status_check, mod_host_status_heartbeat and mod_http_host_status_check
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 }); |
5fcf9d558250
Three new modules: mod_host_status_check, mod_host_status_heartbeat and mod_http_host_status_check
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 return heartbeat_interval; |
5fcf9d558250
Three new modules: mod_host_status_check, mod_host_status_heartbeat and mod_http_host_status_check
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
22 end; |
5fcf9d558250
Three new modules: mod_host_status_check, mod_host_status_heartbeat and mod_http_host_status_check
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
23 } |
5fcf9d558250
Three new modules: mod_host_status_check, mod_host_status_heartbeat and mod_http_host_status_check
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
24 |
5fcf9d558250
Three new modules: mod_host_status_check, mod_host_status_heartbeat and mod_http_host_status_check
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
25 local send_heartbeat = assert(heartbeat_methods[heartbeat_mode], "Unknown heartbeat_mode: "..heartbeat_mode); |
5fcf9d558250
Three new modules: mod_host_status_check, mod_host_status_heartbeat and mod_http_host_status_check
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
26 |
5fcf9d558250
Three new modules: mod_host_status_check, mod_host_status_heartbeat and mod_http_host_status_check
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
27 module:add_timer(0, send_heartbeat); |