From a4b8372901ffcbd9b8e4cb84d6a70269f9733826 Mon Sep 17 00:00:00 2001 From: Jordi Sanfeliu Date: Wed, 20 Feb 2013 15:21:37 +0100 Subject: [PATCH] fixed to detect if a device name defined in 'disk' doesn't exist in the system --- lib/disk.pm | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/disk.pm b/lib/disk.pm index 4739c6c..8a9d1f7 100644 --- a/lib/disk.pm +++ b/lib/disk.pm @@ -33,6 +33,21 @@ sub disk_init { my $rrd = $config->{base_lib} . $package . ".rrd"; my $disk = $config->{disk}; + foreach my $k (sort keys %{$disk->{list}}) { + # values delimitted by ", " (comma + space) + my @dsk = split(', ', $disk->{list}->{$k}); + for(my $n = 0; $n < 8; $n++) { + if($dsk[$n]) { + my $d = trim($dsk[$n]); + $d =~ s/^\"//; + $d =~ s/\"$//; + next if -e $d; + logger("ERROR: $myself: invalid or inexistent device name '$d'."); + return; + } + } + } + my $info; my @ds; my @tmp; @@ -168,7 +183,14 @@ sub disk_update { } } close(IN); - $temp = `hddtemp -wqn $d` unless $temp; + if(!$temp) { + if(open(IN, "hddtemp -wqn $d |")) { + $temp = ; + close(IN); + } else { + logger("$myself: 'smartctl' failed to get data from '$d' and 'hddtemp' seems doesn't exist."); + } + } chomp($temp); } $rrdata .= ":$temp";