From 8ca0309ebffbd3126b86c239ba0435f38bcb8b59 Mon Sep 17 00:00:00 2001 From: Tony Murray Date: Tue, 9 Jun 2020 11:10:07 -0500 Subject: [PATCH] Fix smokeping slave not found causing error (#11799) --- LibreNMS/Util/Smokeping.php | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/LibreNMS/Util/Smokeping.php b/LibreNMS/Util/Smokeping.php index 27b6c7ab03..e183385c3d 100644 --- a/LibreNMS/Util/Smokeping.php +++ b/LibreNMS/Util/Smokeping.php @@ -86,21 +86,27 @@ class Smokeping public function otherGraphs($direction) { $remote = $direction == 'in' ? 'src' : 'dest'; - $data = array_keys(array_filter($this->getFiles()[$direction][$this->device->hostname], function ($file) { - return Str::contains($file, '~'); - })); + $data = []; + foreach ($this->getFiles()[$direction][$this->device->hostname] as $remote_host => $file) { + if (Str::contains($file, '~')) { + $device = \DeviceCache::getByHostname($remote_host); + if (empty($device->device_id)) { + \Log::debug('Could not find smokeping slave device in LibreNMS', ['slave' => $remote_host]); + continue; + } - return array_map(function ($other) use ($direction, $remote) { - $device = \DeviceCache::getByHostname($other); - return [ - 'device' => $device, - 'graph' => [ - 'type' => 'smokeping_' . $direction, - 'device' => $this->device->device_id, - $remote => $device->device_id, - ] - ]; - }, $data); + $data[] = [ + 'device' => $device, + 'graph' => [ + 'type' => 'smokeping_' . $direction, + 'device' => $this->device->device_id, + $remote => $device->device_id, + ] + ]; + } + } + + return $data; } public function hasGraphs()