mirror of https://github.com/MISP/MISP
fix: [widget] Typo in MispSystemResourceWidget
parent
a368e3196f
commit
e93767d814
|
@ -7,41 +7,43 @@ class MispSystemResourceWidget
|
|||
public $width = 3;
|
||||
public $height = 3;
|
||||
public $params = array(
|
||||
'treshold' => 'Treshold for disk space'
|
||||
'threshold' => 'Threshold for disk space'
|
||||
);
|
||||
public $description = 'Basic widget showing some system server statistics.';
|
||||
public $cacheLifetime = false;
|
||||
public $autoRefreshDelay = 30;
|
||||
public $placeholder =
|
||||
'{
|
||||
"treshold": "85"
|
||||
"threshold": "85"
|
||||
}';
|
||||
|
||||
public function handler($user, $options = array())
|
||||
public function handler(array $user, $options = array())
|
||||
{
|
||||
// Keep BC with typo value
|
||||
$threshold = isset($options['threshold']) ? $options['threshold'] : (isset($options['treshold']) ? $options['treshold'] : 85);
|
||||
|
||||
$drive = round((1 - disk_free_space(getcwd())/disk_total_space(getcwd()))*100,2);
|
||||
$cwd = getcwd();
|
||||
$drive = round((1 - disk_free_space($cwd)/disk_total_space($cwd))*100,2);
|
||||
$driveFree = $drive . "%";
|
||||
$driveFreeClass = "";
|
||||
if ($drive > intval($options['treshold'])) {
|
||||
$driveFree = $drive . "% - [Above Treshhold]";
|
||||
if ($drive > intval($threshold)) {
|
||||
$driveFree = $drive . "% - [Above Threshold]";
|
||||
$driveFreeClass = "red";
|
||||
}
|
||||
|
||||
$sysload = sys_getloadavg();
|
||||
|
||||
preg_match('#MemFree:[\s\t]+([\d]+)\s+kB#', file_get_contents('/proc/meminfo'), $matches);
|
||||
$meminfo = file_get_contents('/proc/meminfo');
|
||||
preg_match('#MemFree:[\s\t]+([\d]+)\s+kB#', $meminfo, $matches);
|
||||
$memoryFree = $matches[1];
|
||||
preg_match('#MemTotal:[\s\t]+([\d]+)\s+kB#', file_get_contents('/proc/meminfo'), $matches);
|
||||
preg_match('#MemTotal:[\s\t]+([\d]+)\s+kB#', $meminfo, $matches);
|
||||
$memoryTotal = $matches[1];
|
||||
|
||||
$data = array(
|
||||
array( 'title' => __('User'), 'value' => $user['email']),
|
||||
array( 'title' => __('System'), 'value' => php_uname()),
|
||||
array( 'title' => __('Disk usage'), 'value' => h($driveFree), 'class' => $driveFreeClass),
|
||||
array( 'title' => __('Load'), 'value' => h($sysload[0] . " - " . $sysload[1] . " - " . $sysload[2])),
|
||||
array( 'title' => __('Memory'), 'value' => h(round($memoryFree/1024,2) . "M free (" . round((1 - $memoryFree/$memoryTotal)*100,2) . "% used)")),
|
||||
);
|
||||
array( 'title' => __('User'), 'value' => $user['email']),
|
||||
array( 'title' => __('System'), 'value' => php_uname()),
|
||||
array( 'title' => __('Disk usage'), 'value' => h($driveFree), 'class' => $driveFreeClass),
|
||||
array( 'title' => __('Load'), 'value' => h(implode(" - ", sys_getloadavg()))),
|
||||
array( 'title' => __('Memory'), 'value' => h(round($memoryFree / 1024,2) . " MB free (" . round((1 - $memoryFree/$memoryTotal)*100,2) . " % used)")),
|
||||
);
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue