commit 412cc05: [Minor] Sort error ips by number of errors
Vsevolod Stakhov
vsevolod at rspamd.com
Tue Mar 29 19:49:04 UTC 2022
Author: Vsevolod Stakhov
Date: 2022-03-29 20:43:03 +0100
URL: https://github.com/rspamd/rspamd/commit/412cc05ff14dffee529fdc5b8c19814a9ded1df4 (HEAD -> master)
[Minor] Sort error ips by number of errors
---
lualib/rspamadm/fuzzy_stat.lua | 16 ++++++++++------
1 file 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
More information about the Commits
mailing list