From dd28b2b6d81bdba77f78d9b4ebd230901b3c96d3 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Sun, 5 Nov 2017 12:39:58 +0000 Subject: [Minor] Deal with ungrouped symbols --- lualib/rspamd_config_transform.lua | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/lualib/rspamd_config_transform.lua b/lualib/rspamd_config_transform.lua index 8b7027d37..750862a8c 100644 --- a/lualib/rspamd_config_transform.lua +++ b/lualib/rspamd_config_transform.lua @@ -118,6 +118,28 @@ local function group_transform(cfg, k, v) logger.warnx("overriding group %s from the legacy metric settings", k) end +local function symbol_transform(cfg, k, v) + -- first try to find any group where there is a definition of this symbol + for gr_n, gr in pairs(cfg.group) do + if gr.symbols and gr.symbols[k] then + -- We override group symbol with ungrouped symbol + logger.warnx("overriding group symbol %s in the group %s", k, gr_n) + gr.symbols[k] = override_defaults(gr.symbols[k], v) + return + end + end + + -- Otherwise we just use group 'ungrouped' + if not cfg.group.ungrouped then + cfg.group.ungrouped = { + symbols = {} + } + end + + cfg.group.ungrouped.symbols[k] = v + logger.warnx("adding symbol %s to the group 'ungrouped'", k) +end + local function convert_metric(cfg, metric) if type(metric[1]) == 'table' then logger.warnx("multiple metrics have never been supported") @@ -142,6 +164,12 @@ local function convert_metric(cfg, metric) end end + if metric.symbol then + for k, v in metric_pairs(metric.symbol) do + symbol_transform(cfg, k, v) + end + end + return true, cfg end -- cgit v1.2.3