diff options
author | Vsevolod Stakhov <vsevolod@rspamd.com> | 2024-11-06 13:53:35 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rspamd.com> | 2024-11-06 13:53:35 +0000 |
commit | 1dd3a94674f06f0cd85cd6f698ddcee95b7c7330 (patch) | |
tree | e78ed3412f118c0e278f7bd7bbc726f296f59a33 /conf/lua.local.d/module.lua.example | |
parent | 2fa3f26efff008ba65d8f32f5f41e71181d0bd59 (diff) | |
download | rspamd-1dd3a94674f06f0cd85cd6f698ddcee95b7c7330.tar.gz rspamd-1dd3a94674f06f0cd85cd6f698ddcee95b7c7330.zip |
[Conf] Add lua.local.d folder
Diffstat (limited to 'conf/lua.local.d/module.lua.example')
-rw-r--r-- | conf/lua.local.d/module.lua.example | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/conf/lua.local.d/module.lua.example b/conf/lua.local.d/module.lua.example new file mode 100644 index 000000000..336db6c49 --- /dev/null +++ b/conf/lua.local.d/module.lua.example @@ -0,0 +1,62 @@ +-- This directory is used to define user specific rules and plugins for Rspamd in Lua +-- Each *.lua file is executed and added to the Rspamd + +-- Example of regexp rule: + +local reconf = config['regexp'] -- Create alias for regexp configs + +local re1 = 'From=/foo@/H' -- Mind local here +local re2 = '/blah/P' + +reconf['SYMBOL'] = { + re = string.format('(%s) && !(%s)', re1, re2), -- use string.format to create expression + score = 1.2, + description = 'some description', + + condition = function(task) + -- run this rule only if some condition is satisfied + return true + end, +} + +-- Example of a simple lua rule: +rspamd_config.SYMBOL = { + callback = function(task) + return true + end, + score = 1.2, + description = 'some description', + + condition = function(task) + -- run this rule only if some condition is satisfied + return true + end, +} + +-- Example of a plugin with configuration: +local redis_params +local lua_redis = require "lua_redis" + +local function symbol_cb(task) + local function redis_set_cb(err) + if err ~= nil then + rspamd_logger.errx(task, 'redis_set_cb received error: %1', err) + end + end + -- Create hash of message-id and store to redis + local key = make_key(task) + local ret = lua_redis.redis_make_request(task, + redis_params, -- connect params + key, -- hash key + true, -- is write + redis_set_cb, --callback + 'SETEX', -- command + { key, tostring(settings['expire']), "1" } -- arguments + ) +end + +-- Load redis server for module named 'module' +redis_params = lua_redis.parse_redis_server('module') +if redis_params then + -- Register symbol +end |