Mercurial > prosody-modules
comparison mod_discodot/mod_discodot.tl @ 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:string, conf:{string:any}) : string | |
4 if host == "*" then | |
5 return "Global"; | |
6 end | |
7 local component_module = conf["component_module"]; | |
8 if component_module is 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 : { string }) : integer | |
20 | |
21 local config : { string : { string : any } } = 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 disco_items is { { string, string } } 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 |