mirror of
https://github.com/unraid/webgui.git
synced 2026-03-09 04:21:27 -05:00
Add ceiling to temperature and utilization checks (ignore insane values)
This commit is contained in:
@@ -12,12 +12,8 @@
|
||||
?>
|
||||
<?
|
||||
$docroot = $docroot ?: $_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp';
|
||||
require_once "$docroot/webGui/include/Wrappers.php";
|
||||
|
||||
function getVal(&$ref,$n,$d) {
|
||||
global $var;
|
||||
$val = $ref[$n] ?? -1;
|
||||
return $val!==-1 ? $val : ($var[$n] ?? $d);
|
||||
}
|
||||
function normalize($type,$count) {
|
||||
$words = explode('_',$type);
|
||||
foreach ($words as &$word) $word = $word==strtoupper($word) ? $word : preg_replace(['/^(ct|cnt)$/','/^blk$/'],['count','block'],strtolower($word));
|
||||
@@ -29,9 +25,9 @@ function my_insert(&$source,$string) {
|
||||
function my_smart(&$source,$name,$page) {
|
||||
global $var,$disks,$path,$failed,$numbers,$saved;
|
||||
$disk = &$disks[$name];
|
||||
$select = getVal($disk,'smSelect',0);
|
||||
$level = getVal($disk,'smLevel',1);
|
||||
$events = explode('|',getVal($disk,'smEvents',$numbers));
|
||||
$select = get_value($disk,'smSelect',0);
|
||||
$level = get_value($disk,'smLevel',1);
|
||||
$events = explode('|',get_value($disk,'smEvents',$numbers));
|
||||
$title = '';
|
||||
$thumb = 'good';
|
||||
$smart = "state/smart/$name";
|
||||
@@ -78,9 +74,8 @@ switch ($_POST['cmd']) {
|
||||
case 'disk':
|
||||
$i = 1;
|
||||
$var = [];
|
||||
$disks = @array_filter(parse_ini_file('state/disks.ini',true),'active_disks');
|
||||
$devs = @parse_ini_file('state/devs.ini',true);
|
||||
$saved = @parse_ini_file('state/monitor.ini',true);
|
||||
$disks = array_filter(parse_ini_file('state/disks.ini',true),'active_disks');
|
||||
$devs = parse_ini_file('state/devs.ini',true);
|
||||
require_once "$docroot/webGui/include/CustomMerge.php";
|
||||
require_once "$docroot/webGui/include/Preselect.php";
|
||||
$slots = $_POST['slots'];
|
||||
@@ -122,9 +117,10 @@ case 'disk':
|
||||
my_insert($row5[$n],"<img src=$path/$state.png>");
|
||||
break;}
|
||||
$temp = $disk['temp'];
|
||||
$hot = $disk['hotTemp'] ?? $_POST['hot'];
|
||||
$max = $disk['maxTemp'] ?? $_POST['max'];
|
||||
$heat = $temp>=$max && $max>0 ? 'max' : ($temp>=$hot && $hot>0 ? 'hot' : '');
|
||||
$hot = $disk['hotTemp'] ?? $_POST['hot'];
|
||||
$max = $disk['maxTemp'] ?? $_POST['max'];
|
||||
$top = $_POST['top'] ?? 120;
|
||||
$heat = exceed($temp,$max,$top) ? 'max' : (exceed($temp,$hot,$top) ? 'hot' : '');
|
||||
if ($heat)
|
||||
my_insert($row6[$n],"<span class='heat-img'><img src='$path/$heat.png'></span><span class='heat-text' style='display:none'>".my_temp($temp,$_POST['unit'])."</span>");
|
||||
else
|
||||
@@ -136,13 +132,14 @@ case 'disk':
|
||||
$devRow = function($n,$disk) use (&$row4,&$row6,&$row7,$path) {
|
||||
$hot = $_POST['hot'];
|
||||
$max = $_POST['max'];
|
||||
$top = $_POST['top'] ?? 120;
|
||||
$name = $dev['device'];
|
||||
$port = substr($name,-2)!='n1' ? $name : substr($name,0,-2);
|
||||
$smart = "state/smart/$name";
|
||||
$state = exec("hdparm -C ".escapeshellarg("/dev/$port")."|grep -Po 'active|unknown'") ? 'blue-on' : 'blue-blink';
|
||||
if ($state=='blue-on') my_smart($row7[$n],$name,'New');
|
||||
$temp = file_exists($smart) ? exec("awk 'BEGIN{t=\"*\"} \$1==190||\$1==194{t=\$10;exit};\$1==\"Temperature:\"{t=\$2;exit} END{print t}' ".escapeshellarg($smart)) : '*';
|
||||
$heat = $temp>=$max && $max>0 ? 'max' : ($temp>=$hot && $hot>0 ? 'hot' : '');
|
||||
$heat = exceed($temp,$max,$top) ? 'max' : (exceed($temp,$hot,$top) ? 'hot' : '');
|
||||
if ($heat)
|
||||
my_insert($row6[$n],"<span class='heat-img'><img src='$path/$heat.png'></span><span class='heat-text' style='display:none'>".my_temp($temp,$_POST['unit'])."</span>");
|
||||
else
|
||||
|
||||
@@ -11,7 +11,11 @@
|
||||
*/
|
||||
?>
|
||||
<?
|
||||
$disks = []; $var = [];
|
||||
$docroot = $docroot ?: $_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp';
|
||||
require_once "$docroot/webGui/include/CustomMerge.php";
|
||||
require_once "$docroot/webGui/include/Wrappers.php";
|
||||
require_once "$docroot/webGui/include/Preselect.php";
|
||||
|
||||
function normalize($text, $glue='_') {
|
||||
$words = explode($glue,$text);
|
||||
@@ -35,10 +39,6 @@ function spindownDelay($port) {
|
||||
function append(&$ref, &$info) {
|
||||
if ($info) $ref .= ($ref ? " " : "").$info;
|
||||
}
|
||||
$disks = []; $var = [];
|
||||
require_once "$docroot/webGui/include/CustomMerge.php";
|
||||
require_once "$docroot/webGui/include/Wrappers.php";
|
||||
require_once "$docroot/webGui/include/Preselect.php";
|
||||
$name = $_POST['name'] ?? '';
|
||||
$port = $_POST['port'] ?? '';
|
||||
if ($name) {
|
||||
@@ -58,6 +58,7 @@ case "attributes":
|
||||
$unraid = parse_plugin_cfg('dynamix',true);
|
||||
$max = $disk['maxTemp'] ?? $unraid['display']['max'];
|
||||
$hot = $disk['hotTemp'] ?? $unraid['display']['hot'];
|
||||
$top = $_POST['top'] ?? 120;
|
||||
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);
|
||||
@@ -69,7 +70,7 @@ case "attributes":
|
||||
$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], [190,194])) {
|
||||
if ($info[9]>=$max && $max>0) $color = " class='alert'"; elseif ($info[9]>=$hot && $hot>0) $color = " class='warn'";
|
||||
if (exceed($info[9],$max,$top)) $color = " class='alert'"; elseif (exceed($info[9],$hot,$top)) $color = " class='warn'";
|
||||
}
|
||||
if ($info[8]=='-') $info[8] = 'Never';
|
||||
if ($info[0]==9 && is_numeric($info[9])) duration($info[9]);
|
||||
@@ -88,7 +89,7 @@ case "attributes":
|
||||
switch ($name) {
|
||||
case 'Temperature':
|
||||
$temp = strtok($value,' ');
|
||||
if ($temp>=$max && $max>0) $color = " class='alert'"; elseif ($temp>=$hot && $hot>0) $color = " class='warn'";
|
||||
if (exceed($temp,$max)) $color = " class='alert'"; elseif (exceed($temp,$hot)) $color = " class='warn'";
|
||||
break;
|
||||
case 'Power on hours':
|
||||
if (is_numeric($value)) duration($value);
|
||||
|
||||
@@ -21,13 +21,11 @@ function parse_plugin_cfg($plugin, $sections=false) {
|
||||
$cfg = file_exists($ram) ? parse_ini_file($ram, $sections) : [];
|
||||
return file_exists($rom) ? array_replace_recursive($cfg, parse_ini_file($rom, $sections)) : $cfg;
|
||||
}
|
||||
|
||||
function parse_cron_cfg($plugin, $job, $text = "") {
|
||||
$cron = "/boot/config/plugins/$plugin/$job.cron";
|
||||
if ($text) file_put_contents($cron, $text); else @unlink($cron);
|
||||
exec("/usr/local/sbin/update_cron");
|
||||
}
|
||||
|
||||
function agent_fullname($agent, $state) {
|
||||
switch ($state) {
|
||||
case 'enabled' : return "/boot/config/plugins/dynamix/notifications/agents/$agent";
|
||||
@@ -35,13 +33,11 @@ function agent_fullname($agent, $state) {
|
||||
default : return $agent;
|
||||
}
|
||||
}
|
||||
|
||||
function get_plugin_attr($attr, $file) {
|
||||
global $docroot;
|
||||
exec("$docroot/plugins/dynamix.plugin.manager/scripts/plugin ".escapeshellarg($attr)." ".escapeshellarg($file), $result, $error);
|
||||
if ($error===0) return $result[0];
|
||||
}
|
||||
|
||||
function plugin_update_available($plugin, $os=false) {
|
||||
$local = get_plugin_attr('version', "/var/log/plugins/$plugin.plg");
|
||||
$remote = get_plugin_attr('version', "/tmp/plugins/$plugin.plg");
|
||||
@@ -52,13 +48,11 @@ function plugin_update_available($plugin, $os=false) {
|
||||
if (version_compare($server, $unraid, '>=')) return $remote;
|
||||
}
|
||||
}
|
||||
|
||||
function get_value(&$object,$name,$default) {
|
||||
function get_value(&$object, $name, $default) {
|
||||
global $var;
|
||||
$value = $object[$name] ?? -1;
|
||||
return $value!==-1 ? $value : ($var[$name] ?? $default);
|
||||
}
|
||||
|
||||
function get_ctlr_options(&$type, &$disk) {
|
||||
if (!$type) return;
|
||||
$ports = [];
|
||||
@@ -70,4 +64,7 @@ function get_ctlr_options(&$type, &$disk) {
|
||||
function port_name($port) {
|
||||
return substr($port,-2)!='n1' ? $port : substr($port,0,-2);
|
||||
}
|
||||
function exceed($value, $limit, $top=100) {
|
||||
return ($value>$limit && $limit>0 && $value<=$top);
|
||||
}
|
||||
?>
|
||||
|
||||
@@ -30,6 +30,7 @@ $high1 = $unraid['display']['critical'];
|
||||
$high2 = $unraid['display']['warning'];
|
||||
$server = strtoupper($var['NAME']);
|
||||
$errors = [];
|
||||
$top = 120;
|
||||
|
||||
function plus($val,$word,$last) {
|
||||
return $val>0 ? (($val||$last) ? ($val.' '.$word.($val!=1?'s':'').($last ?'':', ')) : '') : '';
|
||||
@@ -90,11 +91,11 @@ function read_write_parity_log($epoch,$duration,$speed,$status,$error) {
|
||||
return str_replace("\n","",$line);
|
||||
}
|
||||
function check_temp($name,$temp,$text,$info) {
|
||||
global $notify,$disks,$saved,$unraid,$server;
|
||||
global $notify,$disks,$saved,$unraid,$server,$top;
|
||||
$disk = &$disks[$name];
|
||||
$hot = $disk['hotTemp'] ?? $unraid['display']['hot'];
|
||||
$max = $disk['maxTemp'] ?? $unraid['display']['max'];
|
||||
$warn = $temp>=$max && $max>0 ? 'alert' : ($temp>=$hot && $hot>0 ? 'warning' : '');
|
||||
$warn = exceed($temp,$max,$top) ? 'alert' : (exceed($temp,$hot,$top) ? 'warning' : '');
|
||||
$item = 'temp';
|
||||
$last = $saved[$item][$name] ?? 0;
|
||||
if ($warn) {
|
||||
@@ -103,7 +104,7 @@ function check_temp($name,$temp,$text,$info) {
|
||||
$saved[$item][$name] = $max>0 && $temp<=$max ? $max : $temp;
|
||||
}
|
||||
} else {
|
||||
if ($last) {
|
||||
if ($last && $temp<=$top) {
|
||||
exec("$notify -e ".escapeshellarg("unRAID $text message")." -s ".escapeshellarg("Notice [$server] - $text returned to normal temperature")." -d ".escapeshellarg("$info"));
|
||||
unset($saved[$item][$name]);
|
||||
}
|
||||
@@ -171,9 +172,9 @@ function check_usage($name,$used,$text,$info) {
|
||||
global $notify,$disks,$saved,$unraid,$server;
|
||||
if ($used == -1) return;
|
||||
$disk = &$disks[$name];
|
||||
$warning = $disk['warning'] ?? $unraid['display']['warning'];
|
||||
$warning = $disk['warning'] ?? $unraid['display']['warning'];
|
||||
$critical = $disk['critical'] ?? $unraid['display']['critical'];
|
||||
$warn = $used>=$critical && $critical>0 ? 'alert' : ($used>=$warning && $warning>0 ? 'warning' : '');
|
||||
$warn = exceed($used,$critical) ? 'alert' : (exceed($used,$warning) ? 'warning' : '');
|
||||
$item = 'used';
|
||||
$last = $saved[$item][$name] ?? 0;
|
||||
if ($warn) {
|
||||
@@ -182,7 +183,7 @@ function check_usage($name,$used,$text,$info) {
|
||||
$saved[$item][$name] = $critical>0 && $used<=$critical ? $critical : $used;
|
||||
}
|
||||
} else {
|
||||
if ($last) {
|
||||
if ($last && $used<=100) {
|
||||
exec("$notify -e ".escapeshellarg("unRAID $text message")." -s ".escapeshellarg("Notice [$server] - $text returned to normal utilization level")." -d ".escapeshellarg("$info"));
|
||||
unset($saved[$item][$name]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user