commit 460a824: [Minor] Allow to log configuration errors from plugins
Vsevolod Stakhov
vsevolod at rspamd.com
Mon Aug 7 11:21:03 UTC 2023
Author: Vsevolod Stakhov
Date: 2023-08-07 12:19:03 +0100
URL: https://github.com/rspamd/rspamd/commit/460a82484915f5fcbf34f65194c3437fa2a4e0c7
[Minor] Allow to log configuration errors from plugins
---
lualib/lua_util.lua | 20 ++++++++++++++++++++
src/plugins/lua/antivirus.lua | 1 +
src/plugins/lua/bimi.lua | 4 +++-
src/plugins/lua/reputation.lua | 5 ++++-
4 files changed, 28 insertions(+), 2 deletions(-)
diff --git a/lualib/lua_util.lua b/lualib/lua_util.lua
index 16d009619..800d9fcb7 100644
--- a/lualib/lua_util.lua
+++ b/lualib/lua_util.lua
@@ -407,6 +407,26 @@ end
exports.disable_module = disable_module
+--[[[
+-- @function lua_util.push_config_error(module, err)
+-- Pushes a configuration error to the state
+-- @param {string} module name of module
+-- @param {string} err error string
+--]]
+local function push_config_error(module, err)
+ if not rspamd_plugins_state.config_errors then
+ rspamd_plugins_state.config_errors = {}
+ end
+
+ if not rspamd_plugins_state.config_errors[module] then
+ rspamd_plugins_state.config_errors[module] = {}
+ end
+
+ table.insert(rspamd_plugins_state.config_errors[module], err)
+end
+
+exports.push_config_error = push_config_error
+
--[[[
-- @function lua_util.disable_module(modname)
-- Checks experimental plugins state and disable if needed
diff --git a/src/plugins/lua/antivirus.lua b/src/plugins/lua/antivirus.lua
index 26b8509b8..44fe10e98 100644
--- a/src/plugins/lua/antivirus.lua
+++ b/src/plugins/lua/antivirus.lua
@@ -204,6 +204,7 @@ if opts and type(opts) == 'table' then
if not cb then
rspamd_logger.errx(rspamd_config, 'cannot add rule: "' .. k .. '"')
+ lua_util.push_config_error(N, 'cannot add AV rule: "' .. k .. '"')
else
rspamd_logger.infox(rspamd_config, 'added antivirus engine %s -> %s', k, m.symbol)
local t = {
diff --git a/src/plugins/lua/bimi.lua b/src/plugins/lua/bimi.lua
index e3f555e48..5959f59e7 100644
--- a/src/plugins/lua/bimi.lua
+++ b/src/plugins/lua/bimi.lua
@@ -353,7 +353,9 @@ local res, err = settings_schema:transform(settings)
if not res then
rspamd_logger.warnx(rspamd_config, 'plugin is misconfigured: %s', err)
- lua_util.disable_module(N, "config")
+ local err_msg = string.format("schema error: %s", res)
+ lua_util.push_config_error(N, err_msg)
+ lua_util.disable_module(N, "failed", err_msg)
return
end
diff --git a/src/plugins/lua/reputation.lua b/src/plugins/lua/reputation.lua
index 2fc1c3ad5..d569e9070 100644
--- a/src/plugins/lua/reputation.lua
+++ b/src/plugins/lua/reputation.lua
@@ -1377,8 +1377,11 @@ if opts['rules'] then
for k, v in pairs(opts['rules']) do
if not ((v or E).selector) then
rspamd_logger.errx(rspamd_config, "no selector defined for rule %s", k)
+ lua_util.push_config_error(N, "no selector defined for rule: " .. k)
else
- parse_rule(k, v)
+ if not parse_rule(k, v) then
+ lua_util.push_config_error(N, "reputation rule is misconfigured: " .. k)
+ end
end
end
else
More information about the Commits
mailing list