Mercurial > prosody-modules
comparison mod_discodot/mod_discodot.lua @ 4577:253df0798996
mod_discodot: Print a graph of service discovery
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Thu, 27 May 2021 17:23:43 +0200 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 4576:cade5dac1003 | 4577:253df0798996 |
|---|---|
| 1 local cm = require("core.configmanager"); | |
| 2 | |
| 3 local function format_host(host, conf) | |
| 4 if host == "*" then | |
| 5 return "Global" | |
| 6 end | |
| 7 local component_module = conf["component_module"]; | |
| 8 if type(component_module) == "string" then | |
| 9 if component_module == "component" then | |
| 10 return string.format("Component %q", host) | |
| 11 else | |
| 12 return string.format("Component %q %q", host, component_module) | |
| 13 end | |
| 14 else | |
| 15 return string.format("VirtualHost %q", host) | |
| 16 end | |
| 17 end | |
| 18 | |
| 19 function module.command(arg) | |
| 20 | |
| 21 local config = cm.getconfig(); | |
| 22 | |
| 23 print("digraph \"prosody\" {") | |
| 24 for host, conf in pairs(config) do | |
| 25 print(string.format("%q [label=%q]", host, format_host(host, conf))); | |
| 26 local parent = host:match("%.(.*)"); | |
| 27 if parent and rawget(config, parent) then | |
| 28 print(string.format("%q -> %q", parent, host)); | |
| 29 end | |
| 30 local disco_items = conf["disco_items"] | |
| 31 if type(disco_items) == "table" then | |
| 32 for _, pair in ipairs(disco_items) do | |
| 33 print(string.format("%q -> %q", host, pair[1])); | |
| 34 end | |
| 35 end | |
| 36 | |
| 37 end | |
| 38 | |
| 39 print("}") | |
| 40 | |
| 41 return 0 | |
| 42 end |
