diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2021-04-27 14:37:11 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2021-04-27 14:37:11 +0100 |
commit | 755077b555ee224a1655308cc2b3fa8aa9741bfb (patch) | |
tree | 37c2dd46b47a8c24fe1e12cad861689179af2a6e /lualib | |
parent | 9e7d4ba97cab6bd022dbe98db466a201d097493d (diff) | |
download | rspamd-755077b555ee224a1655308cc2b3fa8aa9741bfb.tar.gz rspamd-755077b555ee224a1655308cc2b3fa8aa9741bfb.zip |
[Minor] Statistics_dump: Fix formatting
Diffstat (limited to 'lualib')
-rw-r--r-- | lualib/rspamadm/statistics_dump.lua | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/lualib/rspamadm/statistics_dump.lua b/lualib/rspamadm/statistics_dump.lua index ec8892002..a11c79129 100644 --- a/lualib/rspamadm/statistics_dump.lua +++ b/lualib/rspamadm/statistics_dump.lua @@ -142,7 +142,6 @@ local function check_redis_classifier(cls, cfg) end local function dump_handler(opts) - io.write('[\n') for _,cls in ipairs(classifiers) do local res,conn = lua_redis.redis_connect_sync(cls.redis_params, false) @@ -153,6 +152,7 @@ local function dump_handler(opts) end local cursor = 0 + local has_hdr = false local compress_ctx if opts.compress then compress_ctx = rspamd_zstd.compress_ctx() @@ -175,6 +175,10 @@ local function dump_handler(opts) local tokens = {} local out = {} + if not has_hdr then + out[1] = "{\n" + has_hdr = true + end for _,e in ipairs(elts) do conn:add_cmd('HGETALL', {e}) end @@ -198,18 +202,18 @@ local function dump_handler(opts) -- Output keeping track of the commas for i,d in ipairs(tokens) do - if i == #tokens then - out[#out + 1] = rspamd_logger.slog('{"%s": %s}\n', d.key, + if cursor == 0 and i == #tokens then + out[#out + 1] = rspamd_logger.slog('"%s": %s\n', d.key, ucl.to_format(d.data, "json-compact")) else - out[#out + 1] = rspamd_logger.slog('{"%s": %s},\n', d.key, + out[#out + 1] = rspamd_logger.slog('"%s": %s,\n', d.key, ucl.to_format(d.data, "json-compact")) end end if cursor == 0 then - out[#out + 1] = ']\n' + out[#out + 1] = '}\n' end if compress_ctx then |