[PATCH 3/5] Improve formatting of the Dovecot deliver, login, and disconnect summaries

Richard Hansen <rhansen-A08e6c8yq/[email protected]>
Newsgroups gmane.comp.log.logwatch.devel
Message-ID <[email protected]>
 * Show a one-line total when detail=0
 * Output fewer lines by putting the total on the same line as the
   header
 * Put the count to the left of the thing being counted to make it
   easier to compare values
 * Eliminate useless words to make it easier to quickly scan the
   output
---
 scripts/services/dovecot |  105 +++++++++++++++++++++------------------------
 1 files changed, 49 insertions(+), 56 deletions(-)

diff --git a/scripts/services/dovecot b/scripts/services/dovecot
index 3e76ab4..63d0398 100755
--- a/scripts/services/dovecot
+++ b/scripts/services/dovecot
@@ -294,31 +294,26 @@ if ( ( $Detail >= 5 ) and (keys %Connection)) {
    printf "\n%4s %4s %5s  %s", $POP3Count, $IMAPCount, $TotalCount, "Total";
 }
 
-if ( ( $Detail >= 5 ) and (keys %Deliver)) {
-   print "\n\nDovecot Deliveries:";
-   $DeliverCount = 0;
-   foreach my $User (sort keys %Deliver) {
-      print "\n  User $User:";
-      $UserCount = 0;
-      $NumMailboxes = 0;
-      foreach $Mailbox (sort keys %{$Deliver{$User}}) {
-         $NumMailboxes++;
-         $MailboxCount = $Deliver{$User}{$Mailbox};
-         print "\n    To $Mailbox: $MailboxCount Time(s)" if ($Detail >= 10);
-         $UserCount += $MailboxCount;
+if (keys %Deliver) {
+   my $DeliverCount = 0;
+   my $DeliverUserCount = {};
+   foreach my $User (keys %Deliver) {
+      foreach my $Mailbox (keys %{$Deliver{$User}}) {
+         $DeliverUserCount{$User} += $Deliver{$User}{$Mailbox};
       }
-      $DeliverCount += $UserCount;
-      if ($Detail >= 10) {
-         if ($NumMailboxes > 1) {
-	    print "\n  Total: $UserCount Time(s)\n";
-	 } else {
-	    print "\n";
-	 }
-      } elsif ($Detail >= 5) {
-         print " $UserCount Time(s)";
+      $DeliverCount += $DeliverUserCount{$User};
+   }
+   printf "\n\nDovecot Deliveries: %s", $DeliverCount;
+   if ($Detail >= 5) {
+      foreach my $User (sort keys %DeliverUserCount) {
+         printf "\n  %4s %s", $DeliverUserCount{$User}, $User;
+         if ($Detail >= 10) {
+            foreach my $Mailbox (sort keys %{$Deliver{$User}}) {
+               printf "\n      %4s %s", $Deliver{$User}{$Mailbox}, $Mailbox;
+            }
+         }
       }
    }
-   print "\nTotal: $DeliverCount successful deliveries";
 }
 
 if (($Detail >= 10) and (keys %Forwarded)) {
@@ -362,40 +357,32 @@ if (($Detail >= 10) and (keys %VacationDup)) {
 }
 
 
-if ( ( $Detail >= 5 ) and (keys %Login)) {
-   print "\n\nDovecot IMAP and POP3 Successful Logins:";
-   $LoginCount = 0;
-   foreach my $User (sort keys %Login) {
-      print "\n  User $User:";
-      if ( ($Detail >= 10) and ($LoginPOP3{$User} > 0 || $LoginIMAP{$User} > 0) ) {
-         print "   (";
-         if ($LoginPOP3{$User} > 0) { print "$LoginPOP3{$User} POP3"; };
-         if ($LoginPOP3{$User} > 0 && $LoginIMAP{$User} > 0) { print "/"; };
-         if ($LoginIMAP{$User} > 0) { print "$LoginIMAP{$User} IMAP"; };
-         print ")";
-      }
-      $UserCount = 0;
-      $NumHosts = 0;
-      foreach $Host (sort keys %{$Login{$User}}) {
-         $NumHosts++;
-         $HostCount = $Login{$User}{$Host};
-# Cleanly display IPv4 addresses
-         $Host=~ s/::ffff://;
-         print "\n    From $Host: $HostCount Time(s)" if ($Detail >= 10);
-         $UserCount += $HostCount;
+if (keys %Login) {
+   my $LoginCount = 0;
+   my $LoginUserCount = {};
+   foreach my $User (keys %Login) {
+      foreach my $Host (keys %{$Login{$User}}) {
+         $LoginUserCount{$User} += $Login{$User}{$Host};
       }
-      $LoginCount += $UserCount;
-      if ($Detail >= 10) {
-         if ($NumHosts > 1) {
-            print "\n  Total: $UserCount Time(s)\n";
-         } else {
-	    print "\n";
-	 }
-      } elsif ($Detail >= 5) {
-         print " $UserCount Time(s)";
+      $LoginCount += $LoginUserCount{$User};
+      $LoginPOP3{$User} = 0 if $LoginPOP3{$User} <= 0;
+      $LoginIMAP{$User} = 0 if $LoginIMAP{$User} <= 0;
+   }
+   printf "\n\nDovecot IMAP and POP3 Successful Logins: %s", $LoginCount;
+   if ($Detail >= 5) {
+      foreach my $User (sort keys %LoginUserCount) {
+         printf("\n  %4s %s", $LoginUserCount{$User}, $User);
+         if ($Detail >= 10) {
+            printf(" (%s POP3, %s IMAP)", $LoginPOP3{$User}, $LoginIMAP{$User});
+            foreach my $Host (sort keys %{$Login{$User}}) {
+               $HostCount = $Login{$User}{$Host};
+               # Cleanly display IPv4 addresses
+               $Host=~ s/::ffff://;
+               printf "\n      %4s %s", $Login{$User}{$Host}, $Host;
+            }
+         }
       }
    }
-   print "\nTotal: $LoginCount successful logins";
 }
 
 if ( ( $Detail >= 10 ) and (keys %SieveLogin)) {
@@ -429,9 +416,15 @@ if (keys %LimitExceeded) {
 }
 
 if (keys %Disconnected) {
-   print "\n\nDovecot disconnects:";
-   foreach my $Reason (sort keys %Disconnected) {
-      print "\n   $Reason: $Disconnected{$Reason} Time(s)";
+   my $Disconnects = 0;
+   foreach my $Reason (%Disconnected) {
+      $Disconnects += $Disconnected{$Reason};
+   }
+   printf "\n\nDovecot disconnects: %s", $Disconnects;
+   if ($Detail >= 5) {
+      foreach my $Reason (sort keys %Disconnected) {
+         printf "\n  %4s %s", $Disconnected{$Reason}, $Reason;
+      }
    }
 }
 
-- 
1.7.4.1


------------------------------------------------------------------------------
Better than sec? Nothing is better than sec when it comes to
monitoring Big Data applications. Try Boundary one-second 
resolution app monitoring today. Free.
http://p.sf.net/sfu/Boundary-dev2dev
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.