# HG changeset patch # User Kim Alvefur # Date 1696603797 -7200 # Node ID 9bcd257dea4e68fb416c6c65ce8041495d20cc5f # Parent e5ad3f1f48bd9d1a49e784ae5358d4a82d55f93d mod_http_health: Provide a health check HTTP endpoint Someone in the chat asked about a health check endpoint, which reminded me of mod_http_status, which was simplified to produce this module. diff -r e5ad3f1f48bd -r 9bcd257dea4e mod_http_health/README.md --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mod_http_health/README.md Fri Oct 06 16:49:57 2023 +0200 @@ -0,0 +1,23 @@ +Simple module adding an endpoint meant to be used for health checks. + +# Configuration + +After installing, enable by adding to [`modules_enabled`][doc:modules_enabled] like many other modules: + +``` lua +-- in the global section +modules_enabled = { + -- Other globally enabled modules here... + "http_health"; -- add +} +``` + +# Details + +Adds a `http://your.prosody.example:5280/health` endpoint that returns either HTTP status code 200 when all appears to be good or 500 when any module +[status][doc:developers:moduleapi#logging-and-status] has been set to `error`. + +# See also + +- [mod_measure_modules] provides module statues via OpenMetrics +- [mod_http_status] provides all module status details as JSON via HTTP diff -r e5ad3f1f48bd -r 9bcd257dea4e mod_http_health/mod_http_health.lua --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mod_http_health/mod_http_health.lua Fri Oct 06 16:49:57 2023 +0200 @@ -0,0 +1,21 @@ +module:set_global(); + + +local modulemanager = require "core.modulemanager"; + +module:provides("http", { + route = { + GET = function() + for host in pairs(prosody.hosts) do + local mods = modulemanager.get_modules(host); + for _, mod in pairs(mods) do + if mod.module.status_type == "error" then + return { status_code = 500; headers = { content_type = "text/plain" }; body = "HAS ERRORS\n" }; + end + end + end + + return { status_code = 200; headers = { content_type = "text/plain" }; body = "OK\n" }; + end; + }; +});