diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-02-02 12:08:13 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-02-02 12:08:13 +0000 |
commit | 07e0b263fb50c296ea80f3db48c780fa2a54c653 (patch) | |
tree | 98ea89328ffa364ce4fd4e0d787554ca6bd20816 /src/rspamadm | |
parent | 8bbf2795c8dce18b8c2c64f7107d2a1d1840a6c2 (diff) | |
parent | 1cfa9e3d8b749a08169f5b3495a71bcc3632d7ff (diff) | |
download | rspamd-07e0b263fb50c296ea80f3db48c780fa2a54c653.tar.gz rspamd-07e0b263fb50c296ea80f3db48c780fa2a54c653.zip |
Merge pull request #1390 from fatalbanana/b6
[Minor] Some more fixes/features for rspamadm grep
Diffstat (limited to 'src/rspamadm')
-rw-r--r-- | src/rspamadm/grep.c | 17 | ||||
-rw-r--r-- | src/rspamadm/grep.lua | 35 |
2 files changed, 38 insertions, 14 deletions
diff --git a/src/rspamadm/grep.c b/src/rspamadm/grep.c index aff986c68..3681873b5 100644 --- a/src/rspamadm/grep.c +++ b/src/rspamadm/grep.c @@ -23,6 +23,8 @@ static gchar *string = NULL; static gchar *pattern = NULL; static gchar **inputs = NULL; static gboolean sensitive = FALSE; +static gboolean orphans = FALSE; +static gboolean partial = FALSE; static void rspamadm_grep (gint argc, gchar **argv); static const char *rspamadm_grep_help (gboolean full_help); @@ -42,7 +44,11 @@ static GOptionEntry entries[] = { {"pattern", 'p', 0, G_OPTION_ARG_STRING, &pattern, "Pattern to search for (regex)", NULL}, {"input", 'i', 0, G_OPTION_ARG_STRING_ARRAY, &inputs, - "Processed specified inputs", NULL}, + "Process specified inputs", NULL}, + {"orphans", 'o', 0, G_OPTION_ARG_NONE, &orphans, + "Print orphaned logs", NULL}, + {"partial", 'P', 0, G_OPTION_ARG_NONE, &orphans, + "Print partial logs", NULL}, {NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL} }; @@ -58,6 +64,7 @@ rspamadm_grep_help (gboolean full_help) "Where options are:\n\n" "-s: Plain string to search (case-insensitive)\n" "-S: Enable case-sensitivity in string search\n" + "-o: Print orphaned logs\n" "-p: Pattern to search for (regex)\n" "-i: Process specified inputs\n"; } @@ -127,6 +134,14 @@ rspamadm_grep (gint argc, gchar **argv) ucl_object_insert_key (obj, ucl_object_frombool (sensitive), "sensitive", 0, false); } + if (orphans) { + ucl_object_insert_key (obj, ucl_object_frombool (orphans), + "orphans", 0, false); + } + if (partial) { + ucl_object_insert_key (obj, ucl_object_frombool (partial), + "partial", 0, false); + } rspamadm_execute_lua_ucl_subr (L, argc, diff --git a/src/rspamadm/grep.lua b/src/rspamadm/grep.lua index 4c77db73d..c5527680b 100644 --- a/src/rspamadm/grep.lua +++ b/src/rspamadm/grep.lua @@ -1,8 +1,8 @@ -local rspamd_regexp = require 'rspamd_regexp' -local E = {} - return function(_, res) + local rspamd_regexp = require 'rspamd_regexp' + local E = {} + local buffer = {} local matches = {} @@ -16,8 +16,10 @@ return function(_, res) end end + local orphans = res['orphans'] local search_str = res['string'] local sensitive = res['sensitive'] + local partial = res['partial'] if search_str and not sensitive then search_str = string.lower(search_str) end @@ -67,9 +69,11 @@ return function(_, res) end if ismatch then if not hash then - print('*** orphaned ***') - print(line) - print() + if orphans then + print('*** orphaned ***') + print(line) + print() + end else if matches[hash] then table.insert(matches[hash], line) @@ -92,13 +96,18 @@ return function(_, res) end end end + if partial then + for k, v in pairs(matches) do + print('*** partial ***') + for _, vv in ipairs(v) do + print(vv) + end + print() + matches[k] = nil + end + else + matches = {} + end end end - for _, v in pairs(matches) do - print('*** partial ***') - for _, vv in ipairs(v) do - print(vv) - end - print() - end end |