Mercurial > prosody-modules
annotate mod_host_status_heartbeat/mod_host_status_heartbeat.lua @ 5243:d5dc8edb2695
mod_http_oauth2: Use more compact IDs
UUIDs are nice but so verbose!
The reduction in entropy for the nonce should be fine since the
timestamp is also counts towards this, and it changes every second
(modulo clock shenanigans), so the chances of someone managing to get
the same client_secret by registering with the same information at the
same time as another entity should be negligible.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sat, 11 Mar 2023 22:46:27 +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); |