aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2018-02-15 14:00:56 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2018-02-15 14:00:56 +0000
commitc4a37ba40e2ee0b55df25fbd5e3b8b910f145168 (patch)
tree7c74e82bda7d6ff33f362a88748eef4336fbb76e
parent5c62e098291dea3ce7412ad985c4b94e54f75073 (diff)
downloadrspamd-c4a37ba40e2ee0b55df25fbd5e3b8b910f145168.tar.gz
rspamd-c4a37ba40e2ee0b55df25fbd5e3b8b910f145168.zip
[Rework] Continue stat_convert rework task
-rw-r--r--lualib/rspamadm/stat_convert.lua103
-rw-r--r--lualib/stat_tools.lua23
2 files changed, 26 insertions, 100 deletions
diff --git a/lualib/rspamadm/stat_convert.lua b/lualib/rspamadm/stat_convert.lua
index d497333a1..3845702da 100644
--- a/lualib/rspamadm/stat_convert.lua
+++ b/lualib/rspamadm/stat_convert.lua
@@ -1,104 +1,7 @@
-local sqlite3 = require "rspamd_sqlite3"
-local redis = require "rspamd_redis"
-local util = require "rspamd_util"
+local lua_redis = require "rspamd_redis"
+local stat_tools = require "stat_tools"
-local function send_redis(server, symbol, tokens, password, db, cmd)
- local ret = true
- local conn,err = redis.connect_sync({
- host = server,
- })
-
- local err_str
-
- if not conn then
- print('Cannot connect to ' .. server .. ' error: ' .. err)
- return false, err
- end
-
- if password then
- conn:add_cmd('AUTH', {password})
- end
- if db then
- conn:add_cmd('SELECT', {db})
- end
-
- for _,t in ipairs(tokens) do
- if not conn:add_cmd(cmd, {symbol .. t[3], t[1], t[2]}) then
- ret = false
- err_str = 'add command failure' .. string.format('%s %s',
- cmd, table.concat({symbol .. t[3], t[1], t[2]}, ' '))
- end
- end
-
- if ret then
- ret,err_str = conn:exec()
- end
-
- return ret,err_str
-end
-
-local function convert_learned(cache, server, password, redis_db)
- local converted = 0
- local db = sqlite3.open(cache)
- local ret = true
- local err_str
-
- if not db then
- print('Cannot open cache database: ' .. cache)
- return false
- end
-
- db:sql('BEGIN;')
-
- local conn,err = redis.connect_sync({
- host = server,
- })
-
- if not conn then
- print('Cannot connect to ' .. server .. ' error: ' .. err)
- return false
- end
-
- if password then
- conn:add_cmd('AUTH', {password})
- end
- if redis_db then
- conn:add_cmd('SELECT', {redis_db})
- end
-
- for row in db:rows('SELECT * FROM learns;') do
- local is_spam
- local digest = tostring(util.encode_base32(row.digest))
-
- if row.flag == '0' then
- is_spam = '-1'
- else
- is_spam = '1'
- end
-
- if not conn:add_cmd('HSET', {'learned_ids', digest, is_spam}) then
- print('Cannot add hash: ' .. digest)
- ret = false
- else
- converted = converted + 1
- end
- end
- db:sql('COMMIT;')
-
- if ret then
- ret,err_str = conn:exec()
- end
-
- if ret then
- print(string.format('Converted %d cached items from sqlite3 learned cache to redis',
- converted))
- else
- print('Error occurred during sending data to redis: ' .. err_str)
- end
-
- return ret
-end
return function (_, res)
-
+ local redis_params =
end
diff --git a/lualib/stat_tools.lua b/lualib/stat_tools.lua
index 049de44f4..8f668870b 100644
--- a/lualib/stat_tools.lua
+++ b/lualib/stat_tools.lua
@@ -461,4 +461,27 @@ end
exports.load_sqlite_config = load_sqlite_config
+-- A helper method that suggests a user how to configure Redis based
+-- classifier based on the existing sqlite classifier
+local function redis_classifier_from_sqlite(sqlite_classifier)
+ local result = {
+ backend = 'redis',
+ cache = {
+ backend = 'redis'
+ },
+ statfile = {
+ [sqlite_classifier.symbol_spam] = {
+ spam = true
+ },
+ [sqlite_classifier.symbol_ham] = {
+ spam = false
+ }
+ }
+ }
+
+ return {classifier = {bayes = result}}
+end
+
+exports.redis_classifier_from_sqlite = redis_classifier_from_sqlite
+
return exports