From 1b55cbc27aab9977bd4a03234ce3e3d372fc02e0 Mon Sep 17 00:00:00 2001 From: Mark Unwin Date: Fri, 9 Feb 2024 14:58:00 +1000 Subject: [PATCH] When adding a new device, parse hostname, sysName and dns_hostname to make sure we only store the name, not the fqdn. --- app/Models/DevicesModel.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/app/Models/DevicesModel.php b/app/Models/DevicesModel.php index c652ffe15..93917476b 100644 --- a/app/Models/DevicesModel.php +++ b/app/Models/DevicesModel.php @@ -158,10 +158,22 @@ public function create($data = null): ?int if (empty($data->name)) { if (!empty($data->hostname)) { $data->name = strtolower($data->hostname); + if (strpos($data->hostname, '.') !== false) { + $temp = explode('.', $data->hostname); + $data->name = $temp[0]; + } } else if (!empty($data->sysName)) { $data->name = strtolower($data->sysName); + if (strpos($data->sysName, '.') !== false) { + $temp = explode('.', $data->sysName); + $data->name = $temp[0]; + } } else if (!empty($data->dns_hostname)) { $data->name = strtolower($data->dns_hostname); + if (strpos($data->dns_hostname, '.') !== false) { + $temp = explode('.', $data->dns_hostname); + $data->name = $temp[0]; + } } else if (!empty($data->ip)) { $data->name = ip_address_from_db($data->ip); } else {