#!/usr/bin/perl
# rrd-smart.pl
# v1.0 - Nicolas AGIUS - 04/2010
# Usage : rrd-smart.pl /dev/hdax
#
###################################################################################
## Sonde RRD pour les indicateurs SMART
#
# Copyright (C) 2010 Nicolas AGIUS <nicolas_agius@yahoo.fr>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
#
###################################################################################

# Affiche les valeurs suivantes :
#
# RAW_VALUE, type COUNTER :
#   Reallocated_Sector_Ct
#   Spin_Retry_Count
# 
# VALUE, type GAUGE :
#   Raw_Read_Error_Rate
#   Seek_Error_Rate
# 
# RAW_VALUE, type GAUGE :
#    Temperature_Celsius


# Syntax
(scalar(@ARGV) == 1) or die "Usage : $0 /dev/hdax \n";

$device=shift;

(-e $device) or die "Device $device not found\n";


open(SMART, "/usr/sbin/smartctl -A $device|") or die "Can't read smartctl !\n";
while(<SMART>)
{

	if(/(Reallocated_Sector_Ct|Spin_Retry_Count|Temperature_Celsius)/)
	{
		@fields=split;
		print uc($fields[1])."=".$fields[9]."\n";  # Print RAW_VALUE
	}
	if(/(Raw_Read_Error_Rate|Seek_Error_Rate)/)
	{
		@fields=split;
		print uc($fields[1])."=".$fields[3]."\n";  # Print VALUE
	}
	

}
close(SMART);
exit;

