diff --git a/includes/html/graphs/graph.inc.php b/includes/html/graphs/graph.inc.php
index c3410536fb..17da4b6409 100644
--- a/includes/html/graphs/graph.inc.php
+++ b/includes/html/graphs/graph.inc.php
@@ -9,10 +9,9 @@ try {
$device = is_numeric($vars['device'])
? device_by_id_cache($vars['device'])
: device_by_name($vars['device']);
- if (empty($device['device_id'])) {
- throw new \LibreNMS\Exceptions\RrdGraphException('Device not found');
+ if (isset($device['device_id'])) {
+ DeviceCache::setPrimary($device['device_id']);
}
- DeviceCache::setPrimary($device['device_id']);
}
// variables for included graphs
@@ -59,6 +58,11 @@ try {
return;
}
+ // check after auth
+ if (isset($vars['device']) && empty($device['device_id'])) {
+ throw new \LibreNMS\Exceptions\RrdGraphException('Device not found');
+ }
+
$rrd_options = $graph_params . ' ' . $rrd_options;
// command output requested