From 147ba0f00dad5ded569966430dbad529e82d05d5 Mon Sep 17 00:00:00 2001 From: Tony Murray Date: Sun, 7 Jun 2020 23:18:18 -0500 Subject: [PATCH] Fix latency tab bugs (#11787) when there is no latency data fix smokeping error --- LibreNMS/Util/Smokeping.php | 4 ++-- app/Http/Controllers/Device/Tabs/LatencyController.php | 9 +++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/LibreNMS/Util/Smokeping.php b/LibreNMS/Util/Smokeping.php index 43c5a3124a..27b6c7ab03 100644 --- a/LibreNMS/Util/Smokeping.php +++ b/LibreNMS/Util/Smokeping.php @@ -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 { diff --git a/app/Http/Controllers/Device/Tabs/LatencyController.php b/app/Http/Controllers/Device/Tabs/LatencyController.php index 094a7441c6..b3b987cf38 100644 --- a/app/Http/Controllers/Device/Tabs/LatencyController.php +++ b/app/Http/Controllers/Device/Tabs/LatencyController.php @@ -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 = [];