#!/usr/bin/perl $HostName=$ARGV[0]; $Port=11012; $WarnTemp=50; $CritTemp=55; $WarnErr=1; $CritErr=10; $WarnReloc=6; $CritReloc=100; $Output=""; $State="UNKNOWN"; open (DATA, "tcpcat $HostName $Port 2>\&1 |"); while () { $Line=$_; chomp $Line; if ($Line =~ /tcpclient:/ || $Line eq "") { print "SMART UNKNOWN: $Line\n"; exit(255); } ($Disk,$DataType,$Value)=split(/:/,$Line,3); if ($DataType eq "status") { $Output="$Output $Disk:$Value"; if ($Value eq "PASSED" && $State eq "UNKNOWN") { $State="OK"; } if ($Value eq "FAILURE") { $State="CRITICAL"; } if ($Value =~ /IMPENDING FAILURE/ && $State ne "CRITICAL") { $State="WARNING"; } } if ($DataType =~ /-errors/) { $Output="$Output $Disk:$DataType:$Value"; if ($Value >= $WarnErr) { if ($State eq "OK") { $State="WARNING"; } } if ($Value >= $CritErr) { $State="CRITICAL"; } } if ($DataType eq "temp") { $Output="$Output $Disk:$DataType:$Value"; if ($Value >= $WarnTemp) { if ($State eq "OK") { $State="WARNING"; } } if ($Value >= $CritTemp) { $State="CRITICAL"; } } if ($DataType eq "relocate-count") { $Output="$Output $Disk:$DataType:$Value"; #hdc:relocate-count:615(FAILING_NOW) $RelocateCount=$Value; $RelocateCount =~ s/\(.*\)//g; $RelocateState=$Value; $RelocateState =~ s/.*\(//g; $RelocateState =~ s/\)//g; if ($RelocateState ne "PASSED") { if ($State eq "OK") { $State="WARNING"; } } if ($RelocateState eq "FAILING_NOW") { $State="CRITICAL"; } if ($RelocateCount >= $WarnReloc) { if ($State eq "OK") { $State="WARNING"; } } if ($RelocateCount >= $CritReloc) { $State="CRITICAL"; } } } close (DATA); $Output =~ s/^ //; if ($State eq "OK") { print "SMART OK: $Output\n"; exit (0); } elsif ($State eq "WARNING") { print "SMART WARNING: $Output\n"; exit (1); } elsif ($State eq "CRITICAL") { print "SMART CRITICAL: $Output\n"; exit(2); } else { print "SMART UNKNOWN: $Output\n"; exit(255); }