diff --git a/snmp/smart b/snmp/smart index f6c6813..2fd3c14 100755 --- a/snmp/smart +++ b/snmp/smart @@ -38,14 +38,17 @@ will be /etc/snmp/smart.config. Alternatively you can also specific a config via Anything starting with a # is comment. The format for variables is $variable=$value. Empty lines are ignored. Spaces and tabes at either the start or end of a line are ignored. Any -line with out a = or # are treated as a disk. +line with out a matched variable or # are treated as a disk. #This is a comment cache=/var/cache/smart smartctl=/usr/local/sbin/smartctl useSN=0 ada0 - ada1 + da5 /dev/da5 -d sat + twl0,0 /dev/twl0 -d 3ware,0 + twl0,1 /dev/twl0 -d 3ware,1 + twl0,2 /dev/twl0 -d 3ware,2 The variables are as below. @@ -54,8 +57,13 @@ The variables are as below. useSN = If set to 1, it will use the disks SN for reporting instead of the device name. 1 is the default. 0 will use the device name. +A disk line is can be as simple as just a disk name under /dev/. Such as in the config above +The line "ada0" would resolve to "/dev/ada0" and would be called with no special argument. If +a line has a space in it, everything before the space is treated as the disk name and is what +used for reporting and everything after that is used as the argument to be passed to smartctl. + If you want to guess at the configuration, call it with -g and it will print out what it thinks -it should be. +it should be. =cut @@ -194,25 +202,30 @@ my @configA=split(/\n/, $config_file); my $configA_int=0; while ( defined( $configA[$configA_int] ) ){ my $line=$configA[$configA_int]; + chomp($line); $line=~s/^[\t\s]+//; $line=~s/[\t\s]+$//; my ( $var, $val )=split(/=/, $line, 2); + my $matched; if ( $var eq 'cache' ){ $cache=$val; + $matched=1; } if ( $var eq 'smartctl' ){ $smartctl=$val; + $matched=1; } if ( $var eq 'useSN' ){ $useSN=$val; + $matched=1; } if ( !defined( $val ) ){ - push(@disks, $var); + push(@disks, $line); } $configA_int++; @@ -238,11 +251,22 @@ if ( ! defined( $opts{u} ) ){ } my $toReturn=''; -my $int=0; -while ( defined($disks[$int]) ) { - my $disk=$disks[$int]; +foreach my $line ( @disks ){ + my $disk; + my $name; + if ( $line =~ /\ / ){ + ($name, $disk)=split(/\ /, $line, 2); + }else{ + $disk=$line; + $name=$line; + } my $disk_sn=$disk; - my $output=`$smartctl -A /dev/$disk`; + my $output; + if ( $disk =~ /\// ){ + $output=`$smartctl -A $disk`; + }else{ + $output=`$smartctl -A /dev/$disk`; + } my %IDs=( '5'=>'null', '10'=>'null', @@ -333,7 +357,7 @@ while ( defined($disks[$int]) ) { my $selective=scalar grep(/Selective/, @outputA); # get the drive serial number, if needed - my $disk_id=$disk; + my $disk_id=$name; if ( $useSN ){ while (`$smartctl -i /dev/$disk` =~ /Serial Number:(.*)/g) { $disk_id = $1; @@ -345,7 +369,6 @@ while ( defined($disks[$int]) ) { .','.$IDs{'190'} .','.$IDs{'194'}.','.$IDs{'196'}.','.$IDs{'197'}.','.$IDs{'198'}.','.$IDs{'199'}.','.$IDs{'231'}.','.$IDs{'233'}.','. $completed.','.$interrupted.','.$read_failure.','.$unknown_failure.','.$extended.','.$short.','.$conveyance.','.$selective."\n"; - $int++; } if ( ! $noWrite ){