mirror of
https://github.com/unraid/webgui.git
synced 2026-04-23 18:48:49 -05:00
Support temperature readings+warnings in Dashboard array overview
This commit is contained in:
@@ -13,6 +13,11 @@
|
||||
<?
|
||||
$docroot = $docroot ?: $_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp';
|
||||
|
||||
function getVal(&$ref,$n,$d) {
|
||||
global $var;
|
||||
$val = $ref[$n] ?? -1;
|
||||
return $val!==-1 ? $val : ($var[$n] ?? $d);
|
||||
}
|
||||
function normalize($text, $glue='_') {
|
||||
$words = explode($glue,$text);
|
||||
foreach ($words as &$word) $word = $word==strtoupper($word) ? $word : preg_replace(['/^(ct|cnt)$/','/^blk$/'],['count','block'],strtolower($word));
|
||||
@@ -28,19 +33,12 @@ function duration(&$hrs) {
|
||||
function spindownDelay($port) {
|
||||
$disks = parse_ini_file('state/disks.ini',true);
|
||||
foreach ($disks as $disk) {
|
||||
if ($disk['device']==$port) { file_put_contents("/var/tmp/diskSpindownDelay.{$disk['idx']}", $disk['spindownDelay']); break; }
|
||||
$name = substr($disk['device'],-2)!='n1' ? $disk['device'] : substr($disk['device'],0,-2);
|
||||
if ($name==$port) {file_put_contents("/var/tmp/diskSpindownDelay.{$disk['idx']}", $disk['spindownDelay']); break;}
|
||||
}
|
||||
}
|
||||
function get(&$ref,$n,$d) {
|
||||
global $var;
|
||||
$val = $ref[$n] ?? -1; if ($val==-1) $val = $var[$n] ?? $d;
|
||||
return $val;
|
||||
}
|
||||
function exist(&$ref) {
|
||||
return isset($ref) && strlen($ref);
|
||||
}
|
||||
function append(&$ref, &$info) {
|
||||
if (isset($info)) $ref .= ($ref ? " " : "").$info;
|
||||
if ($info) $ref .= ($ref ? " " : "").$info;
|
||||
}
|
||||
$disks = []; $var = [];
|
||||
require_once "$docroot/webGui/include/CustomMerge.php";
|
||||
@@ -48,27 +46,27 @@ $name = $_POST['name'] ?? '';
|
||||
$port = $_POST['port'] ?? '';
|
||||
if ($name) {
|
||||
$disk = &$disks[$name];
|
||||
$type = get($disk,'smType','');
|
||||
$type = getVal($disk,'smType','');
|
||||
if ($type) {
|
||||
$ports = [];
|
||||
if (exist($disk['smDevice'])) $port = $disk['smDevice'];
|
||||
if (exist($disk['smPort1'])) $ports[] = $disk['smPort1'];
|
||||
if (exist($disk['smPort2'])) $ports[] = $disk['smPort2'];
|
||||
if (exist($disk['smPort3'])) $ports[] = $disk['smPort3'];
|
||||
if (!empty($disk['smDevice'])) $port = $disk['smDevice'];
|
||||
if (!empty($disk['smPort1'])) $ports[] = $disk['smPort1'];
|
||||
if (!empty($disk['smPort2'])) $ports[] = $disk['smPort2'];
|
||||
if (!empty($disk['smPort3'])) $ports[] = $disk['smPort3'];
|
||||
if ($ports) $type .= ','.implode($disk['smGlue'] ?? ',',$ports);
|
||||
}
|
||||
}
|
||||
if (substr($port,-2)=='n1') $port = substr($port,0,-2);
|
||||
switch ($_POST['cmd']) {
|
||||
case "attributes":
|
||||
require_once "$docroot/webGui/include/Wrappers.php";
|
||||
require_once "$docroot/webGui/include/Preselect.php";
|
||||
$select = get($disk,'smSelect',0);
|
||||
$level = get($disk,'smLevel',1);
|
||||
$events = explode('|',$disk['smEvents'] ?? $var['smEvents'] ?? $numbers);
|
||||
$temps = [190,194];
|
||||
$select = getVal($disk,'smSelect',0);
|
||||
$level = getVal($disk,'smLevel',1);
|
||||
$events = explode('|',getVal($disk,'smEvents',$numbers));
|
||||
$unraid = parse_plugin_cfg('dynamix',true);
|
||||
$max = $unraid['display']['max'];
|
||||
$hot = $unraid['display']['hot'];
|
||||
$max = $disk['maxTemp'] ?? $unraid['display']['max'];
|
||||
$hot = $disk['hotTemp'] ?? $unraid['display']['hot'];
|
||||
exec("smartctl -A $type ".escapeshellarg("/dev/$port")."|awk 'NR>4'",$output);
|
||||
if (strpos($output[0], 'SMART Attributes Data Structure')===0) {
|
||||
$output = array_slice($output, 3);
|
||||
@@ -79,8 +77,8 @@ case "attributes":
|
||||
$color = "";
|
||||
$highlight = strpos($info[8],'FAILING_NOW')!==false || ($select ? $info[5]>0 && $info[3]<=$info[5]*$level : $info[9]>0);
|
||||
if (in_array($info[0], $events) && $highlight) $color = " class='warn'";
|
||||
elseif (in_array($info[0], $temps)) {
|
||||
if ($info[9]>=$max) $color = " class='alert'"; elseif ($info[9]>=$hot) $color = " class='warn'";
|
||||
elseif (in_array($info[0], [190,194])) {
|
||||
if ($info[9]>=$max && $max>0) $color = " class='alert'"; elseif ($info[9]>=$hot && $hot>0) $color = " class='warn'";
|
||||
}
|
||||
if ($info[8]=='-') $info[8] = 'Never';
|
||||
if ($info[0]==9 && is_numeric($info[9])) duration($info[9]);
|
||||
@@ -93,7 +91,19 @@ case "attributes":
|
||||
foreach ($output as $line) {
|
||||
if (strpos($line,':')===false) continue;
|
||||
list($name,$value) = explode(':', $line);
|
||||
echo "<tr><td>-</td><td>".ucfirst(strtolower($name))."</td><td colspan='8'>".trim($value)."</td></tr>";
|
||||
$name = ucfirst(strtolower($name));
|
||||
$value = trim($value);
|
||||
$color = '';
|
||||
switch ($name) {
|
||||
case 'Temperature':
|
||||
$temp = strtok($value,' ');
|
||||
if ($temp>=$max && $max>0) $color = " class='alert'"; elseif ($temp>=$hot && $hot>0) $color = " class='warn'";
|
||||
break;
|
||||
case 'Power on hours':
|
||||
if (is_numeric($value)) duration($value);
|
||||
break;
|
||||
}
|
||||
echo "<tr{$color}><td>-</td><td>$name</td><td colspan='8'>$value</td></tr>";
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -123,7 +133,7 @@ case "identify":
|
||||
exec("smartctl -H $type ".escapeshellarg("/dev/$port")."|grep -Pom1 '^SMART.*: [A-Z]+'|sed 's:self-assessment test result::'",$output);
|
||||
$empty = true;
|
||||
foreach ($output as $line) {
|
||||
if (!strlen($line)) continue;
|
||||
if (!$line) continue;
|
||||
if (strpos($line,'VALID ARGUMENTS')!==false) break;
|
||||
list($title,$info) = array_map('trim', explode(':', $line, 2));
|
||||
if (in_array($info,$passed)) $info = "<span class='green-text'>Passed</span>";
|
||||
|
||||
Reference in New Issue
Block a user