aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rspamd.com>2022-03-29 20:43:03 +0100
committerVsevolod Stakhov <vsevolod@rspamd.com>2022-03-29 20:43:03 +0100
commit412cc05ff14dffee529fdc5b8c19814a9ded1df4 (patch)
treeb63ae2ca1b000712f2c9267c55c5312a7e1d2641
parent9631b8674c5f782c548fe114f12b61bcdf59f318 (diff)
downloadrspamd-412cc05ff14dffee529fdc5b8c19814a9ded1df4.tar.gz
rspamd-412cc05ff14dffee529fdc5b8c19814a9ded1df4.zip
[Minor] Sort error ips by number of errors
-rw-r--r--lualib/rspamadm/fuzzy_stat.lua16
1 files changed, 10 insertions, 6 deletions
diff --git a/lualib/rspamadm/fuzzy_stat.lua b/lualib/rspamadm/fuzzy_stat.lua
index 45e13bb60..6417430b8 100644
--- a/lualib/rspamadm/fuzzy_stat.lua
+++ b/lualib/rspamadm/fuzzy_stat.lua
@@ -1,4 +1,5 @@
-local util = require "rspamd_util"
+local rspamd_util = require "rspamd_util"
+local lua_util = require "lua_util"
local opts = {}
local argparse = require "argparse"
@@ -45,7 +46,7 @@ local function print_num(num)
if opts['n'] or opts['number'] then
return tostring(num)
else
- return util.humanize_number(num)
+ return rspamd_util.humanize_number(num)
end
end
@@ -270,11 +271,14 @@ return function(args, res)
if st['errors_ips'] and not opts['no-ips'] and not opts['short'] then
print('')
print('Errors IPs statistics:')
- table.sort(st['errors_ips'], function(a, b)
- return a > b
+ local ip_stat = st['errors_ips']
+ local ips = lua_util.keys(ip_stat)
+ -- Reverse sort by number of errors
+ table.sort(ips, function(a, b)
+ return ip_stat[a] > ip_stat[b]
end)
- for i, v in pairs(st['errors_ips']) do
- print(string.format('%s: %s', i, print_result(v)))
+ for _, ip in ipairs(ips) do
+ print(string.format('%s: %s', ip, print_result(ip_stat[ip])))
end
print('')
end