#!/usr/bin/perl

$pipenm = "isi_radish -tqv " . $ARGV[0] . "|";

open (H, $pipenm);

print
"Bay/SN:      OnTheFly Hard-ECC--Soft  OffTrack Seek---OL  Temp  Prob/Alloc\n";

$bay = "?";
$ser = "????????";
$ecc = "__/____";
$ot  = "__/____";
$otf = "__/____";
$skp = "__/____";
$sec = "__/____";
$ols = "__/____";
$rac = "__/____";
$pbc = "__/____";
$hot = "__/____";

while (<H>) {
	if ((/SMART data \(bay (\S+)\)/) ||
	    (/SMART data \(Bay ([^\/]+)\/.*/))
	{ # old and new radish support
		$bay = $1;
	}
	if (/Bay.+\/twed.+ SN:([^ ,]+)/) {
		$ser = $1;
	}
	if ((/On The Fly: ([^\)]+\))/) || 
	    (/Raw Read Error Rate: ([^\)]+\))/))
	{ # maxtor and ibm support
		$otf = $1;
	}
	if (/ECC Errors: ([^\)]+\))/)
	{
		$ecc = $1;
	}
	if (/Soft ECC Correction: ([^\)]+\))/)
	{
		$sec = $1;
	}
	if (/Off-track Errors: ([^\)]+\))/)
	{
		$ot = $1;
	}
	if ((/Seek Performance: ([^\)]+\))/)
	    && !(/Offline/))
	{
		$skp = $1;
	}
	if (/Offline Seek Performance: ([^\)]+\))/)
	{
		$ols = $1;
	}
	if (/Reallocation Count: ([^\)]+\))/)
	{
		$rac = $1;
	}
	if (/Probational Count: ([^\)]+\))/)
	{
		$pbc = $1;
	}
	if (/HDD Temperature: ([^\)]+\))/)
	{
		$hot = $1;
	}
	if (/cksums/)
	{
		$ecc =~ s-/.. vs .. -/-;
		$ot  =~ s-/.. vs .. -/-;
		$otf =~ s-/.. vs .. -/-;
		$skp =~ s-/.. vs .. -/-;
		$sec =~ s-/.. vs .. -/-;
		$ols =~ s-/.. vs .. -/-;
		$rac =~ s-/.. vs .. -/-;
		$pbc =~ s-/.. vs .. -/-;
		$hot =~ s-/.. vs .. -/-;

		$ecc =~ s/\(raw //;
		$ot  =~ s/\(raw //;
		$otf =~ s/\(raw //;
		$skp =~ s/\(raw //;
		$sec =~ s/\(raw //;
		$ols =~ s/\(raw //;
		$rac =~ s/\(raw //;
		$pbc =~ s/\(raw //;
		$hot =~ s/\(raw //;

		$ecc =~ s/\)//;
		$ot  =~ s/\)//;
		$otf =~ s/\)//;
		$skp =~ s/\)//;
		$sec =~ s/\)//;
		$ols =~ s/\)//;
		$rac =~ s/\)//;
		$pbc =~ s/\)//;
		$hot =~ s/\)//;

		#custom -- remove always-zero end from offline-seek
		$ols =~ s-/0000--;
		#custom -- remove ratings from probation/realloc
		$pbc =~ s-../--;
		$rac =~ s-../--;
		#custom -- remove ratings from temp
		$hot =~ s-../--;

		print "$bay/$ser:  $otf $ecc $sec  $ot $skp $ols  $hot  $pbc $rac\n";

		$ecc = "__/____";
		$ot  = "__/____";
		$otf = "__/____";
		$skp = "__/____";
		$sec = "__/____";
		$ols = "__/____";
		$rac = "__/____";
		$pbc = "__/____";
		$hot = "__/____";
	}
}
