Commits

Chris Perl  committed 123b9b7

Experiementing with adding a rollup option. Need to rethink the command parser structure, etc.

  • Participants
  • Parent commits ade7e07

Comments (0)

Files changed (1)

File loganalyze.py

             attr = "_%s" % arg
             value = kwargs[arg]
             # Special handling for ._{foo}_filter attrs, compile them ahead of time
-            if re.match('^_.*_filter$', attr) and value is not None:
+            if re.match('^_re_.*$', attr) and value is not None:
                 value = re.compile(value)
             setattr(self, attr, value)
         self.aggr_data = {}
         # short circuit if the re_filter does not match the given self._key
         if self._re_filter and not self._re_filter.search(self._key):
             return
+        if self._re_rollup:
+            m = self._re_rollup.search(self._key)
+            if m:
+                self._key = self._key[m.start():m.end()]
         hits = self.aggr_data.setdefault(self._key, 0)
         self.aggr_data[self._key] = hits + 1
 
     def _setup_parser_do_topurls(self):
         self._parser_do_topurls = NonExitingOptionParser(usage="topurls [number of urls to display]")
         self._parser_do_topurls.add_option('-f', '--filter', action='store', type='str', dest='re_filter')
+        self._parser_do_topurls.add_option('-r', '--rollup', action='store', type='str', dest='re_rollup')
 
     def _setup_parser_do_url_hits_per_time(self):
         self._parser_do_url_hits_per_time = NonExitingOptionParser(usage="""url-hits-per-time --step STEP --filter FILTER""")
     def _setup_parser_do_toptalkers(self):
         self._parser_do_toptalkers = NonExitingOptionParser(usage="toptalkers [number of IPs to display]")
         self._parser_do_toptalkers.add_option('-f', '--filter', action='store', type='str', dest='re_filter')
+        self._parser_do_toptalkers.add_option('-r', '--rollup', action='store', type='str', dest='re_rollup')
 
     def _setup_parser_do_ip_hits_per_time(self):
         self._parser_do_ip_hits_per_time = NonExitingOptionParser(usage="""ip-hits-per-time --step STEP --filter FILTER""")
         options, args = self._parser_do_topurls.parse_args(list(cmd_args))
         num_urls = self._do_single_optional_numerical_positional_arg_check('topurls', args, 10)
 
-        self._hpu(start=self.start, end=self.end, re_filter=options.re_filter)
+        self._hpu(start=self.start, end=self.end, re_filter=options.re_filter,
+                  re_rollup=options.re_rollup)
         self._hpu.display(self._display_obj, num_urls)
 
     def _do_toptalkers(self, *cmd_args):
         options, args = self._parser_do_toptalkers.parse_args(list(cmd_args))
         num_ips = self._do_single_optional_numerical_positional_arg_check('toptalkers', args, 10)
 
-        self._hpi(start=self.start, end=self.end, re_filter=options.re_filter)
+        self._hpi(start=self.start, end=self.end, re_filter=options.re_filter,
+                  re_rollup=options.re_rollup)
         self._hpi.display(self._display_obj, num_ips)
 
     def _do_url_hits_per_time(self, *cmd_args):