]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Some more fixes/features for rspamadm grep 1390/head
authorAndrew Lewis <nerf@judo.za.org>
Thu, 2 Feb 2017 11:57:31 +0000 (13:57 +0200)
committerAndrew Lewis <nerf@judo.za.org>
Thu, 2 Feb 2017 11:57:31 +0000 (13:57 +0200)
 - Dump partial matches after processing each file
 - Don't print orphans & partial matches by default
 - Fix typo

src/rspamadm/grep.c
src/rspamadm/grep.lua

index aff986c68c8e80d1af1555081d9b41b43dfb843d..3681873b5f86635e8da7e4b9b297fa4d2c2e094f 100644 (file)
@@ -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,
index 4c77db73dd37b61ea47b68bf99bdc696c25e1916..c5527680bbdc21410269c9366fcf3296e883f436 100644 (file)
@@ -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