[PATCH] lvm: add snapshot monitoring

Hayden Lau <[email protected]> Thu, 21 Jul 2016 14:09:32 -0400
Newsgroups gmane.comp.log.logwatch.devel
Message-ID <[email protected]>
Hello,

Was using Logwatch on my home server and saw it spit out unmatched lines 
about monitoring snapshots, so I figured I'd modify the script to handle 
that. Take it easy on me - this is the first thing I've ever written in 
Perl. This is 'monitoring' output after the patch:

  Monitoring started for:
      Thin Pool vg_bulk-testpool0-tpool: 1 Time(s)
      Snapshot vg_raid-rsnapshot: 3 Time(s)
  
  Monitoring stopped for:
      Thin Pool vg_bulk-testpool0-tpool: 1 Time(s)
      Snapshot vg_raid-rsnapshot: 3 Time(s)

Regards,
Hayden Lau

---
  scripts/services/lvm | 24 ++++++++++++++++++------
  1 file changed, 18 insertions(+), 6 deletions(-)

diff --git a/scripts/services/lvm b/scripts/services/lvm
index 136e507..6b3689c 100755
--- a/scripts/services/lvm
+++ b/scripts/services/lvm
@@ -23,7 +23,9 @@ my %PoolMetadataUsed;
  my $SnapshotThreshold = $ENV{'snapshot_threshold'} || 0;
  my %SnapshotUsed;
  my %MonitoringOn;
+my %MonitoringOnType;
  my %MonitoringOff;
+my %MonitoringOffType;
  my %OtherList;

  while (defined(my $ThisLine = <STDIN>)) {
@@ -32,10 +34,20 @@ while (defined(my $ThisLine = <STDIN>)) {
        $PoolUsed{$1} = $2 if $2 >= $PoolThreshold;
     } elsif ($ThisLine =~ /^Thin metadata (\S+) is now (\d+)% full/) {
        $PoolMetadataUsed{$1} = $2 if $2 >= $PoolMetadataThreshold;
-   } elsif ($ThisLine =~ /^Monitoring thin (\S+)\./) {
-      $MonitoringOn{$1}++;
-   } elsif ($ThisLine =~ /^No longer monitoring thin (\S+)\./) {
-      $MonitoringOff{$1}++;
+   } elsif ($ThisLine =~ /^Monitoring (thin|snapshot) (\S+(?=\.)|\S+)/) {
+      $MonitoringOn{$2}++;
+      if ($1 eq "thin") {
+         $MonitoringOnType{$2} = "Thin Pool";
+      } elsif ($1 eq "snapshot") {
+         $MonitoringOnType{$2} = "Snapshot";
+      }
+   } elsif ($ThisLine =~ /^No longer monitoring (thin|snapshot) 
(\S+(?=\.)|\S+)/) {
+      $MonitoringOff{$2}++;
+      if ($1 eq "thin") {
+         $MonitoringOffType{$2} = "Thin Pool";
+      } elsif ($1 eq "snapshot") {
+         $MonitoringOffType{$2} = "Snapshot";
+      }
     } elsif ($ThisLine =~ /^Snapshot (\S+) is now (\d+)% full/) {
        $SnapshotUsed{$1} = $2 if $2 >= $SnapshotThreshold;
     } else {
@@ -70,7 +82,7 @@ if (keys %SnapshotUsed) {
  if (keys %MonitoringOn and $Detail) {
     print "Monitoring started for:\n";
     foreach my $Pool (sort {$a cmp $b} keys %MonitoringOn) {
-      print "    $Pool: $MonitoringOn{$Pool} Time(s)\n";
+      print "    $MonitoringOnType{$Pool} $Pool: $MonitoringOn{$Pool} 
Time(s)\n";
     }
     print "\n";
  }
@@ -78,7 +90,7 @@ if (keys %MonitoringOn and $Detail) {
  if (keys %MonitoringOff and $Detail) {
     print "Monitoring stopped for:\n";
     foreach my $Pool (sort {$a cmp $b} keys %MonitoringOff) {
-      print "    $Pool: $MonitoringOff{$Pool} Time(s)\n";
+      print "    $MonitoringOffType{$Pool} $Pool: $MonitoringOff{$Pool} 
Time(s)\n";
     }
     print "\n";
  }
-- 
2.9.2.windows.1

-- 
Hayden Lau
EngSci 1T6 Aerospace
999812984


------------------------------------------------------------------------------
What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are 
consuming the most bandwidth. Provides multi-vendor support for NetFlow, 
J-Flow, sFlow and other flows. Make informed decisions using capacity planning
reports.http://sdm.link/zohodev2dev