rspamd_config
This module is used to configure rspamd and is normally available as global
variable named rspamd_config
. Unlike other modules, it is not necessary to
require it before usage.
Methods:
Method | Description |
---|---|
rspamd_config:get_module_opt(mname, optname) |
Returns value of specified option optname for a module mname ,. |
rspamd_config:get_all_opt(mname) |
Returns value of all options for a module mname , flattening values into a single table consisting. |
rspamd_config:get_ucl() |
Returns full configuration as a native Lua object (ucl to lua conversion). |
rspamd_config:get_mempool() |
Returns static configuration memory pool. |
rspamd_config:get_resolver() |
Returns DNS resolver. |
rspamd_config:add_radix_map(mapline[, description]) |
Creates new dynamic map of IP/mask addresses. |
rspamd_config:radix_from_config(mname, optname) |
Creates new embedded map of IP/mask addresses from config. |
rspamd_config:radix_from_ucl(obj) |
Creates new embedded map of IP/mask addresses from object. |
rspamd_config:add_hash_map(mapline[, description]) |
Creates new dynamic map string objects. |
rspamd_config:add_kv_map(mapline[, description]) |
Creates new dynamic map of key/values associations. |
rspamd_config:add_map({args}) |
Creates new dynamic map according to the attributes passed. |
rspamd_config:get_maps() |
Get all maps defined as an array of rspamd{map} objects. |
rspamd_config:get_classifier(name) |
Returns classifier config. |
rspamd_config:register_symbol(table) |
Register symbol of a specified type in rspamd. |
rspamd_config:register_symbols(callback, [weight], callback_name, [, symbol, ...]) |
Register callback function to be called for a set of symbols with initial weight. |
rspamd_config:register_virtual_symbol(name, weight,) |
Register virtual symbol that is not associated with any callback. |
rspamd_config:register_callback_symbol(name, weight, callback) |
Register callback function to be called for a specified symbol with initial weight. |
rspamd_config:register_dependency(id|name, depname) |
Create a dependency on symbol identified by name for symbol identified by ID or name. |
rspamd_config:get_symbol_flags(name) |
Returns symbol flags. |
rspamd_config:add_symbol_flags(name, flags) |
Adds flags to a symbol. |
rspamd_config:register_pre_filter(callback[, order]) |
Register function to be called prior to symbols processing. |
rspamd_config:register_post_filter(callback[, order]) |
Register function to be called after symbols are processed. |
rspamd_config:get_key(name) |
Returns configuration section with the specified name . |
rspamd_config:add_condition(symbol, condition) |
Adds condition callback for specified symbol. |
rspamd_config:enable_symbol(symbol) |
Enables execution for the specified symbol. |
rspamd_config:disable_symbol(symbol, [disable_parent=true]) |
Disables execution for the specified symbol. |
rspamd_config:get_symbol_parent(symbol) |
Returns a parent symbol for specific symbol (or symbol itself if top level). |
rspamd_config:get_group_symbols(group) |
Returns list of symbols for a specific group. |
rspamd_config:get_groups([need_private]) |
Returns list of all groups defined. |
rspamd_config:register_settings_id(name, symbols_enabled, symbols_disabled) |
Register new static settings id in config. |
rspamd_config:__newindex(name, callback) |
This metamethod is called if new indices are added to the rspamd_config object. |
rspamd_config:register_regexp(params) |
Registers new re for further cached usage. |
rspamd_config:replace_regexp(params) |
Replaces regexp with a new one. |
rspamd_config:register_worker_script(worker_type, script) |
Registers the following script for workers of a specified type. |
rspamd_config:add_on_load(function(cfg, ev_base, worker) ... end) |
Registers the following script to be executed when configuration is completely loaded. |
rspamd_config:add_periodic(event_base, timeout, function(cfg, ev_base) ... end, [jitter = false]) |
Registers function to be periodically executed by Rspamd. |
rspamd_config:add_post_init(function(cfg) ... end) |
Registers the following script to be executed when configuration is completely loaded. |
rspamd_config:add_config_unload(function(cfg) ... end) |
Registers the following script to be executed when configuration is unloaded. |
rspamd_config:get_symbols_count() |
Returns number of symbols registered in rspamd configuration. |
rspamd_config:get_symbols_cksum() |
Returns checksum for all symbols in the cache. |
rspamd_config:get_symbols_counters() |
Returns table of all counters in the cache (weights, frequencies etc). |
rspamd_config:get_symbols() |
Returns table of all scores defined in config. |
rspamd_config:get_symbol(sym_name) |
Returns table for a specific symbol getting data from the static config. |
rspamd_config:get_symbol_callback(name) |
Returns callback function for the specified symbol if it is a lua registered callback. |
rspamd_config:get_symbol_stat(name) |
Returns table with statistics for a specific symbol. |
rspamd_config:set_symbol_callback(name, callback) |
Sets callback for the specified symbol. |
rspamd_config:register_finish_script(callback) |
Adds new callback that is called on worker process termination when all. |
rspamd_config:register_monitored(url, type, [{params}]) |
Registers monitored resource to watch its availability. |
rspamd_config:add_doc(path, option, doc_string, [{params}]) |
Adds new documentation string for an option option at path path . |
rspamd_config:add_example(path, option, doc_string, example) |
Adds new documentation. |
rspamd_config:set_peak_cb(function) |
Sets a function that will be called when frequency of some symbol goes out of. |
rspamd_config:get_cpu_flags() |
Returns architecture dependent flags supported by the CPU. |
rspamd_config:has_torch() |
Returns true if Rspamd is compiled with torch support and the runtime CPU. |
rspamd_config:is_mime_utf8() |
Returns true if Rspamd is configured to use UTF for mime processing. |
rspamd_config:experimental_enabled() |
Returns true if experimental plugins are enabled. |
rspamd_config:load_ucl(filename[, include_trace]) |
Loads config from the UCL file (but does not perform parsing using rcl). |
rspamd_config:parse_rcl([skip_sections]) |
Parses RCL using loaded ucl file. |
rspamd_config:init_modules() |
Initialize lua and internal modules. |
rspamd_config:init_subsystem(str) |
Initialize config subsystem from a comma separated list. |
rspamd_config:get_tld_path() |
Returns path to TLD file. |
rspamd_config:get_dns_max_requests() |
Returns limit of DNS requests per task. |
rspamd_config:get_dns_timeout() |
Returns timeout for a DNS request. |
The module rspamd_config
defines the following methods.
rspamd_config:get_module_opt(mname, optname)
Returns value of specified option optname
for a module mname
,
Parameters:
mname {string}
: name of moduleoptname {string}
: option to getReturns:
{string or table}
: value of the option or nil
if option is not foundBack to module description.
rspamd_config:get_all_opt(mname)
Returns value of all options for a module mname
, flattening values into a single table consisting
of all sections with such a name.
Parameters:
mname {string}
: name of moduleReturns:
{table}
: table of all options for mname
or nil
if a module’s configuration is not foundBack to module description.
rspamd_config:get_ucl()
Returns full configuration as a native Lua object (ucl to lua conversion). This method uses caching if possible.
Parameters:
No parameters
Returns:
{table}
: table of all options in the configurationBack to module description.
rspamd_config:get_mempool()
Returns static configuration memory pool.
Parameters:
No parameters
Returns:
{mempool}
: memory pool objectBack to module description.
rspamd_config:get_resolver()
Returns DNS resolver.
Parameters:
No parameters
Returns:
{dns_resolver}
: opaque DNS resolver pointer if anyBack to module description.
rspamd_config:add_radix_map(mapline[, description])
Creates new dynamic map of IP/mask addresses.
Parameters:
mapline {string}
: URL for a mapdescription {string}
: optional map descriptionReturns:
{map}
: radix tree objectBack to module description.
rspamd_config:radix_from_config(mname, optname)
Creates new embedded map of IP/mask addresses from config.
Parameters:
mname {string}
: name of moduleoptname {string}
: option to getReturns:
{map}
: radix tree objectBack to module description.
rspamd_config:radix_from_ucl(obj)
Creates new embedded map of IP/mask addresses from object.
Parameters:
obj {ucl}
: objectReturns:
{map}
: radix tree objectBack to module description.
rspamd_config:add_hash_map(mapline[, description])
Creates new dynamic map string objects.
Parameters:
mapline {string}
: URL for a mapdescription {string}
: optional map descriptionReturns:
{map}
: hash set objectBack to module description.
rspamd_config:add_kv_map(mapline[, description])
Creates new dynamic map of key/values associations.
Parameters:
mapline {string}
: URL for a mapdescription {string}
: optional map descriptionReturns:
{map}
: hash table objectBack to module description.
rspamd_config:add_map({args})
Creates new dynamic map according to the attributes passed.
type
: type of map to be created, can be one of the following set:
set
: set of stringsradix
: map of IP addresses to stringsmap
: map of strings to stringsregexp
: map of regexps to stringscallback
: map processed by lua callbackurl
: url to load map fromdescription
: map’s descriptioncallback
: lua callback for the mapParameters:
No parameters
Returns:
{map}
: true
if map has been addedBack to module description.
rspamd_config:get_maps()
Get all maps defined as an array of rspamd{map} objects
Parameters:
No parameters
Returns:
{table|rspamd{map}
: }Back to module description.
rspamd_config:get_classifier(name)
Returns classifier config.
Parameters:
name {string}
: name of classifier (e.g. bayes
)Returns:
{classifier}
: classifier object or nil
Back to module description.
rspamd_config:register_symbol(table)
Register symbol of a specified type in rspamd. This function accepts table of arguments:
name
: name of symbol (can be missing for callback symbols)callback
: function to be called for symbol’s check (can be absent for virtual symbols)weight
: weight of symbol (should normally be 1 or missing)priority
: priority of symbol (normally 0 or missing)type
: type of symbol:
normal
: executed after prefilters, according to dependency graph or in undefined ordercallback
: a check that merely inserts virtual symbolsconnfilter
: executed early; before message body is availableidempotent
: cannot change result in any way; executed lastpostfilter
: executed after most other checksprefilter
: executed before most other checksvirtual
: a symbol inserted by its parent checkflags
: various flags split by commas or spaces:
nice
if symbol can produce negative score;empty
if symbol can be called for empty messagesskip
if symbol should be skipped nownostat
if symbol should be excluded from stat tokenstrivial
symbol is trivial (e.g. no network requests)explicit_disable
requires explicit disabling (e.g. via settings)ignore_passthrough
executed even if passthrough result has been setparent
: id of parent symbol (useful for virtual symbols)Parameters:
No parameters
Returns:
{number}
: id of symbol registeredBack to module description.
rspamd_config:register_symbols(callback, [weight], callback_name, [, symbol, ...])
Register callback function to be called for a set of symbols with initial weight.
Parameters:
callback {function}
: callback function to be called for a specified symbolweight {number}
: initial weight of symbol (can be less than zero to specify non-spam symbols)callback_name {string}
: symbolic name of callbacksymbol {list of strings}
: list of symbols registered by this functionReturns:
No return
Back to module description.
rspamd_config:register_virtual_symbol(name, weight,)
Register virtual symbol that is not associated with any callback.
**This method is deprecated and should not be used in newly written code **
Parameters:
virtual {string}
: name symbol’s nameweight {number}
: initial weight of symbol (can be less than zero to specify non-spam symbols)Returns:
No return
Back to module description.
rspamd_config:register_callback_symbol(name, weight, callback)
Register callback function to be called for a specified symbol with initial weight. Symbol itself is not registered in the metric and is not intended to be visible by a user.
**This method is deprecated and should not be used in newly written code **
Parameters:
name {string}
: symbol’s name (just for unique id purposes)weight {number}
: initial weight of symbol (can be less than zero to specify non-spam symbols)callback {function}
: callback function to be called for a specified symbolReturns:
No return
Back to module description.
rspamd_config:register_dependency(id|name, depname)
Create a dependency on symbol identified by name for symbol identified by ID or name. This affects order of checks only (a symbol is still checked if its dependencies are disabled).
Parameters:
id {number|string}
: id or name of source (numeric id is returned by all register_*_symbol)depname {string}
: dependency nameReturns:
No return
Back to module description.
rspamd_config:get_symbol_flags(name)
Returns symbol flags
Parameters:
name {string}
: symbols’s nameReturns:
{table|string}
: list of flags for symbol or nilBack to module description.
rspamd_config:add_symbol_flags(name, flags)
Adds flags to a symbol
Parameters:
name {string}
: symbols’s nameflags {table|string}
: flags to addReturns:
{table|string}
: new set of flagsBack to module description.
rspamd_config:register_pre_filter(callback[, order])
Register function to be called prior to symbols processing.
Parameters:
callback {function}
: callback functionorder {number}
: filters are called from lower orders to higher orders, order is equal to 0 by defaultReturns:
No return
Back to module description.
rspamd_config:register_post_filter(callback[, order])
Register function to be called after symbols are processed.
Parameters:
callback {function}
: callback functionorder {number}
: filters are called from lower orders to higher orders, order is equal to 0 by defaultReturns:
No return
Back to module description.
rspamd_config:get_key(name)
Returns configuration section with the specified name
.
Parameters:
name {string}
: name of config sectionReturns:
{variant}
: specific value of sectionBack to module description.
rspamd_config:add_condition(symbol, condition)
Adds condition callback for specified symbol
Parameters:
symbol {string}
: symbol’s namecondition {function}
: condition callbackReturns:
{boolean}
: true if condition has been addedBack to module description.
rspamd_config:enable_symbol(symbol)
Enables execution for the specified symbol
Parameters:
symbol {string}
: symbol’s nameReturns:
No return
Back to module description.
rspamd_config:disable_symbol(symbol, [disable_parent=true])
Disables execution for the specified symbol
Parameters:
symbol {string}
: symbol’s namedisable_parent {boolean}
: if true then disable parent execution in case of a virtual symbolReturns:
No return
Back to module description.
rspamd_config:get_symbol_parent(symbol)
Returns a parent symbol for specific symbol (or symbol itself if top level)
Parameters:
symbol {string}
: symbol’s nameReturns:
No return
Back to module description.
rspamd_config:get_group_symbols(group)
Returns list of symbols for a specific group
Parameters:
group {string}
: group’s nameReturns:
{list|string}
: list of all symbols in a specific groupAvailable in: 2.0+
Back to module description.
rspamd_config:get_groups([need_private])
Returns list of all groups defined
Parameters:
need_private {boolean}
: optional flag to include private groupsReturns:
{list|table}
: list of all groupsAvailable in: 2.3+
Back to module description.
rspamd_config:register_settings_id(name, symbols_enabled, symbols_disabled)
Register new static settings id in config
Parameters:
name {string}
: id name (not numeric!)symbols_enabled {map|string->string}
: map from symbol’s name to boolean (currently)symbols_disabled {map|string->string}
: map from symbol’s name to boolean (currently)Returns:
No return
Available in: 2.0+
Back to module description.
rspamd_config:__newindex(name, callback)
This metamethod is called if new indices are added to the rspamd_config
object.
Technically, it is the equivalent of rspamd_config:register_symbol
where weight
is 1.0.
There is also table form invocation that allows to control more things:
callback
: has the same meaning and acts as function of taskscore
: default score for a symbolgroup
: default group for a symboldescription
: default symbol’s descriptionpriority
: additional priority valueone_shot
: default value for one shot attributecondition
: function of task that can enable or disable this specific rule’s executionParameters:
name {string}
: index namecallback {function/table}
: callback to be calledReturns:
{number}
: id of the new symbol addedBack to module description.
rspamd_config:register_regexp(params)
Registers new re for further cached usage
Params is the table with the following fields (mandatory fields are marked with *
):
re
* : regular expression objecttype
*: type of regular expression:
mime
: mime regexprawmime
: raw mime regexpheader
: header regexprawheader
: raw header expressionbody
: raw body regexpurl
: url regexpheader
: for header and rawheader regexp means the name of headerpcre_only
: flag regexp as pcre only regexpParameters:
No parameters
Returns:
No return
Back to module description.
rspamd_config:replace_regexp(params)
Replaces regexp with a new one
Params is the table with the following fields (mandatory fields are marked with *
):
old_re
* : old regular expression object (must be in the cache)new_re
* : old regular expression object (must not be in the cache)Parameters:
No parameters
Returns:
No return
Back to module description.
rspamd_config:register_worker_script(worker_type, script)
Registers the following script for workers of a specified type. The exact type of script function depends on worker type
Parameters:
worker_type {string}
: worker type (e.g. “normal”)script {function}
: script for a workerReturns:
{boolean}
: true
if a script has been registeredBack to module description.
rspamd_config:add_on_load(function(cfg, ev_base, worker) ... end)
Registers the following script to be executed when configuration is completely loaded and the worker is already started (forked)
Parameters:
script {function}
: function to be executedReturns:
No return
Back to module description.
rspamd_config:add_periodic(event_base, timeout, function(cfg, ev_base) ... end, [jitter = false])
Registers function to be periodically executed by Rspamd
Parameters:
event_base {ev_base}
: event base that is needed for async eventstimeout {number}
: time in seconds (could be fractional)script {function}
: function to be executedjitter {boolean}
: true
if timeout jittering is neededReturns:
No return
Back to module description.
rspamd_config:add_post_init(function(cfg) ... end)
Registers the following script to be executed when configuration is completely loaded
Parameters:
script {function}
: function to be executedReturns:
No return
Available in: 2.0+
Back to module description.
rspamd_config:add_config_unload(function(cfg) ... end)
Registers the following script to be executed when configuration is unloaded
Parameters:
script {function}
: function to be executedReturns:
No return
Available in: 2.0+
Back to module description.
rspamd_config:get_symbols_count()
Returns number of symbols registered in rspamd configuration
Parameters:
No parameters
Returns:
{number}
: number of symbols registered in the configurationBack to module description.
rspamd_config:get_symbols_cksum()
Returns checksum for all symbols in the cache
Parameters:
No parameters
Returns:
{int64}
: boxed value of the 64 bit checksumBack to module description.
rspamd_config:get_symbols_counters()
Returns table of all counters in the cache (weights, frequencies etc)
Parameters:
No parameters
Returns:
{table|tables}
: all symbols indexed by nameBack to module description.
rspamd_config:get_symbols()
Returns table of all scores defined in config. From version 2.0 returns table:
ignore
or oneparam
)Parameters:
No parameters
Returns:
{table|tables}
: all symbols indexed by nameAvailable in: 2.0+
Back to module description.
rspamd_config:get_symbol(sym_name)
Returns table for a specific symbol getting data from the static config:
ignore
or oneparam
)Parameters:
No parameters
Returns:
{table}
: symbol data (or nil)Available in: 3.3+
Back to module description.
rspamd_config:get_symbol_callback(name)
Returns callback function for the specified symbol if it is a lua registered callback
Parameters:
No parameters
Returns:
{function}
: callback function or nilBack to module description.
rspamd_config:get_symbol_stat(name)
Returns table with statistics for a specific symbol:
frequency
: frequency for symbol’s hitsstddev
: standard deviation of frequency
time
: average time in seconds (floating point)count
: total number of hitsParameters:
No parameters
Returns:
{table}
: symbol statsBack to module description.
rspamd_config:set_symbol_callback(name, callback)
Sets callback for the specified symbol
Parameters:
No parameters
Returns:
{boolean}
: true if function has been replacedBack to module description.
rspamd_config:register_finish_script(callback)
Adds new callback that is called on worker process termination when all tasks pending are processed
Parameters:
callback {no type}
: {function} a function with one argument (rspamd_task)Returns:
No return
Back to module description.
rspamd_config:register_monitored(url, type, [{params}])
Registers monitored resource to watch its availability. Supported types:
dns
: DNS monitored objectParams are optional table specific for each type. For DNS it supports the following options:
prefix
: prefix to add before making requesttype
: type of request (e.g. ‘a’ or ‘txt’)ipnet
: array of ip/networks to expect on replyrcode
: expected return code (e.g. nxdomain
)Returned object has the following methods:
alive
: returns true
if monitored resource is aliveoffline
: returns number of seconds of the current offline period (or 0 if alive)total_offline
: returns number of seconds of the overall offlinelatency
: returns the current average latency in seconds (or 0 if offline)Parameters:
url {string}
: resource to monitortype {string}
: type of monitoringopts {table}
: optional parametersReturns:
{rspamd_monitored}
: rspamd monitored objectBack to module description.
rspamd_config:add_doc(path, option, doc_string, [{params}])
Adds new documentation string for an option option
at path path
Options defines optional params, such as:
default
: default option valuetype
: type of an option (string
, number
, object
, array
etc)required
: if an option is requiredParameters:
path {string}
: documentation path (e.g. module name)option {string}
: name of the optiondoc_string {string}
: documentation stringparams {table}
: optional parametersReturns:
No return
Back to module description.
rspamd_config:add_example(path, option, doc_string, example)
Adds new documentation
Parameters:
path {string}
: documentation path (e.g. module name or nil for top)option {string}
: name of the optiondoc_string {string}
: documentation stringexample {string}
: example in ucl format, comments are also parsedReturns:
No return
Back to module description.
rspamd_config:set_peak_cb(function)
Sets a function that will be called when frequency of some symbol goes out of stddev * 2 over the last period of refreshment.
Parameters:
No parameters
Returns:
No return
Back to module description.
rspamd_config:get_cpu_flags()
Returns architecture dependent flags supported by the CPU Currently, only x86 flags are supported:
Parameters:
No parameters
Returns:
{table}
: flag -> true tableBack to module description.
rspamd_config:has_torch()
Returns true if Rspamd is compiled with torch support and the runtime CPU supports sse4.2 required for torch.
Parameters:
No parameters
Returns:
{boolean}
: true if torch is compiled and supportedBack to module description.
rspamd_config:is_mime_utf8()
Returns true if Rspamd is configured to use UTF for mime processing
Parameters:
No parameters
Returns:
{boolean}
: true if mime utf is enabledBack to module description.
rspamd_config:experimental_enabled()
Returns true if experimental plugins are enabled
Parameters:
No parameters
Returns:
{boolean}
: true if experimental plugins are enabledBack to module description.
rspamd_config:load_ucl(filename[, include_trace])
Loads config from the UCL file (but does not perform parsing using rcl)
Parameters:
filename {string}
: file to loadReturns:
Back to module description.
rspamd_config:parse_rcl([skip_sections])
Parses RCL using loaded ucl file
Parameters:
sections {table|string}
: to skipReturns:
Back to module description.
rspamd_config:init_modules()
Initialize lua and internal modules
Parameters:
No parameters
Returns:
Back to module description.
rspamd_config:init_subsystem(str)
Initialize config subsystem from a comma separated list:
modules
- init moduleslangdet
- language detectordns
- DNS resolverParameters:
No parameters
Returns:
No return
Back to module description.
rspamd_config:get_tld_path()
Returns path to TLD file
Parameters:
No parameters
Returns:
{string}
: path to tld fileBack to module description.
rspamd_config:get_dns_max_requests()
Returns limit of DNS requests per task
Parameters:
No parameters
Returns:
{number}
: number of dns requests allowedBack to module description.
rspamd_config:get_dns_timeout()
Returns timeout for a DNS request
Parameters:
No parameters
Returns:
{number}
: DNS timeout in second or 0 if not definedBack to module description.
Back to top.