#!/usr/bin/perl -w
##########################################################################
# $Id: smartd,v 1.5 2004/02/03 03:36:39 kirk Exp $
##########################################################################

#$Detail = $ENV{'LOGWATCH_DETAIL_LEVEL'} || 0;

while (defined($ThisLine = <STDIN>)) {
   chomp($ThisLine);
   if ( ($Device,$Msg) = ($ThisLine =~ /^Device: ([^,]+), No such device or address, open\(\) failed/ )) {
       # ignore
   } elsif ( ($Device,$Msg) = ($ThisLine =~ /^Device: ([^,]+), is SMART capable. Adding to "monitor" list./ )) {
       # ignore
   } elsif ( ($Device,$Msg) = ($ThisLine =~ /^Device: ([^,]+), found in smartd database./ )) {
       # ignore
   } elsif ( ($Device,$Msg) = ($ThisLine =~ /^Device: ([^,]+), opened/)) {
       # ignore
   } elsif ( ($Device,$Msg) = ($ThisLine =~ /^Device: ([^,]+), appears to lack SMART*/ )) {
       # ignore
#   } elsif ( ($Device,$Msg) = ($ThisLine =~ /^Device: ([^,]+), (.*)$/)) {
#      $ParamChanges{$Device}{$Msg}++;
   } elsif ( ($Device,$AttribType,$Code,$Name,undef,$NewVal) = ($ThisLine =~ /^Device: ([^,]+), SMART ([A-Za-z]+) Attribute: ([0-9]+) ([A-Za-z_]+) changed from ([0-9]+) to ([0-9]+)/)) {
      $ParamChanges{$Device}{"$AttribType: $Name ($Code)"}{$NewVal}++;
   }
}

if (keys %ParamChanges) {
   foreach $Device (sort keys %ParamChanges) {
      print "\n$Device :\n";
      foreach $Msg (sort keys %{$ParamChanges{$Device}}) {
         print "   $Msg changed to ";
         $vv="";
         foreach $Val (sort keys %{$ParamChanges{$Device}{$Msg}}) {
            if (! $vv eq "") {
               print "$vv, ";
            }
            $vv = "$Val";
            #$vv .= " ($ParamChanges{$Device}{$Msg}{$Val} times)";
         }
         print "$vv\n";
      }
   }
}

exit(0);

# vi: shiftwidth=3 tabstop=3 et

