summarize shows a narrower screen by default.

passing in -l for when your term windows is more than 200 chars wide will show more detail
This commit is contained in:
Matt Simerson 2013-04-24 00:27:07 -04:00
parent 3d7d43e0af
commit f41df6e96d

View File

@ -6,9 +6,13 @@ use warnings;
use Cwd; use Cwd;
use Data::Dumper; use Data::Dumper;
use File::Tail; use File::Tail;
use Getopt::Std;
$Data::Dumper::Sortkeys = 1; $Data::Dumper::Sortkeys = 1;
our $opt_l = 0;
getopts('l');
my (%plugins, %plugin_aliases, %seen_plugins, %pids); my (%plugins, %plugin_aliases, %seen_plugins, %pids);
my %hide_plugins = map { $_ => 1 } qw/ hostname /; my %hide_plugins = map { $_ => 1 } qw/ hostname /;
@ -32,7 +36,7 @@ my %formats = (
ip => "%-15.15s", ip => "%-15.15s",
hostname => "%-20.20s", hostname => "%-20.20s",
distance => "%5.5s", distance => "%5.5s",
'ident::geoip' => "%-20.20s", 'ident::geoip' => $opt_l ? "%-20.20s" : "%-6.6s",
'ident::p0f' => "%-10.10s", 'ident::p0f' => "%-10.10s",
count_unrecognized_commands => "%-5.5s", count_unrecognized_commands => "%-5.5s",
unrecognized_commands => "%-5.5s", unrecognized_commands => "%-5.5s",
@ -269,18 +273,20 @@ sub print_auto_format {
next; next;
} }
my $wide = $opt_l ? 20 : 8;
if (defined $pids{$pid}{helo_host} && $plugin =~ /helo/) { if (defined $pids{$pid}{helo_host} && $plugin =~ /helo/) {
$format .= " %-18.18s"; $format .= " %-$wide.${wide}s";
push @values, substr(delete $pids{$pid}{helo_host}, -18, 18); push @values, substr(delete $pids{$pid}{helo_host}, -$wide, $wide);
push @headers, 'HELO'; push @headers, 'HELO';
} }
elsif (defined $pids{$pid}{from} && $plugin =~ /from/) { elsif (defined $pids{$pid}{from} && $plugin =~ /from/) {
$format .= " %-20.20s"; $format .= " %-$wide.${wide}s";
push @values, substr(delete $pids{$pid}{from}, -20, 20); push @values, substr(delete $pids{$pid}{from}, -$wide, $wide);
push @headers, 'MAIL FROM'; push @headers, 'MAIL FROM';
} }
elsif (defined $pids{$pid}{to} && $plugin =~ /to|rcpt|recipient/) { elsif (defined $pids{$pid}{to} && $plugin =~ /to|rcpt|recipient/) {
$format .= " %-20.20s"; $format .= " %-$wide.${wide}s";
push @values, delete $pids{$pid}{to}; push @values, delete $pids{$pid}{to};
push @headers, 'RCPT TO'; push @headers, 'RCPT TO';
} }
@ -299,7 +305,7 @@ sub print_auto_format {
$format .= "\n"; $format .= "\n";
printf("\n$format", @headers) if (!$printed || $printed % 20 == 0); printf("\n$format", @headers) if (!$printed || $printed % 20 == 0);
printf($format, @values); printf($format, @values);
print Data::Dumper::Dumper($pids{$pid}) if keys %{$pids{$pid}}; #print Data::Dumper::Dumper($pids{$pid}) if keys %{$pids{$pid}};
$printed++; $printed++;
} }
@ -347,6 +353,8 @@ sub populate_plugins_from_registry {
open my $F, '<', $file; open my $F, '<', $file;
while (defined(my $line = <$F>)) { while (defined(my $line = <$F>)) {
next if $line =~ /^#/; # discard comments next if $line =~ /^#/; # discard comments
chomp $line;
next if ! $line;
my ($id, $name, $abb3, $abb5, $aliases) = split /\s+/, $line; my ($id, $name, $abb3, $abb5, $aliases) = split /\s+/, $line;
next if !defined $name; next if !defined $name;
$plugins{$name} = {id => $id, abb3 => $abb3, abb5 => $abb5}; $plugins{$name} = {id => $id, abb3 => $abb3, abb5 => $abb5};