aboutsummaryrefslogtreecommitdiffstats
path: root/src/rspamadm/fuzzy_stat.lua
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2015-12-15 18:42:34 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2015-12-15 18:42:34 +0000
commit25b2b061e6711e914d2512ee584d4687bdf53641 (patch)
tree095adba0c74e9620b0c25801bf36bcd9d6b7ef31 /src/rspamadm/fuzzy_stat.lua
parent24b42e94c5980a3e1056881cf92d085a4809458e (diff)
downloadrspamd-25b2b061e6711e914d2512ee584d4687bdf53641.tar.gz
rspamd-25b2b061e6711e914d2512ee584d4687bdf53641.zip
Improve output for fuzzystat
Diffstat (limited to 'src/rspamadm/fuzzy_stat.lua')
-rw-r--r--src/rspamadm/fuzzy_stat.lua103
1 files changed, 50 insertions, 53 deletions
diff --git a/src/rspamadm/fuzzy_stat.lua b/src/rspamadm/fuzzy_stat.lua
index c7a9b49b6..f4c4455a9 100644
--- a/src/rspamadm/fuzzy_stat.lua
+++ b/src/rspamadm/fuzzy_stat.lua
@@ -1,27 +1,3 @@
---Res here is the table of the following args:
---workers: {
--- pid: {
--- data: {
--- key_id: {
--- matched:
--- scanned:
--- added:
--- removed:
--- errors:
--- last_ips: {
--- ip: {
--- matched:
--- scanned
--- added:
--- removed:
--- }
--- }
--- }
--- }
--- }
---}
---.USE "getopt"
-
local function add_data(target, src)
for k,v in pairs(src) do
if k ~= 'ips' then
@@ -60,30 +36,47 @@ local function print_stat(st, tabs)
end
-- Sort by checked
-local function sort_ips(tbl)
+local function sort_ips(tbl, opts)
local res = {}
for k,v in pairs(tbl) do
table.insert(res, {ip = k, data = v})
end
- table.sort(res, function(a, b)
- local n1 = 0
- if a['data']['checked'] then n1 = a['data']['checked'] end
+ local function sort_order(elt)
+ local key = 'checked'
+ local res = 0
+
+ if opts['sort'] then
+ if opts['sort'] == 'matched' then
+ key = 'matched'
+ elseif opts['sort'] == 'errors' then
+ key = 'errors'
+ elseif opts['sort'] == 'ip' then
+ return elt['ip']
+ end
+ end
+
+ if elt['data'][key] then
+ res = elt['data'][key]
+ end
- local n2 = 0
- if b['data']['checked'] then n2 = b['data']['checked'] end
+ return res
+ end
- return n1 > n2
+ table.sort(res, function(a, b)
+ return sort_order(a) > sort_order(b)
end)
return res
end
+--.USE "getopt"
+
return function(args, res)
local res_keys = {}
local res_ips = {}
-
local wrk = res['workers']
+ local opts = getopt(args, '')
if wrk then
for i,pr in pairs(wrk) do
@@ -109,34 +102,38 @@ return function(args, res)
end
end
- print('Keys statistics:')
- for k,st in pairs(res_keys) do
- print(string.format('Key id: %s', k))
- print_stat(st, '\t')
+ if not opts['no-keys'] then
+ print('Keys statistics:')
+ for k,st in pairs(res_keys) do
+ print(string.format('Key id: %s', k))
+ print_stat(st, '\t')
- if st['ips'] then
- print('')
- print('\tIPs stat:')
- local sorted_ips = sort_ips(st['ips'])
-
- for i,v in ipairs(sorted_ips) do
- print(string.format('\t%s', v['ip']))
- print_stat(v['data'], '\t\t')
+ if st['ips'] then
print('')
+ print('\tIPs stat:')
+ local sorted_ips = sort_ips(st['ips'], opts)
+
+ for i,v in ipairs(sorted_ips) do
+ print(string.format('\t%s', v['ip']))
+ print_stat(v['data'], '\t\t')
+ print('')
+ end
end
- end
- print('')
+ print('')
+ end
end
- print('')
- print('IPs statistics:')
-
- local sorted_ips = sort_ips(res_ips)
- for i, v in ipairs(sorted_ips) do
- print(string.format('%s', v['ip']))
- print_stat(v['data'], '\t')
+ if not opts['no-ips'] then
print('')
+ print('IPs statistics:')
+
+ local sorted_ips = sort_ips(res_ips, opts)
+ for i, v in ipairs(sorted_ips) do
+ print(string.format('%s', v['ip']))
+ print_stat(v['data'], '\t')
+ print('')
+ end
end
end