Software /
code /
prosody-modules
Changeset
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 | 5160:8474a3b80200 |
children | 5162:243c156074d3 |
files | mod_http_status/README.md mod_http_status/mod_http_status.lua |
diffstat | 2 files changed, 51 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mod_http_status/README.md Mon Jan 30 00:48:12 2023 +0100 @@ -0,0 +1,15 @@ +Prosody 0.12 added an API allowing modules to report their status. This +module allows reading these statuses via HTTP for use in monitoring. + +``` +$ curl http://prosody.localhost:5280/status +{ + "example.com" : { + "c2s" : { + "message" : "Loaded", + "type" : "core" + } + } +} +``` +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mod_http_status/mod_http_status.lua Mon Jan 30 00:48:12 2023 +0100 @@ -0,0 +1,36 @@ +module:set_global(); + +local json = require "util.json"; +local datetime = require "util.datetime".datetime; + +local modulemanager = require "core.modulemanager"; + +module:provides("http", { + route = { + GET = function(event) + local request, response = event.request, event.response; + response.headers.content_type = "application/json"; + + local resp = { ["*"] = true }; + + for host in pairs(prosody.hosts) do + resp[host] = true; + end + + for host in pairs(resp) do + local hostmods = {}; + local mods = modulemanager.get_modules(host); + for mod_name, mod in pairs(mods) do + hostmods[mod_name] = { + type = mod.module.status_type; + message = mod.module.status_message; + time = datetime(math.floor(mod.module.status_time)); + }; + end + resp[host] = hostmods; + end + + return json.encode(resp); + end; + }; +});