--[[ Copyright (c) 2026, Vsevolod Stakhov Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ]]-- local argparse = require "argparse" local rspamd_regexp = require "rspamd_regexp" local ucl = require "ucl" local log_utils = require "lua_log_utils" local ansicolors = require "ansicolors" local action_colors = { reject = ansicolors.red, ['add header'] = ansicolors.yellow, ['rewrite subject'] = ansicolors.yellow, ['soft reject'] = ansicolors.magenta, greylist = ansicolors.cyan, ['no action'] = ansicolors.green, } local parser = argparse() :name "rspamadm logstats" :description "Analyze Rspamd rules by parsing log files" :help_description_margin(32) parser:argument "log" :description "Log file or directory to read (stdin if omitted)" :args "?" :default "" parser:option "-r --reject-score" :description "Reject threshold" :argname "" :default "15.0" :convert(tonumber) parser:option "-j --junk-score" :description "Junk score threshold" :argname "" :default "6.0" :convert(tonumber) parser:option "-s --symbol" :description "Check specified symbol (regexp, '.*' by default)" :argname "" :count "*" parser:option "-S --symbol-bidir" :description "Bidirectional symbol (splits into SYM_SPAM/SYM_HAM)" :argname "" :count "*" parser:option "-X --exclude" :description "Exclude log lines if symbol fires" :argname "" :count "*" parser:option "--ignore" :description "Ignore symbol in correlations" :argname "" :count "*" parser:option "-g --group" :description "Group symbols (comma-separated)" :argname "" :count "*" parser:option "--mult" :description "Multiply symbol score (sym=number)" :argname "" :count "*" parser:option "-a --alpha-score" :description "Ignore score threshold" :argname "" :default "0.1" :convert(tonumber) parser:flag "-c --correlations" :description "Enable correlations report" parser:option "--nrelated" :description "Number of related symbols to show" :argname "" :default "10" :convert(tonumber) parser:option "--search-pattern" :description "Do not process input until pattern is found" :argname "" :default "" parser:option "--start" :description "Starting time for log parsing" :argname "