Debian Codegraph @

lualib/plugins_stats.lua

raw
1 --[[
2 Copyright (c) 2022, Vsevolod Stakhov <[email protected]>
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15 ]]--
16
17 local ansicolors = require "ansicolors"
18
19 local function printf(fmt, ...)
20 print(string.format(fmt, ...))
21 end
22
23 local function highlight(str)
24 return ansicolors.white .. str .. ansicolors.reset
25 end
26
27 local function print_plugins_table(tbl, what)
28 local mods = {}
29 for k, _ in pairs(tbl) do
30 table.insert(mods, k)
31 end
32
33 printf("Modules %s: %s", highlight(what), table.concat(mods, ", "))
34 end
35
36 return function(args, _)
37 print_plugins_table(rspamd_plugins_state.enabled, "enabled")
38 print_plugins_table(rspamd_plugins_state.disabled_explicitly,
39 "disabled (explicitly)")
40 print_plugins_table(rspamd_plugins_state.disabled_unconfigured,
41 "disabled (unconfigured)")
42 print_plugins_table(rspamd_plugins_state.disabled_redis,
43 "disabled (no Redis)")
44 print_plugins_table(rspamd_plugins_state.disabled_experimental,
45 "disabled (experimental)")
46 print_plugins_table(rspamd_plugins_state.disabled_failed,
47 "disabled (failed)")
48 end