]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Deal with ungrouped symbols
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Sun, 5 Nov 2017 12:39:58 +0000 (12:39 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Sun, 5 Nov 2017 12:39:58 +0000 (12:39 +0000)
lualib/rspamd_config_transform.lua

index 8b7027d37df6678d2261e8073c00aa1fe8307644..750862a8cdfda7249f8d6cb849e19f1ee1ebd59c 100644 (file)
@@ -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