]> source.dussan.org Git - rspamd.git/commitdiff
[Feature] Allow to register metrics symbols using register_symbol
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 26 Nov 2016 19:53:11 +0000 (19:53 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 26 Nov 2016 19:53:11 +0000 (19:53 +0000)
src/lua/lua_config.c

index 7025d8fdaca2a3bd2ca03aff24249bbdf15e7f4a..7c2b8460962541171ca83ce45023ded421525a32 100644 (file)
@@ -1111,17 +1111,20 @@ static gint
 lua_config_register_symbol (lua_State * L)
 {
        struct rspamd_config *cfg = lua_check_config (L, 1);
-       const gchar *name = NULL, *flags_str = NULL, *type_str = NULL;
-       double weight = 0;
+       const gchar *name = NULL, *flags_str = NULL, *type_str = NULL,
+                       *description = NULL, *group = NULL;
+       double weight = 0, score = NAN;
        gint ret = -1, cbref = -1, type;
        gint64 parent = 0, priority = 0;
        GError *err = NULL;
 
        if (cfg) {
                if (!rspamd_lua_parse_table_arguments (L, 2, &err,
-                               "name=S;weigth=N;callback=F;flags=S;type=S;priority=I;parent=I",
+                               "name=S;weigth=N;callback=F;flags=S;type=S;priority=I;parent=I;"
+                               "score=D;description=S;group=S",
                                &name, &weight, &cbref, &flags_str, &type_str,
-                               &priority, &parent)) {
+                               &priority, &parent,
+                               &score, &description, &group)) {
                        msg_err_config ("bad arguments: %e", err);
                        g_error_free (err);
 
@@ -1148,6 +1151,11 @@ lua_config_register_symbol (lua_State * L)
                                type,
                                parent == 0 ? -1 : parent,
                                FALSE);
+
+               if (!isnan (score)) {
+                       rspamd_config_add_metric_symbol (cfg, DEFAULT_METRIC, name,
+                                       score, description, group, 0, (guint)priority);
+               }
        }
        else {
                return luaL_error (L, "invalid arguments");