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);
{"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}
};
"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";
}
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,
-local rspamd_regexp = require 'rspamd_regexp'
-local E = {}
-
return function(_, res)
+ local rspamd_regexp = require 'rspamd_regexp'
+ local E = {}
+
local buffer = {}
local matches = {}
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
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)
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