Mercurial > prosody-modules
comparison mod_http_status/mod_http_status.lua @ 5161:6af2d74daa15
mod_http_status: Report module statuses
Uncommitted code from 2021
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Mon, 30 Jan 2023 00:48:12 +0100 |
| parents | |
| children | e274431bf4ce |
comparison
equal
deleted
inserted
replaced
| 5160:8474a3b80200 | 5161:6af2d74daa15 |
|---|---|
| 1 module:set_global(); | |
| 2 | |
| 3 local json = require "util.json"; | |
| 4 local datetime = require "util.datetime".datetime; | |
| 5 | |
| 6 local modulemanager = require "core.modulemanager"; | |
| 7 | |
| 8 module:provides("http", { | |
| 9 route = { | |
| 10 GET = function(event) | |
| 11 local request, response = event.request, event.response; | |
| 12 response.headers.content_type = "application/json"; | |
| 13 | |
| 14 local resp = { ["*"] = true }; | |
| 15 | |
| 16 for host in pairs(prosody.hosts) do | |
| 17 resp[host] = true; | |
| 18 end | |
| 19 | |
| 20 for host in pairs(resp) do | |
| 21 local hostmods = {}; | |
| 22 local mods = modulemanager.get_modules(host); | |
| 23 for mod_name, mod in pairs(mods) do | |
| 24 hostmods[mod_name] = { | |
| 25 type = mod.module.status_type; | |
| 26 message = mod.module.status_message; | |
| 27 time = datetime(math.floor(mod.module.status_time)); | |
| 28 }; | |
| 29 end | |
| 30 resp[host] = hostmods; | |
| 31 end | |
| 32 | |
| 33 return json.encode(resp); | |
| 34 end; | |
| 35 }; | |
| 36 }); |
