[PATCH 4/5] Sort the connections, deliveries, logins, and disconnects by count

Richard Hansen <rhansen-A08e6c8yq/[email protected]>
Newsgroups gmane.comp.log.logwatch.devel
Message-ID <[email protected]>
This makes it easier to see the most significant events.
---
 scripts/services/dovecot |   19 +++++++++++++------
 1 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/scripts/services/dovecot b/scripts/services/dovecot
index 63d0398..afe7134 100755
--- a/scripts/services/dovecot
+++ b/scripts/services/dovecot
@@ -271,7 +271,8 @@ if ( ( $Detail >= 5 ) and (keys %Connection)) {
              "\n" . "-" x 72;
 
    $TLSInitFail = 0;
-   foreach $Host (sort keys %Connection) {
+   foreach $Host (sort { $Connection{$b} <=> $Connection{$a} }
+                  keys %Connection) {
       $Total = $Connection{$Host};
       if (defined ($ConnectionPOP3{$Host})) {
          $Conns = $ConnectionPOP3{$Host};
@@ -305,10 +306,13 @@ if (keys %Deliver) {
    }
    printf "\n\nDovecot Deliveries: %s", $DeliverCount;
    if ($Detail >= 5) {
-      foreach my $User (sort keys %DeliverUserCount) {
+      foreach my $User (sort { $DeliverUserCount{$b} <=> $DeliverUserCount{$a} }
+                        keys %DeliverUserCount) {
          printf "\n  %4s %s", $DeliverUserCount{$User}, $User;
          if ($Detail >= 10) {
-            foreach my $Mailbox (sort keys %{$Deliver{$User}}) {
+            foreach my $Mailbox (sort {
+               $Deliver{$User}{$b} <=> $Deliver{$User}{$a}
+                              } keys %{$Deliver{$User}}) {
                printf "\n      %4s %s", $Deliver{$User}{$Mailbox}, $Mailbox;
             }
          }
@@ -370,11 +374,13 @@ if (keys %Login) {
    }
    printf "\n\nDovecot IMAP and POP3 Successful Logins: %s", $LoginCount;
    if ($Detail >= 5) {
-      foreach my $User (sort keys %LoginUserCount) {
+      foreach my $User (sort { $LoginUserCount{$b} <=> $LoginUserCount{$a} }
+                        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}}) {
+            foreach my $Host (sort { $Login{$User}{$b} <=> $Login{$User}{$a} }
+                              keys %{$Login{$User}}) {
                $HostCount = $Login{$User}{$Host};
                # Cleanly display IPv4 addresses
                $Host=~ s/::ffff://;
@@ -422,7 +428,8 @@ if (keys %Disconnected) {
    }
    printf "\n\nDovecot disconnects: %s", $Disconnects;
    if ($Detail >= 5) {
-      foreach my $Reason (sort keys %Disconnected) {
+      foreach my $Reason (sort { $Disconnected{$b} <=> $Disconnected{$a} }
+                          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.