Skip to content

Commit

Permalink
fixed fetching of status
Browse files Browse the repository at this point in the history
  • Loading branch information
sukhbir-singh committed Jul 6, 2018
1 parent accc55f commit 26aa787
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 17 deletions.
26 changes: 19 additions & 7 deletions lib/smart_statuses/smart_test_util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ def stats
@disks = DiskUtils.stats
response = []
@disks.each_with_index do |disk, index|
status = read_smart_status(get_created_file_path(disk[:device]))
status = fetch_status(disk[:device])
next if status.blank?
color = get_color(status)
response << { model: disk[:model], device: disk[:device],
response << { model: disk[:model], device: disk[:device],
health_check: status, color: color }
end
return response
end

def get_created_file_path(device)
def fetch_status(device)
return nil if device.blank?
status_file = Rails.root+Dir["plugins/*smart_statuses/db/smartctl-"+device[5..-1]][0]
read_smart_status(status_file)
status = `/var/hda/apps/0gjocmmq4k/elevated/smart-details #{device[5..-1]}`
read_streamed_smart_status(status)
end

def sample_stats
Expand All @@ -25,7 +25,7 @@ def sample_stats
@disks.each_with_index do |disk, index|
status = read_smart_status(get_sample_file_path(index))
color = get_color(status)
response << { model: disk[:model], device: disk[:device],
response << { model: disk[:model], device: disk[:device],
health_check: status, color: color }
end
return response
Expand Down Expand Up @@ -60,5 +60,17 @@ def read_smart_status(filepath)
return IO.readlines(filepath)[line_num + 1][50..-1]
end
end

def read_streamed_smart_status(status)
return "Some Error Occurred !!" if status.blank?
strings = status.split("\n")
line_num = strings.index { |line| line =~ /START OF READ SMART DATA SECTION/ }

if line_num.blank?
return "Device Lacks SMART Compatibility."
else
return strings[line_num + 1][50..-1]
end
end
end
end
end
17 changes: 7 additions & 10 deletions script/fetch-smart-status
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
mkdir -p elevated
cd elevated
cat > elevated-script << 'EOF'

lsblk -o name,type | grep disk | awk '{print $1;}' >> disk_names
cat > smart-details << 'EOF'

while read line
do
smartctl -H '/dev/'$line > '/db/smartctl-'$line
done < disk_names

drive=$1

smartctl -H "/dev/$drive"

EOF
chmod +x elevated-script
sudo ./elevated-script
cd ..
rm -rf elevated

chmod +x smart-details

0 comments on commit 26aa787

Please sign in to comment.