From 45a2116e8ea8b6ef0f7393b9bde3976301f2b9a5 Mon Sep 17 00:00:00 2001 From: Matt Simerson Date: Sat, 30 Jun 2012 17:51:59 -0400 Subject: [PATCH] log/summarize: narrower column when no geoip city data present --- log/summarize | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/log/summarize b/log/summarize index f1cf174..b203cca 100755 --- a/log/summarize +++ b/log/summarize @@ -25,7 +25,6 @@ my %formats = ( ip => "%-15.15s", hostname => "%-20.20s", distance => "%5.5s", - 'ident::geoip' => "%-20.20s", 'ident::p0f' => "%-10.10s", count_unrecognized_commands => "%-5.5s", @@ -109,10 +108,16 @@ while ( defined (my $line = $fh->read) ) { }; if ( $plugin eq 'ident::geoip' ) { - my ($gip, $distance) = $message =~ /(.*?),\s+([\d]+)\skm/; - if ( $distance ) { - $pids{$pid}{$plugin} = $gip; - $pids{$pid}{distance} = $distance; + if ( length $message < 3 ) { + $formats{'ident::geoip'} = "%-3.3s"; + $formats3{'ident::geoip'} = "%-3.3s"; + } + else { + my ($gip, $distance) = $message =~ /(.*?),\s+([\d]+)\skm/; + if ( $distance ) { + $pids{$pid}{$plugin} = $gip; + $pids{$pid}{distance} = $distance; + }; }; }; } @@ -234,12 +239,12 @@ sub print_auto_format { if ( defined $pids{$pid}{helo_host} && $plugin =~ /helo/ ) { $format .= " %-18.18s"; - push @values, delete $pids{$pid}{helo_host}; + push @values, substr( delete $pids{$pid}{helo_host}, -18, 18); push @headers, 'HELO'; } elsif ( defined $pids{$pid}{from} && $plugin =~ /from/ ) { $format .= " %-20.20s"; - push @values, delete $pids{$pid}{from}; + push @values, substr( delete $pids{$pid}{from}, -20, 20); push @headers, 'MAIL FROM'; } elsif ( defined $pids{$pid}{to} && $plugin =~ /to|rcpt|recipient/ ) {