forked from hummypkg/webif
68 lines
1.7 KiB
Plaintext
Executable File
68 lines
1.7 KiB
Plaintext
Executable File
#!/mod/bin/jimsh
|
|
|
|
source /mod/webif/lib/setup
|
|
require system.class settings.class
|
|
|
|
set disk [system disk]
|
|
set settings [settings]
|
|
|
|
# Extract overall SMART status.
|
|
set smart ""
|
|
set line ""
|
|
# smartctl uses non-zero exit status to indicate health hence catch.
|
|
catch { set line [exec /bin/smartctl -H $disk | 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]
|
|
$settings _tval_setting "SMART_status" $smart
|
|
}
|
|
|
|
# Extract disk model.
|
|
if {[catch {set msg [exec /bin/smartctl -i $disk]}]} {
|
|
set msg ""
|
|
}
|
|
foreach line [split $msg "\n"] {
|
|
if {[string match "*Not in smartctl database*" $line]} continue
|
|
if {[string match "*: *" $line]} {
|
|
regsub -all -- {[[:space:]]+} $line " " line
|
|
lassign [split $line ":"] key val
|
|
if {$key ne "Device Model"} continue
|
|
$settings _tval_setting "SMART_model" [string trim $val]
|
|
}
|
|
}
|
|
|
|
# Extract disk attributes.
|
|
if {[catch {set msg [exec /bin/smartctl -A -f brief $disk]}]} {
|
|
set msg ""
|
|
}
|
|
set attrs {}
|
|
foreach line [split $msg "\n"] {
|
|
regsub -all -- {[[:space:]]+} $line " " line
|
|
regsub -all -- {^[[:space:]]+} $line "" line
|
|
lassign [split $line] id name flags val worst thresh when rval
|
|
if {![string is integer $id]} continue
|
|
set attrs($id) $rval
|
|
}
|
|
|
|
#puts "Attrs: ($attrs)"
|
|
puts "SMART: ($smart)"
|
|
|
|
foreach a {
|
|
{4 "startstop"}
|
|
{5 "realloc"}
|
|
{9 "hours"}
|
|
{10 "spinretry"}
|
|
{197 "pending"}
|
|
{198 "offline"}
|
|
} {
|
|
lassign $a id attr
|
|
if {![dict exists $attrs $id]} continue
|
|
puts -nonewline "$attr: $attrs($id) "
|
|
$settings _nval_setting "SMART_$attr" $attrs($id)
|
|
if {$attrs($id) < [$settings _nval_setting "SMART_ack_$attr"]} {
|
|
$settings _nval_setting "SMART_ack_$attr" $attrs($id)
|
|
}
|
|
}
|
|
puts ""
|
|
|