]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Minor] Add logging variable for forced actions
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 11 Oct 2018 16:26:02 +0000 (17:26 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 11 Oct 2018 16:26:02 +0000 (17:26 +0100)
src/libserver/cfg_file.h
src/libserver/cfg_utils.c
src/libserver/task.c

index c583766c44ef928e1dd520df91007c0c109844c7..cb3581e9736fbc723ea090c5a0343fa7ab84c7f9 100644 (file)
@@ -236,6 +236,7 @@ enum rspamd_log_format_type {
        RSPAMD_LOG_LUA,
        RSPAMD_LOG_DIGEST,
        RSPAMD_LOG_FILENAME,
+       RSPAMD_LOG_FORCED_ACTION,
 };
 
 enum rspamd_log_format_flags {
index 3d5b690508a39d128fa9511596490fbfb980c3f5..ff1e77d159a2df47548e89c58f7a413eef49cbbe 100644 (file)
@@ -446,6 +446,9 @@ rspamd_config_process_var (struct rspamd_config *cfg, const rspamd_ftok_t *var,
        else if (rspamd_ftok_cstr_equal (&tok, "filename", TRUE)) {
                type = RSPAMD_LOG_FILENAME;
        }
+       else if (rspamd_ftok_cstr_equal (&tok, "forced_action", TRUE)) {
+               type = RSPAMD_LOG_FORCED_ACTION;
+       }
        else {
                msg_err_config ("unknown log variable: %T", &tok);
                return FALSE;
index 42d9b17895e42c009d43e30f2669c1eef5c4f903..f4a09fd30e917755905cbd42e9587cf5b6aded5e 100644 (file)
@@ -1010,6 +1010,11 @@ rspamd_task_log_check_condition (struct rspamd_task *task,
                        ret = TRUE;
                }
                break;
+       case RSPAMD_LOG_FORCED_ACTION:
+               if (task->result->passthrough_result) {
+                       ret = TRUE;
+               }
+               break;
        default:
                ret = TRUE;
                break;
@@ -1292,7 +1297,7 @@ rspamd_task_log_variable (struct rspamd_task *task,
 {
        rspamd_fstring_t *res = logbuf;
        rspamd_ftok_t var = {.begin = NULL, .len = 0};
-       static gchar numbuf[64];
+       static gchar numbuf[128];
        static const gchar undef[] = "undef";
 
        switch (lf->type) {
@@ -1412,6 +1417,29 @@ rspamd_task_log_variable (struct rspamd_task *task,
                        var.len = sizeof (undef) - 1;
                }
                break;
+       case RSPAMD_LOG_FORCED_ACTION:
+               if (task->result->passthrough_result) {
+                       struct rspamd_passthrough_result *pr = task->result->passthrough_result;
+
+                       if (!isnan (pr->target_score)) {
+                               var.len = rspamd_snprintf (numbuf, sizeof (numbuf),
+                                               "%s \"%s\"; score=%.2f (set by %s)",
+                                               rspamd_action_to_str (pr->action),
+                                               pr->message, pr->target_score, pr->module);
+                       }
+                       else {
+                               var.len = rspamd_snprintf (numbuf, sizeof (numbuf),
+                                               "%s \"%s\"; score=nan (set by %s)",
+                                               rspamd_action_to_str (pr->action),
+                                               pr->message, pr->module);
+                       }
+                       var.begin = numbuf;
+               }
+               else {
+                       var.begin = undef;
+                       var.len = sizeof (undef) - 1;
+               }
+               break;
        default:
                var = rspamd_task_log_metric_res (task, lf);
                break;