from ..handler.pflogparse import PostfixLogfileParser
from ..xlate import XLATOR
-__version__ = '0.6.0'
+__version__ = '0.6.1'
LOG = logging.getLogger(__name__)
_ = XLATOR.gettext
self.pflogparser.evaluate_logfiles(self.logfiles)
self._collect_results()
- if self.verbose > 0:
+ if self.verbose > 2:
self.empty_line()
LOG.debug(_('Results per domain:') + '\n' + pp(self.per_domain))
self.empty_line()
LOG.debug(_('Results per address:') + '\n' + pp(self.per_address))
+ if self.show_address_results:
+ self._output_results_per_address()
+ self._output_results_per_domain()
+
+ # -------------------------------------------------------------------------
+ def _output_results_per_address(self):
+
+ max_len_loghost = 1
+ max_len_address = 1
+ max_len_count = 1
+
+ title = _('Results per address:')
+ self.empty_line()
+ print(self.colored(title, 'CYAN'))
+ self.line(width=len(title), linechar='-', color='CYAN')
+
+ for loghost in self.per_address.keys():
+
+ if len(loghost) > max_len_loghost:
+ max_len_loghost = len(loghost)
+
+ for address in self.per_address[loghost].keys():
+ count = self.per_address[loghost][address]
+ if len(address) > max_len_address:
+ max_len_address = len(address)
+ if len(str(count)) > max_len_count:
+ max_len_count = len(str(count))
+
+ template = '{{h:<{lh}}} {{a:<{la}}} - {{c:>{lc}}}'.format(
+ lh=max_len_loghost, la=max_len_address, lc=max_len_count)
+
+ for loghost in sorted(self.per_address.keys(), key=str.lower):
+
+ first = True
+
+ self.empty_line()
+ for address in sorted(
+ self.per_address[loghost].keys(),
+ key=lambda x: self.per_address[loghost][x],
+ reverse=True):
+ lh_out = loghost
+ if not first:
+ lh_out = ''
+
+ count = self.per_address[loghost][address]
+ print(template.format(h=lh_out, a=address, c=count))
+
+ first = False
+
+ # -------------------------------------------------------------------------
+ def _output_results_per_domain(self):
+
+ max_len_loghost = 1
+ max_len_domain = 1
+ max_len_count = 1
+
+ title = _('Results per domain:')
+ self.empty_line()
+ print(self.colored(title, 'CYAN'))
+ self.line(width=len(title), linechar='-', color='CYAN')
+
+ for loghost in self.per_domain.keys():
+
+ if len(loghost) > max_len_loghost:
+ max_len_loghost = len(loghost)
+
+ for domain in self.per_domain[loghost].keys():
+ count = self.per_domain[loghost][domain]
+ if len(domain) > max_len_domain:
+ max_len_domain = len(domain)
+ if len(str(count)) > max_len_count:
+ max_len_count = len(str(count))
+
+ template = '{{h:<{lh}}} {{d:<{ld}}} - {{c:>{lc}}}'.format(
+ lh=max_len_loghost, ld=max_len_domain, lc=max_len_count)
+
+ for loghost in sorted(self.per_domain.keys(), key=str.lower):
+
+ first = True
+
+ self.empty_line()
+
+ for domain in sorted(
+ self.per_domain[loghost].keys(),
+ key=lambda x: self.per_domain[loghost][x],
+ reverse=True):
+ lh_out = loghost
+ if not first:
+ lh_out = ''
+
+ count = self.per_domain[loghost][domain]
+ print(template.format(h=lh_out, d=domain, c=count))
+
+ first = False
+
# =============================================================================
if __name__ == '__main__':