commit b1182d6: [Minor] Log SMTP HELO/.EHLO to ClickHouse

Anton Yuzhaninov citrin+github at citrin.ru
Thu Jun 27 16:14:03 UTC 2019


Author: Anton Yuzhaninov
Date: 2019-06-26 17:02:45 +0100
URL: https://github.com/rspamd/rspamd/commit/b1182d67944ad8b9165c688d7b6998bfb50485ca

[Minor] Log SMTP HELO/.EHLO to ClickHouse

---
 src/plugins/lua/clickhouse.lua | 23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)

diff --git a/src/plugins/lua/clickhouse.lua b/src/plugins/lua/clickhouse.lua
index f62bda2c6..b4c5d5567 100644
--- a/src/plugins/lua/clickhouse.lua
+++ b/src/plugins/lua/clickhouse.lua
@@ -95,6 +95,7 @@ CREATE TABLE rspamd
     From String COMMENT 'Domain part of the return address (RFC5321.MailFrom)',
     MimeFrom String COMMENT 'Domain part of the address in From: header (RFC5322.From)',
     IP String COMMENT 'SMTP client IP as provided by MTA or from Received: header',
+    Helo String COMMENT 'Full hostname as sent by the SMTP client (RFC5321.HELO/.EHLO)',
     Score Float32 COMMENT 'Message score',
     NRcpt UInt8 COMMENT 'Number of envelope recipients (RFC5321.RcptTo)',
     Size UInt32 COMMENT 'Message size in bytes',
@@ -210,6 +211,14 @@ local migrations = {
     -- New version
     [[INSERT INTO rspamd_version (Version) Values (6)]],
   },
+  [6] = {
+    -- Add new columns
+    [[ALTER TABLE rspamd
+      ADD COLUMN Helo String AFTER IP
+    ]],
+    -- New version
+    [[INSERT INTO rspamd_version (Version) Values (7)]],
+  },
 }
 
 local predefined_actions = {
@@ -228,6 +237,7 @@ local function clickhouse_main_row(res)
     'From',
     'MimeFrom',
     'IP',
+    'Helo',
     'Score',
     'NRcpt',
     'Size',
@@ -429,16 +439,6 @@ local function clickhouse_collect(task)
       from_domain = from['domain']:lower()
       from_user = from['user']
     end
-
-    if from_domain == '' then
-      if task:get_helo() then
-        from_domain = task:get_helo()
-      end
-    end
-  else
-    if task:get_helo() then
-      from_domain = task:get_helo()
-    end
   end
 
   local mime_domain = ''
@@ -471,6 +471,8 @@ local function clickhouse_collect(task)
     ip_str = ipnet:to_string()
   end
 
+  local helo = task:get_helo() or ''
+
   local rcpt_user = ''
   local rcpt_domain = ''
   if task:has_recipients('smtp') then
@@ -637,6 +639,7 @@ local function clickhouse_collect(task)
     from_domain,
     mime_domain,
     ip_str,
+    helo,
     score,
     nrcpts,
     task:get_size(),


More information about the Commits mailing list