diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-01-25 15:30:48 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-01-25 15:31:11 +0000 |
commit | 896cef33597e7f36294b6122fbd8dc8db7b8d9b9 (patch) | |
tree | 13aa270e0fde49ce75560077465943b09f6d98d9 /src/lua | |
parent | 5bebcf793bdb4cc69f142d19edd74a945ce618ae (diff) | |
download | rspamd-896cef33597e7f36294b6122fbd8dc8db7b8d9b9.tar.gz rspamd-896cef33597e7f36294b6122fbd8dc8db7b8d9b9.zip |
[Feature] Allow to set peak callbacks from Lua
Diffstat (limited to 'src/lua')
-rw-r--r-- | src/lua/lua_config.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/lua/lua_config.c b/src/lua/lua_config.c index 4f826901b..06157f44e 100644 --- a/src/lua/lua_config.c +++ b/src/lua/lua_config.c @@ -572,6 +572,26 @@ LUA_FUNCTION_DEF (config, register_monitored); */ LUA_FUNCTION_DEF (config, add_doc); +/*** + * @method 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. + * + * @example +rspamd_config:set_peak_cb(function(ev_base, sym, mean, stddev, value, error) + -- ev_base: event base for async events (e.g. redis) + -- sym: symbol's name + -- mean: mean frequency value + -- stddev: standard deviation of frequency + -- value: current frequency value + -- error: squared error + local logger = require "rspamd_logger" + logger.infox(rspamd_config, "symbol %s has changed frequency significantly: %s(%s) over %s(%s)", + sym, value, error, mean, stddev) +end) + */ +LUA_FUNCTION_DEF (config, set_peak_cb); + static const struct luaL_reg configlib_m[] = { LUA_INTERFACE_DEF (config, get_module_opt), LUA_INTERFACE_DEF (config, get_mempool), @@ -613,6 +633,7 @@ static const struct luaL_reg configlib_m[] = { LUA_INTERFACE_DEF (config, register_finish_script), LUA_INTERFACE_DEF (config, register_monitored), LUA_INTERFACE_DEF (config, add_doc), + LUA_INTERFACE_DEF (config, set_peak_cb), {"__tostring", rspamd_lua_class_tostring}, {"__newindex", lua_config_newindex}, {NULL, NULL} @@ -1888,6 +1909,22 @@ lua_config_add_condition (lua_State *L) } static gint +lua_config_set_peak_cb (lua_State *L) +{ + struct rspamd_config *cfg = lua_check_config (L, 1); + gint condref; + + if (cfg && lua_type (L, 2) == LUA_TFUNCTION) { + lua_pushvalue (L, 2); + condref = luaL_ref (L, LUA_REGISTRYINDEX); + rspamd_symbols_cache_set_peak_callback (cfg->cache, + condref); + } + + return 0; +} + +static gint lua_config_enable_symbol (lua_State *L) { struct rspamd_config *cfg = lua_check_config (L, 1); |