#!/mod/bin/jimsh
package require cgi
source /mod/webif/lib/setup
require system.class
puts "Content-Type: text/html"
puts ""
header
set space [system diskspace]
set device [string range [lindex $space 5] 0 end-1]
set smart Unknown
set line ""
# smartctl uses non-zero exit status to indicate health hence catch.
catch { set line [exec /mod/bin/smartctl -H $device | sed -n 5p] } msg
if {$msg ne "" && $line eq ""} { set line $msg }
if {$line ne ""} {
set smart [string range [lindex [split $line :] 1] 1 end]
}
puts "
SMART data read from device $device
Disk Information
SMART Status $smart
"
foreach line [split [exec /mod/bin/smartctl -i $device] "\n"] {
if {[string match "*Not in smartctl database*" $line]} continue
if {[string match "*: *" $line]} {
regsub -all -- {[[:space:]]+} $line " " line
set fields [split $line ":"]
puts "[lindex $fields 0] "
puts "[join [lrange $fields 1 end] :] "
}
}
puts {
Attributes
ID
Name
Flags
Raw Value
Value
Worst
Thresh
Type
Updated
When Failed
}
#set flag_autokeep 0x20
#set flag_count 0x10
#set flag_rate 0x08
#set flag_speed 0x04
#set flag_online 0x02
#set flag_prefailure 0x01
set flaglist [split "POSRCK" ""]
set flagdescr [list \
"P prefailure warning" \
"O updated online" \
"S speed/performance" \
"R error rate" \
"C event count" \
"K auto-keep" \
]
proc flags {val} {
global flaglist flagdescr
set f ""
set fx ""
loop i 0 [llength $flaglist] {
if {[expr $val & (1 << $i)]} {
append f [lindex $flaglist $i]
append fx "[lindex $flagdescr $i]\n"
} else {
append f "-"
}
}
return "$f "
}
set i 0
foreach line [split [exec /mod/bin/smartctl -A $device] "\n"] {
regsub -all -- {[[:space:]]+} $line " " line
regsub -all -- {^[[:space:]]+} $line "" line
if {[incr i] < 8} continue
lassign [split $line] \
id name flags val worst thresh type updated when rval
set class normal
switch $id {
5 { if {$rval > 0} { set class orangeshade } }
197 { if {$rval > 0} { set class redshade } }
198 { if {$rval > 0} { set class redshade } }
}
puts ""
puts "
$id
$name
[flags $flags]
$rval
$val
$worst
$thresh
$type
$updated
$when
"
}
puts {
Self-test logs
No.
Description
Status
Remaining
When
First Error LBA
}
set i 0
foreach line [split [exec /mod/bin/smartctl -l selftest $device] "\n"] {
regsub -all -- {[[:space:]][[:space:]]+} $line "|" line
if {[incr i] < 7} continue
lassign [split $line "|"] id name status remaining when lba
puts "
$id
$name
$status
$remaining
$when
$lba
"
}
puts {
}
footer