|
2 | 2 |
|
3 | 3 | namespace LibreNMS\Cache; |
4 | 4 |
|
| 5 | +use App\Facades\DeviceCache; |
5 | 6 | use App\Models\Ipv4Address; |
6 | 7 | use App\Models\Ipv6Address; |
7 | 8 | use Illuminate\Support\Facades\Log; |
@@ -106,25 +107,26 @@ public function getIdFromIp(string|IP $ip, ?string $context_name = null, \App\Mo |
106 | 107 |
|
107 | 108 | $device_id = $this->deviceToId($device); |
108 | 109 | $ip_string = $ip->uncompressed(); |
| 110 | + $context_name = (string) $context_name; |
109 | 111 |
|
110 | 112 | if (! array_key_exists($device_id, $this->ipMaps) || ! array_key_exists($ip_string, $this->ipMaps[$device_id])) { |
111 | 113 | if ($ip->getFamily() == 'ipv4') { |
112 | | - $this->ipMaps[$device_id][$ip_string] = Ipv4Address::query() |
113 | | - ->when($device, fn ($q) => $q->where('device_id', $device_id)) |
| 114 | + $query = $device ? DeviceCache::get($device_id)->ipv4() : Ipv4Address::query(); |
| 115 | + $this->ipMaps[$device_id][$context_name][$ip_string] = $query |
114 | 116 | ->where('ipv4_address', $ip_string) |
115 | 117 | ->where('context_name', $context_name) |
116 | | - ->value('port_id'); |
| 118 | + ->value('ipv4_addresses.port_id'); |
117 | 119 | } else { |
118 | | - $this->ipMaps[$device_id][$ip_string] = Ipv6Address::query() |
119 | | - ->when($device, fn ($q) => $q->where('device_id', $device_id)) |
| 120 | + $query = $device ? DeviceCache::get($device_id)->ipv6() : Ipv6Address::query(); |
| 121 | + $this->ipMaps[$device_id][$context_name][$ip_string] = $query |
120 | 122 | ->where('ipv6_address', $ip_string) |
121 | 123 | ->where('context_name', $context_name) |
122 | | - ->value('port_id'); |
| 124 | + ->value('ipv6_addresses.port_id'); |
123 | 125 | } |
124 | 126 | } |
125 | 127 |
|
126 | | - if (isset($this->ipMaps[$device_id][$ip_string])) { |
127 | | - return $this->ipMaps[$device_id][$ip_string]; |
| 128 | + if (isset($this->ipMaps[$device_id][$context_name][$ip_string])) { |
| 129 | + return $this->ipMaps[$device_id][$context_name][$ip_string]; |
128 | 130 | } |
129 | 131 |
|
130 | 132 | return null; |
|
0 commit comments