Mercurial > prosody-modules
annotate mod_host_status_heartbeat/mod_host_status_heartbeat.lua @ 4530:33c149d0261d
mod_rest: Add mappings for a whole pile of XEPs
Look ma, programming in JSON!
XEP-0012: Last Activity
XEP-0077: In-Band Registration
XEP-0115: Entity Capabilities
XEP-0153: vCard-Based Avatars
XEP-0297: Stanza Forwarding
XEP-0308: Last Message Correction
XEP-0319: Last User Interaction in Presence
XEP-0333: Chat Markers
XEP-0367: Message Attaching
XEP-0372: References
XEP-0421: Anonymous unique occupant identifiers for MUCs
XEP-0428: Fallback Indication
XEP-0444: Message Reactions
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Tue, 23 Mar 2021 23:18:33 +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); |