Fix latency tab bugs (#11787)

when there is no latency data
fix smokeping error
This commit is contained in:
Tony Murray
2020-06-07 23:18:18 -05:00
committed by GitHub
parent 7b93b386a3
commit 147ba0f00d
2 changed files with 9 additions and 4 deletions
+2 -2
View File
@@ -48,11 +48,11 @@ class Smokeping
{
if (is_null($this->files) && Config::has('smokeping.dir')) {
$dir = $this->generateFileName();
if (is_dir($dir)) {
if (is_dir($dir) && is_readable($dir)) {
foreach (array_diff(scandir($dir), ['.', '..']) as $file) {
if (stripos($file, '.rrd') !== false) {
if (strpos($file, '~') !== false) {
list($target, $slave) = explode('~', $this->filenameToHostname($file));
[$target, $slave] = explode('~', $this->filenameToHostname($file));
$this->files['in'][$target][$slave] = $file;
$this->files['out'][$slave][$target] = $file;
} else {
@@ -37,7 +37,8 @@ class LatencyController implements DeviceTab
{
public function visible(Device $device): bool
{
return true;
return Config::get('smokeping.integration') || DB::table('device_perf')
->where('device_id', $device->device_id)->exists();
}
public function slug(): string
@@ -61,7 +62,11 @@ class LatencyController implements DeviceTab
$to = Request::get('dtpickerto', Carbon::now()->format(Config::get('dateformat.byminute')));
$perf = $this->fetchPerfData($device, $from, $to);
$duration = abs(strtotime($perf->first()->date) - strtotime($perf->last()->date)) * 1000;
$duration = $perf && $perf->isNotEmpty()
? abs(strtotime($perf->first()->date) - strtotime($perf->last()->date)) * 1000
: 0;
$smokeping = new Smokeping($device);
$smokeping_tabs = [];