diff --git a/LibreNMS/Util/ObjectCache.php b/LibreNMS/Util/ObjectCache.php index c018fc31d7..b36fe19ece 100644 --- a/LibreNMS/Util/ObjectCache.php +++ b/LibreNMS/Util/ObjectCache.php @@ -193,19 +193,21 @@ class ObjectCache * @param array $fields array of counts to get. Valid options: total, ok, warning, critical, ignored, disabled * @return array */ - public static function serviceCounts($fields = ['total']) + public static function serviceCounts($fields = ['total'], $device_id = 0) { $result = []; foreach ($fields as $field) { - $result[$field] = self::getServiceCount($field); + $result[$field] = self::getServiceCount($field, $device_id); } return $result; } - private static function getServiceCount($field) + private static function getServiceCount($field, $device_id) { - return Cache::remember("ObjectCache:service_{$field}_count:" . auth()->id(), self::$cache_time, function () use ($field) { - $query = Service::hasAccess(auth()->user()); + return Cache::remember("ObjectCache:service_{$field}_count:" . auth()->id(), self::$cache_time, function () use ($field, $device_id) { + $query = Service::hasAccess(auth()->user())->when($device_id, function ($query) use ($device_id) { + $query->where('device_id', $device_id); + });; switch ($field) { case 'ok': return $query->isOk()->count(); diff --git a/includes/html/pages/device/overview/services.inc.php b/includes/html/pages/device/overview/services.inc.php index f17377d176..c3ae0288f0 100644 --- a/includes/html/pages/device/overview/services.inc.php +++ b/includes/html/pages/device/overview/services.inc.php @@ -2,7 +2,7 @@ use LibreNMS\Util\ObjectCache; -if (ObjectCache::serviceCounts()['total'] > 0) { +if (ObjectCache::serviceCounts(['total'], $device['device_id'])['total'] > 0) { // Build the string. $break = ''; $output = ''; @@ -24,7 +24,7 @@ if (ObjectCache::serviceCounts()['total'] > 0) { $break = ', '; } - $services = ObjectCache::serviceCounts(['total', 'ok', 'warning', 'critical']); + $services = ObjectCache::serviceCounts(['total', 'ok', 'warning', 'critical'], $device['device_id']); ?>