A free open source IT asset/license management system
Added the STORAGE info from Jamf, normalize storage into GB for all adapters
snipe6329182f94bd
diff --git a/_ide_helper_models.php b/_ide_helper_models.phpindex 0ec5a57e76..81ec102303 100644--- a/_ide_helper_models.php+++ b/_ide_helper_models.php@@ -2366,7 +2366,9 @@ namespace App\Models{* @method static \Illuminate\Database\Eloquent\Builder<static>|MaintenanceType newModelQuery()* @method static \Illuminate\Database\Eloquent\Builder<static>|MaintenanceType newQuery()* @method static \Illuminate\Database\Eloquent\Builder<static>|MaintenanceType onlyTrashed()+ * @method static \Illuminate\Database\Eloquent\Builder<static>|MaintenanceType orWhereMultipleColumns(array $columns, $term)* @method static \Illuminate\Database\Eloquent\Builder<static>|MaintenanceType query()+ * @method static \Illuminate\Database\Eloquent\Builder<static>|MaintenanceType textSearch($search)* @method static \Illuminate\Database\Eloquent\Builder<static>|MaintenanceType whereCreatedAt($value)* @method static \Illuminate\Database\Eloquent\Builder<static>|MaintenanceType whereCreatedBy($value)* @method static \Illuminate\Database\Eloquent\Builder<static>|MaintenanceType whereDeletedAt($value)@@ -2982,16 +2984,8 @@ namespace App\Models{namespace App\Models{/*** Named filter-preset for a listing page's advanced-search. Each- * record stores a URL query string (filter[.- *- * ..] + filter_operator)- * captured from the advanced-search modal. Loading a saved search- * means navigating back to the originating listing route with the- * stored query string re-attached. Private to the creator for v1- * (no sharing/default yet).- *- * table_name holds the bs-table idTable (e.g. 'accessoriesListingTable')- * so a single table's saved-searches dropdown only lists its own.+ * record stores a URL query string captured from the advanced-search+ * modal. Private to the creator for v1 (no sharing/default yet).** @property int $id* @property int $created_by@@ -3002,19 +2996,20 @@ namespace App\Models{* @property \Illuminate\Support\Carbon|null $created_at* @property \Illuminate\Support\Carbon|null $updated_at* @property-read \App\Models\User|null $creator- * @method static \Illuminate\Database\Eloquent\Builder<static>|SavedSearch forTable(string $tableName)- * @method static \Illuminate\Database\Eloquent\Builder<static>|SavedSearch newModelQuery()- * @method static \Illuminate\Database\Eloquent\Builder<static>|SavedSearch newQuery()- * @method static \Illuminate\Database\Eloquent\Builder<static>|SavedSearch ownedByCurrent()- * @method static \Illuminate\Database\Eloquent\Builder<static>|SavedSearch query()- * @method static \Illuminate\Database\Eloquent\Builder<static>|SavedSearch whereCreatedAt($value)- * @method static \Illuminate\Database\Eloquent\Builder<static>|SavedSearch whereCreatedBy($value)- * @method static \Illuminate\Database\Eloquent\Builder<static>|SavedSearch whereId($value)- * @method static \Illuminate\Database\Eloquent\Builder<static>|SavedSearch whereModel($value)- * @method static \Illuminate\Database\Eloquent\Builder<static>|SavedSearch whereName($value)- * @method static \Illuminate\Database\Eloquent\Builder<static>|SavedSearch whereQueryString($value)- * @method static \Illuminate\Database\Eloquent\Builder<static>|SavedSearch whereTableName($value)- * @method static \Illuminate\Database\Eloquent\Builder<static>|SavedSearch whereUpdatedAt($value)+ * @method static \Database\Factories\SavedSearchFactory factory($count = null, $state = [])+ * @method static \App\Models\Builders\SavedSearchQueryBuilder<static>|SavedSearch forTable(string $tableName)+ * @method static \App\Models\Builders\SavedSearchQueryBuilder<static>|SavedSearch newModelQuery()+ * @method static \App\Models\Builders\SavedSearchQueryBuilder<static>|SavedSearch newQuery()+ * @method static \App\Models\Builders\SavedSearchQueryBuilder<static>|SavedSearch ownedByCurrent()+ * @method static \App\Models\Builders\SavedSearchQueryBuilder<static>|SavedSearch query()+ * @method static \App\Models\Builders\SavedSearchQueryBuilder<static>|SavedSearch whereCreatedAt($value)+ * @method static \App\Models\Builders\SavedSearchQueryBuilder<static>|SavedSearch whereCreatedBy($value)+ * @method static \App\Models\Builders\SavedSearchQueryBuilder<static>|SavedSearch whereId($value)+ * @method static \App\Models\Builders\SavedSearchQueryBuilder<static>|SavedSearch whereModel($value)+ * @method static \App\Models\Builders\SavedSearchQueryBuilder<static>|SavedSearch whereName($value)+ * @method static \App\Models\Builders\SavedSearchQueryBuilder<static>|SavedSearch whereQueryString($value)+ * @method static \App\Models\Builders\SavedSearchQueryBuilder<static>|SavedSearch whereTableName($value)+ * @method static \App\Models\Builders\SavedSearchQueryBuilder<static>|SavedSearch whereUpdatedAt($value)* @mixin \Eloquent*/#[\AllowDynamicProperties]diff --git a/app/Models/Accessory.php b/app/Models/Accessory.phpindex 588dcae428..7b544e52bb 100755--- a/app/Models/Accessory.php+++ b/app/Models/Accessory.php@@ -211,7 +211,7 @@ class Accessory extends SnipeModel implements Importableprotected function applyCustomFilter(\Illuminate\Database\Eloquent\Builder $query, string $filterKey, string $filterValue, string $boolean = 'and'): ?\Illuminate\Database\Eloquent\Builder{if ($filterKey === 'purchase_date') {- if (!preg_match('/^(\d{4}-\d{2}-\d{2})?\.\.(\d{4}-\d{2}-\d{2})?$/', trim($filterValue), $m)) {+ if (! preg_match('/^(\d{4}-\d{2}-\d{2})?\.\.(\d{4}-\d{2}-\d{2})?$/', trim($filterValue), $m)) {return null;}$start = $m[1] !== '' ? $m[1] : null;diff --git a/app/Models/Actionlog.php b/app/Models/Actionlog.phpindex f27f82386d..3486f192ae 100755--- a/app/Models/Actionlog.php+++ b/app/Models/Actionlog.php@@ -62,7 +62,7 @@ class Actionlog extends SnipeModelreturn $value;}- if (!$this->item instanceof License) {+ if (! $this->item instanceof License) {return $value;}@@ -71,7 +71,7 @@ class Actionlog extends SnipeModel}$decoded = json_decode($value, true);- if (!is_array($decoded) || !isset($decoded['serial']) || !is_array($decoded['serial'])) {+ if (! is_array($decoded) || ! isset($decoded['serial']) || ! is_array($decoded['serial'])) {return $value;}@@ -198,7 +198,7 @@ class Actionlog extends SnipeModelpublic static function filterableFields(): array{$typeOptions = array_map(- fn(\App\Enums\ActivityItemType $case) => [+ fn (\App\Enums\ActivityItemType $case) => ['value' => $case->value,'label' => $case->label(),],@@ -206,7 +206,7 @@ class Actionlog extends SnipeModel);$actionTypeOptions = array_map(- fn(\App\Enums\ActionType $case) => [+ fn (\App\Enums\ActionType $case) => ['value' => $case->value,'label' => ucwords($case->value),],@@ -295,7 +295,7 @@ class Actionlog extends SnipeModel$column = $filterKey === 'item' ? 'item_type' : 'target_type';$method = $boolean === 'or' ? 'orWhereIn' : 'whereIn';- $query->{$method}('action_logs.' . $column, array_values(array_unique($classes)));+ $query->{$method}('action_logs.'.$column, array_values(array_unique($classes)));return $query;}diff --git a/app/Models/Asset.php b/app/Models/Asset.phpindex a59b45f270..6e884bc1d5 100644--- a/app/Models/Asset.php+++ b/app/Models/Asset.php@@ -360,21 +360,21 @@ class Asset extends Depreciable implements Importable'type' => 'fk','column' => null,'endpoint' => 'users',- 'label' => trans('admin/hardware/table.assigned_to') . ' - ' . trans('general.user'),+ 'label' => trans('admin/hardware/table.assigned_to').' - '.trans('general.user'),],['field' => 'assigned_asset','type' => 'fk','column' => null,'endpoint' => 'hardware',- 'label' => trans('admin/hardware/table.assigned_to') . ' - ' . trans('general.asset'),+ 'label' => trans('admin/hardware/table.assigned_to').' - '.trans('general.asset'),],['field' => 'assigned_location','type' => 'fk','column' => null,'endpoint' => 'locations',- 'label' => trans('admin/hardware/table.assigned_to') . ' - ' . trans('general.location'),+ 'label' => trans('admin/hardware/table.assigned_to').' - '.trans('general.location'),],['field' => 'requestable',@@ -636,10 +636,10 @@ class Asset extends Depreciable implements Importable$outerBoolean = $boolean === 'or' ? 'orWhere' : 'where';$query->{$outerBoolean}(function ($nested) use ($modelFkColumn, $ids, $includeNull) {- if (!empty($ids)) {+ if (! empty($ids)) {$nested->whereIn('assets.model_id', function ($q) use ($modelFkColumn, $ids) {$q->from('models')- ->whereIn('models.' . $modelFkColumn, $ids)+ ->whereIn('models.'.$modelFkColumn, $ids)->select('models.id');});}@@ -647,7 +647,7 @@ class Asset extends Depreciable implements Importable$nullMatcher = function ($q) use ($modelFkColumn) {$q->whereIn('assets.model_id', function ($sub) use ($modelFkColumn) {$sub->from('models')- ->whereNull('models.' . $modelFkColumn)+ ->whereNull('models.'.$modelFkColumn)->select('models.id');})->orWhereNull('assets.model_id');};@@ -656,7 +656,7 @@ class Asset extends Depreciable implements Importable} else {$nested->orWhereIn('assets.model_id', function ($sub) use ($modelFkColumn) {$sub->from('models')- ->whereNull('models.' . $modelFkColumn)+ ->whereNull('models.'.$modelFkColumn)->select('models.id');})->orWhereNull('assets.model_id');}@@ -672,7 +672,7 @@ class Asset extends Depreciable implements Importable// NULLs, so assets without a purchase date or without a// warranty duration naturally fall out of the match.if ($filterKey === 'warranty_expires') {- if (!preg_match('/^(\d{4}-\d{2}-\d{2})?\.\.(\d{4}-\d{2}-\d{2})?$/', trim($filterValue), $m)) {+ if (! preg_match('/^(\d{4}-\d{2}-\d{2})?\.\.(\d{4}-\d{2}-\d{2})?$/', trim($filterValue), $m)) {return null;}$start = $m[1] !== '' ? $m[1] : null;@@ -781,7 +781,7 @@ class Asset extends Depreciable implements Importable$outerBoolean = $boolean === 'or' ? 'orWhere' : 'where';$query->{$outerBoolean}(function ($nested) use ($assignedType, $ids, $includeNull) {- if (!empty($ids)) {+ if (! empty($ids)) {$nested->where(function ($q) use ($assignedType, $ids) {$q->where('assets.assigned_type', $assignedType)->whereIn('assets.assigned_to', $ids);diff --git a/app/Models/Component.php b/app/Models/Component.phpindex fb631e8734..2ba662eb9a 100644--- a/app/Models/Component.php+++ b/app/Models/Component.php@@ -278,7 +278,7 @@ class Component extends SnipeModel implements Importableprotected function applyCustomFilter(\Illuminate\Database\Eloquent\Builder $query, string $filterKey, string $filterValue, string $boolean = 'and'): ?\Illuminate\Database\Eloquent\Builder{if ($filterKey === 'purchase_date') {- if (!preg_match('/^(\d{4}-\d{2}-\d{2})?\.\.(\d{4}-\d{2}-\d{2})?$/', trim($filterValue), $m)) {+ if (! preg_match('/^(\d{4}-\d{2}-\d{2})?\.\.(\d{4}-\d{2}-\d{2})?$/', trim($filterValue), $m)) {return null;}$start = $m[1] !== '' ? $m[1] : null;diff --git a/app/Models/Maintenance.php b/app/Models/Maintenance.phpindex 5d20f438e4..613703abfe 100644--- a/app/Models/Maintenance.php+++ b/app/Models/Maintenance.php@@ -285,11 +285,11 @@ class Maintenance extends SnipeModel implements CompanyableChild$outerBoolean = $boolean === 'or' ? 'orWhere' : 'where';$query->{$outerBoolean}(function ($nested) use ($ids, $includeNull) {$nested->where('maintenances.item_type', Asset::class);- if (!empty($ids)) {+ if (! empty($ids)) {$nested->whereIn('maintenances.item_id', $ids);}if ($includeNull) {- if (!empty($ids)) {+ if (! empty($ids)) {$nested->orWhereNull('maintenances.item_id');} else {$nested->whereNull('maintenances.item_id');@@ -306,19 +306,19 @@ class Maintenance extends SnipeModel implements CompanyableChildreturn null;}[$ids, $includeNull] = $parsed;- if (empty($ids) && !$includeNull) {+ if (empty($ids) && ! $includeNull) {return null;}$outerBoolean = $boolean === 'or' ? 'orWhere' : 'where';$query->{$outerBoolean}(function ($nested) use ($ids, $includeNull) {$nested->whereHas('asset', function ($assetQuery) use ($ids, $includeNull) {- if (!empty($ids) && $includeNull) {+ if (! empty($ids) && $includeNull) {$assetQuery->where(function ($q) use ($ids) {$q->whereIn('assets.status_id', $ids)->orWhereNull('assets.status_id');});- } elseif (!empty($ids)) {+ } elseif (! empty($ids)) {$assetQuery->whereIn('assets.status_id', $ids);} else {$assetQuery->whereNull('assets.status_id');diff --git a/app/SyncAdapters/AppleBusinessManager/AppleBusinessManagerAdapter.php b/app/SyncAdapters/AppleBusinessManager/AppleBusinessManagerAdapter.phpindex 565d6e75f8..3ff4feacbc 100644--- a/app/SyncAdapters/AppleBusinessManager/AppleBusinessManagerAdapter.php+++ b/app/SyncAdapters/AppleBusinessManager/AppleBusinessManagerAdapter.php@@ -272,8 +272,8 @@ class AppleBusinessManagerAdapter extends SyncAdapter'abm_mdm_device_lock_status' => ['label_key' => 'admin/settings/sync_adapters.abm_extra_mdm_device_lock_status'],'abm_mdm_lost_mode_status' => ['label_key' => 'admin/settings/sync_adapters.abm_extra_mdm_lost_mode_status'],'abm_mdm_device_erase_status' => ['label_key' => 'admin/settings/sync_adapters.abm_extra_mdm_device_erase_status'],- 'abm_mdm_storage_total' => ['label_key' => 'admin/settings/sync_adapters.abm_extra_mdm_storage_total'],- 'abm_mdm_storage_free' => ['label_key' => 'admin/settings/sync_adapters.abm_extra_mdm_storage_free'],+ 'abm_mdm_storage_total_gb' => ['label_key' => 'admin/settings/sync_adapters.abm_extra_mdm_storage_total_gb'],+ 'abm_mdm_storage_free_gb' => ['label_key' => 'admin/settings/sync_adapters.abm_extra_mdm_storage_free_gb'],];}@@ -773,6 +773,25 @@ class AppleBusinessManagerAdapter extends SyncAdapterreturn $fallback;}+ /**+ * Normalize MDM-reported bytes (storageTotalCapacity /+ * storageFreeCapacity) to GB for cross-adapter consistency with+ * the other storage extras across sync adapters. Divides by 10^9+ * (decimal GB, same convention Apple uses in marketed capacity).+ * Null or non-numeric input returns null so an unpopulated field+ * stays unpopulated rather than becoming a bogus 0 GB that an+ * admin filter could misread.+ */+ private static function bytesToGb(mixed $bytes): int|float|null+ {+ if (! is_numeric($bytes)) {+ return null;+ }+ $gb = $bytes / 1_000_000_000;++ return $gb == (int) $gb ? (int) $gb : round($gb, 2);+ }+/*** Pick the primary MAC from the MDM detail attributes. Prefers* Wi-Fi, falls back to Ethernet (desktops without Wi-Fi), then@@ -834,8 +853,8 @@ class AppleBusinessManagerAdapter extends SyncAdapter$extra['abm_mdm_device_lock_status'] = Arr::get($attrs, 'deviceLockStatus');$extra['abm_mdm_lost_mode_status'] = Arr::get($attrs, 'lostModeStatus');$extra['abm_mdm_device_erase_status'] = Arr::get($attrs, 'deviceEraseStatus');- $extra['abm_mdm_storage_total'] = Arr::get($attrs, 'storageTotalCapacity');- $extra['abm_mdm_storage_free'] = Arr::get($attrs, 'storageFreeCapacity');+ $extra['abm_mdm_storage_total_gb'] = self::bytesToGb(Arr::get($attrs, 'storageTotalCapacity'));+ $extra['abm_mdm_storage_free_gb'] = self::bytesToGb(Arr::get($attrs, 'storageFreeCapacity'));// Wi-Fi and Bluetooth are single-radio on every current Apple// SKU so they stay scalar. Ethernet can be a two-element arraydiff --git a/app/SyncAdapters/Intune/IntuneAdapter.php b/app/SyncAdapters/Intune/IntuneAdapter.phpindex 0421b2eccc..adc64a0ea6 100644--- a/app/SyncAdapters/Intune/IntuneAdapter.php+++ b/app/SyncAdapters/Intune/IntuneAdapter.php@@ -5,7 +5,6 @@ namespace App\SyncAdapters\Intune;use App\Models\Asset;use App\SyncAdapters\HostInventoryRecord;use App\SyncAdapters\PushableSyncAdapter;-use App\SyncAdapters\SyncAdapter;use Carbon\Carbon;use Illuminate\Support\Arr;use Illuminate\Support\Facades\Log;@@ -100,8 +99,8 @@ class IntuneAdapter extends PushableSyncAdapter'intune_management_agent' => ['label_key' => 'admin/settings/sync_adapters.intune_extra_management_agent'],'intune_ownership' => ['label_key' => 'admin/settings/sync_adapters.intune_extra_ownership'],'intune_wifi_mac' => ['label_key' => 'admin/settings/sync_adapters.intune_extra_wifi_mac'],- 'intune_total_storage_bytes' => ['label_key' => 'admin/settings/sync_adapters.intune_extra_total_storage_bytes'],- 'intune_free_storage_bytes' => ['label_key' => 'admin/settings/sync_adapters.intune_extra_free_storage_bytes'],+ 'intune_total_storage_gb' => ['label_key' => 'admin/settings/sync_adapters.intune_extra_total_storage_gb'],+ 'intune_free_storage_gb' => ['label_key' => 'admin/settings/sync_adapters.intune_extra_free_storage_gb'],'intune_is_encrypted' => ['label_key' => 'admin/settings/sync_adapters.intune_extra_is_encrypted', 'type' => 'boolean'],'intune_jail_broken' => ['label_key' => 'admin/settings/sync_adapters.intune_extra_jail_broken'],'intune_is_supervised' => ['label_key' => 'admin/settings/sync_adapters.intune_extra_is_supervised', 'type' => 'boolean'],@@ -133,7 +132,7 @@ class IntuneAdapter extends PushableSyncAdapter// "Fetch per-device details" opt-in is on - Graph's LIST// endpoint returns null for these regardless of $select.'intune_ethernet_mac' => ['label_key' => 'admin/settings/sync_adapters.intune_extra_ethernet_mac'],- 'intune_physical_memory_bytes' => ['label_key' => 'admin/settings/sync_adapters.intune_extra_physical_memory_bytes'],+ 'intune_physical_memory_gb' => ['label_key' => 'admin/settings/sync_adapters.intune_extra_physical_memory_gb'],];}@@ -368,11 +367,13 @@ class IntuneAdapter extends PushableSyncAdapter// setting is on. Null otherwise - Graph's LIST never// populates these fields.'intune_ethernet_mac' => self::blankToNull(Arr::get($device, 'ethernetMacAddress')),- 'intune_physical_memory_bytes' => Arr::get($device, 'physicalMemoryInBytes'),- // Hardware inventory. Graph reports storage in bytes -- // admins who want GB can run a custom-field formula.- 'intune_total_storage_bytes' => Arr::get($device, 'totalStorageSpaceInBytes'),- 'intune_free_storage_bytes' => Arr::get($device, 'freeStorageSpaceInBytes'),+ 'intune_physical_memory_gb' => self::bytesToGb(Arr::get($device, 'physicalMemoryInBytes')),+ // Hardware inventory. Graph reports storage in bytes which+ // we convert to GB at the adapter boundary so the value+ // lines up with the other adapters that speak GB natively+ // (Addigy, Levelio, Mosyle, AxM device_capacity, Jamf).+ 'intune_total_storage_gb' => self::bytesToGb(Arr::get($device, 'totalStorageSpaceInBytes')),+ 'intune_free_storage_gb' => self::bytesToGb(Arr::get($device, 'freeStorageSpaceInBytes')),'intune_is_encrypted' => Arr::get($device, 'isEncrypted'),'intune_jail_broken' => Arr::get($device, 'jailBroken'),'intune_is_supervised' => Arr::get($device, 'isSupervised'),@@ -460,6 +461,25 @@ class IntuneAdapter extends PushableSyncAdapterreturn $parts === [] ? null : implode(',', $parts);}+ /**+ * Normalize a raw byte value from Graph's hardware inventory into+ * GB so the storage/memory extras line up with the GB unit the+ * other sync adapters already use. Divides by 10^9 (decimal GB,+ * same convention Apple uses in marketed capacity). Null or+ * non-numeric input returns null so an unpopulated field stays+ * unpopulated rather than becoming a bogus 0 GB that an admin+ * filter could misread.+ */+ private static function bytesToGb(mixed $bytes): int|float|null+ {+ if (! is_numeric($bytes)) {+ return null;+ }+ $gb = $bytes / 1_000_000_000;++ return $gb == (int) $gb ? (int) $gb : round($gb, 2);+ }+private function parseTimestamp(mixed $value): ?Carbon{if ($value === null || $value === '') {diff --git a/app/SyncAdapters/Jamf/JamfAdapter.php b/app/SyncAdapters/Jamf/JamfAdapter.phpindex fd23c85dd2..d39585e7b4 100644--- a/app/SyncAdapters/Jamf/JamfAdapter.php+++ b/app/SyncAdapters/Jamf/JamfAdapter.php@@ -8,6 +8,7 @@ use App\SyncAdapters\PushableSyncAdapter;use App\SyncAdapters\Traits\UsesAppleDbEnrichment;use Carbon\Carbon;use Illuminate\Support\Arr;+use Illuminate\Support\Facades\Log;/*** Jamf Pro adapter. Pulls computer inventory via the Jamf Pro API and@@ -64,6 +65,12 @@ class JamfAdapter extends PushableSyncAdapter'required' => false,'help' => trans('admin/settings/sync_adapters.jamf_include_mobile_devices_help'),],+ [+ 'key' => 'group_filter',+ 'label' => trans('admin/settings/sync_adapters.jamf_group_filter_label'),+ 'required' => false,+ 'help' => trans('admin/settings/sync_adapters.jamf_group_filter_help'),+ ],$this->appleDbSettingsField(),];}@@ -75,12 +82,20 @@ class JamfAdapter extends PushableSyncAdapter'jamf_udid' => ['label_key' => 'admin/settings/sync_adapters.extra_udid'],'jamf_last_enrolled' => ['label_key' => 'admin/settings/sync_adapters.extra_last_enrolled', 'type' => 'date'],'jamf_model_identifier' => ['label_key' => 'admin/settings/sync_adapters.extra_model_identifier'],+ // Computer-only hardware fields. Values normalize to GB so+ // they line up with the other adapters (Addigy, Levelio,+ // Mosyle, AxM device_capacity) which all speak GB natively.+ // Conversion from Jamf's native MB divides by 1000 (decimal+ // GB, same convention Apple uses in marketed capacity).+ 'jamf_ram_gb' => ['label_key' => 'admin/settings/sync_adapters.jamf_extra_ram_gb'],+ 'jamf_storage_gb' => ['label_key' => 'admin/settings/sync_adapters.jamf_extra_storage_gb'],// Mobile-only fields. Blank on computer records so admins// can still map them without worrying about overwriting a// computer's custom field with an empty string.'jamf_mobile_device_type' => ['label_key' => 'admin/settings/sync_adapters.jamf_extra_mobile_device_type'],'jamf_mobile_managed' => ['label_key' => 'admin/settings/sync_adapters.jamf_extra_mobile_managed', 'type' => 'boolean'],'jamf_mobile_supervised' => ['label_key' => 'admin/settings/sync_adapters.jamf_extra_mobile_supervised', 'type' => 'boolean'],+ 'jamf_mobile_storage_gb' => ['label_key' => 'admin/settings/sync_adapters.jamf_extra_mobile_storage_gb'],];}@@ -122,7 +137,12 @@ class JamfAdapter extends PushableSyncAdapter$enrichmentEnabled = $this->appleDbEnrichmentEnabled();$enrichmentHandled = [];+ $filter = $this->resolveGroupFilter($client);+foreach ($client->computers() as $computer) {+ if ($filter !== null && ! isset($filter['computerIds'][(int) Arr::get($computer, 'id')])) {+ continue;+ }$record = $this->normalizeComputer($computer);if ($enrichmentEnabled) {$enrichmentHandled = $this->enrichFromAppleDb($record, $enrichmentHandled);@@ -132,6 +152,9 @@ class JamfAdapter extends PushableSyncAdapterif ($this->shouldPullMobileDevices()) {foreach ($client->mobileDevices() as $device) {+ if ($filter !== null && ! isset($filter['mobileIds'][(int) Arr::get($device, 'id')])) {+ continue;+ }$record = $this->normalizeMobileDevice($device);if ($enrichmentEnabled) {$enrichmentHandled = $this->enrichFromAppleDb($record, $enrichmentHandled);@@ -141,6 +164,128 @@ class JamfAdapter extends PushableSyncAdapter}}+ /**+ * Resolve the admin-entered group_filter into the union of computer+ * and mobile-device IDs that belong to any of the named groups.+ * Entries can be group names (friendly) or raw IDs (short-circuit).+ * Names are resolved against the full group list once per sync.+ * Unresolvable names log a warning and get skipped, matching the+ * Intune scope-tag flow, so one bad entry does not kill the pull.+ *+ * Mobile device groups are only consulted when the include-mobile+ * toggle is also on, so Jamf tenants that don't have mobile devices+ * enabled never pay for the extra classic-API calls.+ *+ * Returns null when no filter is configured so the pull short-+ * circuits the membership gate entirely.+ *+ * @return array{computerIds: array<int, int>, mobileIds: array<int, int>}|null+ */+ private function resolveGroupFilter(JamfClient $client): ?array+ {+ $raw = '';+ try {+ $raw = (string) $this->credential('group_filter');+ } catch (\Throwable) {+ // Credential not set yet. Treat as unconfigured.+ }++ $entries = array_values(array_filter(array_map('trim', explode(',', $raw))));+ if ($entries === []) {+ return null;+ }++ $computerIds = [];+ $mobileIds = [];++ $this->collectMembersForFilter(+ $entries,+ $client->computerGroups(),+ fn (int $id) => $client->computerGroupMembers($id),+ $computerIds,+ 'computer',+ );++ if ($this->shouldPullMobileDevices()) {+ $this->collectMembersForFilter(+ $entries,+ $client->mobileDeviceGroups(),+ fn (int $id) => $client->mobileDeviceGroupMembers($id),+ $mobileIds,+ 'mobile',+ );+ }++ return [+ 'computerIds' => array_flip($computerIds),+ 'mobileIds' => array_flip($mobileIds),+ ];+ }++ /**+ * Shared resolution helper used for both computer groups and mobile+ * device groups. Builds a name-and-id index from the group list,+ * resolves each entry to a concrete group id, and asks $memberFetcher+ * for that group's members. Unresolvable entries log once per+ * namespace so an admin typo in a filter names "Law School Macs" is+ * visible in the sync-adapters log.+ *+ * @param array<int, string> $entries+ * @param array<int, array<string, mixed>> $groups+ * @param callable(int): array<int, int> $memberFetcher+ * @param array<int, int> &$into+ */+ private function collectMembersForFilter(+ array $entries,+ array $groups,+ callable $memberFetcher,+ array &$into,+ string $namespace,+ ): void {+ $nameToId = [];+ $idSet = [];+ foreach ($groups as $group) {+ $name = (string) ($group['name'] ?? '');+ $id = isset($group['id']) ? (int) $group['id'] : null;+ if ($name === '' || $id === null) {+ continue;+ }+ $nameToId[strtolower($name)] = $id;+ $idSet[$id] = true;+ }++ foreach ($entries as $entry) {+ $lower = strtolower($entry);+ $groupId = null;+ if (isset($nameToId[$lower])) {+ $groupId = $nameToId[$lower];+ } elseif (ctype_digit($entry) && isset($idSet[(int) $entry])) {+ $groupId = (int) $entry;+ }++ if ($groupId === null) {+ // Computer groups and mobile-device groups are separate+ // namespaces in Jamf. An entry that doesn't resolve in+ // this namespace may still resolve in the other, so log+ // debug rather than warn here. A true typo is caught+ // because it fails in both namespaces and the admin+ // notices zero devices are matching.+ Log::channel('sync-adapters')->debug(sprintf(+ '%s: group_filter entry "%s" did not match any %s group. Skipping in this namespace.',+ $this->name(),+ $entry,+ $namespace,+ ));++ continue;+ }++ foreach ($memberFetcher($groupId) as $memberId) {+ $into[] = $memberId;+ }+ }+ }+/*** Pass the Jamf record to the shared enrichment flow. Both the* computer and mobile normalize paths put the AppleDB-shape@@ -226,12 +371,77 @@ class JamfAdapter extends PushableSyncAdapter'jamf_udid' => Arr::get($computer, 'udid'),'jamf_last_enrolled' => Arr::get($computer, 'general.lastEnrolledDate'),'jamf_model_identifier' => Arr::get($computer, 'hardware.modelIdentifier'),+ 'jamf_ram_gb' => self::megabytesToGb(Arr::get($computer, 'hardware.totalRamMegabytes')),+ 'jamf_storage_gb' => self::megabytesToGb(self::primaryDiskMegabytes($computer)),],canonicalMarketingName: $canonical['canonicalMarketingName'],canonicalModelNumber: $canonical['canonicalModelNumber'],);}+ /**+ * Extract the Mac's internal boot disk size from a Jamf STORAGE+ * section. Jamf returns an array of disks under storage.disks that+ * includes any external drive plugged in at inventory time, so+ * taking the first disk or summing the array would inflate the+ * value. Each disk's partitions carry a partitionType enum, and+ * exactly one partition across the whole machine carries+ * partitionType="BOOT" (the macOS boot volume), so the disk that+ * contains that partition is the internal SSD. Fall back to+ * disks[0] when Jamf doesn't tag any partition as BOOT (older+ * Jamf versions and some edge states), which is still correct in+ * practice because the first disk is disk0 on every modern Mac.+ *+ * Returns null when Jamf didn't return a storage section for this+ * computer (common on offline-at-inventory machines or on tenants+ * that haven't enabled STORAGE collection).+ *+ * @param array<string, mixed> $computer+ */+ /**+ * Normalize an MB value to GB for cross-adapter unit consistency.+ * Divides by 1000 (decimal), matching Apple's marketed-capacity+ * convention and the GB unit the other storage/memory extras+ * across sync adapters already use. Null/non-numeric input returns+ * null so empty storage sections stay empty rather than becoming 0+ * (which an admin filter would misread as a real zero-GB value).+ */+ private static function megabytesToGb(mixed $megabytes): int|float|null+ {+ if (! is_numeric($megabytes)) {+ return null;+ }+ $gb = $megabytes / 1000;++ return $gb == (int) $gb ? (int) $gb : round($gb, 2);+ }++ private static function primaryDiskMegabytes(array $computer): ?int+ {+ $disks = Arr::get($computer, 'storage.disks');+ if (! is_array($disks) || $disks === []) {+ return null;+ }++ foreach ($disks as $disk) {+ $partitions = Arr::get($disk, 'partitions', []);+ if (! is_array($partitions)) {+ continue;+ }+ foreach ($partitions as $partition) {+ if ((Arr::get($partition, 'partitionType') ?? '') === 'BOOT') {+ $size = Arr::get($disk, 'sizeMegabytes');++ return is_numeric($size) ? (int) $size : null;+ }+ }+ }++ $size = Arr::get($disks[0], 'sizeMegabytes');++ return is_numeric($size) ? (int) $size : null;+ }+/*** Convert a /api/v2/mobile-devices list entry into the normalized* record shape. Mobile Jamf payloads are flatter than computer@@ -274,6 +484,7 @@ class JamfAdapter extends PushableSyncAdapter'jamf_mobile_device_type' => Arr::get($device, 'deviceType'),'jamf_mobile_managed' => Arr::get($device, 'managed'),'jamf_mobile_supervised' => Arr::get($device, 'supervised'),+ 'jamf_mobile_storage_gb' => self::megabytesToGb(Arr::get($device, 'capacityMb')),],canonicalMarketingName: $canonical['canonicalMarketingName'],canonicalModelNumber: $canonical['canonicalModelNumber'],diff --git a/app/SyncAdapters/Jamf/JamfClient.php b/app/SyncAdapters/Jamf/JamfClient.phpindex 9ad76bf4c2..ded7fdd77f 100644--- a/app/SyncAdapters/Jamf/JamfClient.php+++ b/app/SyncAdapters/Jamf/JamfClient.php@@ -53,7 +53,7 @@ class JamfClient// Build the query string by hand so the wire form matches// what Jamf actually reads.- $sections = ['GENERAL', 'HARDWARE', 'OPERATING_SYSTEM', 'USER_AND_LOCATION'];+ $sections = ['GENERAL', 'HARDWARE', 'OPERATING_SYSTEM', 'USER_AND_LOCATION', 'STORAGE'];do {$query = http_build_query([@@ -140,6 +140,96 @@ class JamfClientreturn is_array($response) ? $response : [];}+ /**+ * List every Computer Group (smart + static) in the Jamf Pro tenant.+ * Used by the adapter's optional group filter so admins who don't+ * use Sites can still scope the sync to specific Smart Groups (or+ * static groups), e.g. "Law School Macs".+ *+ * Hits the classic API because /JSSResource/computergroups has been+ * the stable membership-returning endpoint across every supported+ * Jamf Pro release, where the v1 pro-API equivalent has moved+ * several times and omits smart-group member lists on older tenants.+ * Bearer-token auth works against classic API endpoints since Jamf+ * Pro 10.35, which is well below our effective minimum.+ *+ * Returns a list of {id, name, is_smart} entries.+ *+ * @return array<int, array<string, mixed>>+ */+ public function computerGroups(): array+ {+ $response = $this->request()+ ->get('/JSSResource/computergroups')+ ->throw()+ ->json();++ return (array) ($response['computer_groups'] ?? []);+ }++ /**+ * Return the computer IDs that currently belong to a given Computer+ * Group. The classic group-detail endpoint returns the full group+ * payload including a `computers` array of `{id, name, ...}` entries+ * for both smart and static groups. We just need the IDs.+ *+ * @return array<int, int>+ */+ public function computerGroupMembers(int $groupId): array+ {+ $response = $this->request()+ ->get('/JSSResource/computergroups/id/'.$groupId)+ ->throw()+ ->json();++ $computers = (array) ($response['computer_group']['computers'] ?? []);++ return array_values(array_filter(array_map(+ fn (array $computer) => isset($computer['id']) ? (int) $computer['id'] : null,+ $computers,+ )));+ }++ /**+ * Mobile device groups counterpart to computerGroups(). Only queried+ * when the admin has enabled mobile-device sync AND configured a+ * group filter, so Jamf tenants without mobile device groups don't+ * pay for the call.+ *+ * @return array<int, array<string, mixed>>+ */+ public function mobileDeviceGroups(): array+ {+ $response = $this->request()+ ->get('/JSSResource/mobiledevicegroups')+ ->throw()+ ->json();++ return (array) ($response['mobile_device_groups'] ?? []);+ }++ /**+ * Mobile device ID list for a given Mobile Device Group. Same shape+ * as computerGroupMembers() but the classic payload nests the member+ * list under `mobile_devices` instead of `computers`.+ *+ * @return array<int, int>+ */+ public function mobileDeviceGroupMembers(int $groupId): array+ {+ $response = $this->request()+ ->get('/JSSResource/mobiledevicegroups/id/'.$groupId)+ ->throw()+ ->json();++ $devices = (array) ($response['mobile_device_group']['mobile_devices'] ?? []);++ return array_values(array_filter(array_map(+ fn (array $device) => isset($device['id']) ? (int) $device['id'] : null,+ $devices,+ )));+ }+/*** Update a computer's inventory detail via Jamf Pro's newer JSON* API. Accepts a partial payload with nested objects like `general`diff --git a/database/migrations/2026_11_03_212634_normalize_sync_adapter_storage_extras_to_gb.php b/database/migrations/2026_11_03_212634_normalize_sync_adapter_storage_extras_to_gb.phpnew file mode 100644index 0000000000..3d2da9f279--- /dev/null+++ b/database/migrations/2026_11_03_212634_normalize_sync_adapter_storage_extras_to_gb.php@@ -0,0 +1,100 @@+<?php++use Illuminate\Database\Migrations\Migration;+use Illuminate\Support\Facades\DB;+use Illuminate\Support\Facades\Schema;++return new class extends Migration+{+ private const RENAMES = [+ 'mapping.intune_total_storage_bytes' => 'mapping.intune_total_storage_gb',+ 'mapping.intune_free_storage_bytes' => 'mapping.intune_free_storage_gb',+ 'mapping.intune_physical_memory_bytes' => 'mapping.intune_physical_memory_gb',+ 'mapping.abm_mdm_storage_total' => 'mapping.abm_mdm_storage_total_gb',+ 'mapping.abm_mdm_storage_free' => 'mapping.abm_mdm_storage_free_gb',+ ];++ public function up(): void+ {+ if (! Schema::hasTable('sync_adapter_instances')) {+ return;+ }++ $targetColumns = [];++ foreach (DB::table('sync_adapter_instances')->get() as $instance) {+ $config = json_decode($instance->config ?? '[]', true);+ if (! is_array($config)) {+ continue;+ }++ $dirty = false;+ foreach (self::RENAMES as $oldKey => $newKey) {+ if (! array_key_exists($oldKey, $config)) {+ continue;+ }+ $target = $config[$oldKey];+ if (is_string($target) && str_starts_with($target, '_snipeit_')) {+ $targetColumns[$target] = true;+ }+ $config[$newKey] = $target;+ unset($config[$oldKey]);+ $dirty = true;+ }++ if ($dirty) {+ DB::table('sync_adapter_instances')+ ->where('id', $instance->id)+ ->update(['config' => json_encode($config)]);+ }+ }++ /*+ * Convert the stored byte values in each affected custom-field+ * column to GB.+ */+ foreach (array_keys($targetColumns) as $column) {+ if (! Schema::hasColumn('assets', $column)) {+ continue;+ }++ DB::table('assets')+ ->whereNotNull($column)+ ->update([+ $column => DB::raw("$column / 1000000000"),+ ]);+ }+ }++ public function down(): void+ {+ if (! Schema::hasTable('sync_adapter_instances')) {+ return;+ }++ $reverse = array_flip(self::RENAMES);++ foreach (DB::table('sync_adapter_instances')->get() as $instance) {+ $config = json_decode($instance->config ?? '[]', true);+ if (! is_array($config)) {+ continue;+ }++ $dirty = false;+ foreach ($reverse as $newKey => $oldKey) {+ if (! array_key_exists($newKey, $config)) {+ continue;+ }+ $config[$oldKey] = $config[$newKey];+ unset($config[$newKey]);+ $dirty = true;+ }++ if ($dirty) {+ DB::table('sync_adapter_instances')+ ->where('id', $instance->id)+ ->update(['config' => json_encode($config)]);+ }+ }+ }+};diff --git a/resources/lang/en-US/admin/settings/sync_adapters.php b/resources/lang/en-US/admin/settings/sync_adapters.phpindex 49c028de4d..09caf558fa 100644--- a/resources/lang/en-US/admin/settings/sync_adapters.php+++ b/resources/lang/en-US/admin/settings/sync_adapters.php@@ -180,8 +180,13 @@ return ['jamf_client_secret_help' => 'Paired with the Client ID above. Jamf Pro shows the secret once at API Client creation time.','jamf_label_include_mobile_devices' => 'Include mobile devices','jamf_include_mobile_devices_help' => 'When enabled, Snipe-IT also pulls iOS / iPadOS / tvOS devices from Jamf Pro alongside computers. The API Role you created above must additionally grant Read on Mobile Devices for this to work.',+ 'jamf_group_filter_label' => 'Group filter',+ 'jamf_group_filter_help' => 'Comma-separated Jamf Pro Smart or Static Computer Group names (or IDs) to limit the sync to. Only devices that belong to any of these groups are synced, everything else is skipped. Leave blank to sync every device the API Client can see. If you enable the mobile toggle above, the same names are also resolved against Mobile Device Groups, so a group named "Law School" that exists in both namespaces filters both fleets. The API Role you created above must grant Read on Computer Groups (and Read on Mobile Device Groups if you enable the mobile toggle) for this to work. Example: "Law School, Faculty Loaners".',+ 'jamf_extra_ram_gb' => 'Jamf RAM (GB)',+ 'jamf_extra_storage_gb' => 'Jamf storage (GB)','jamf_extra_mobile_device_type' => 'Jamf mobile device type','jamf_extra_mobile_managed' => 'Jamf mobile managed',+ 'jamf_extra_mobile_storage_gb' => 'Jamf mobile storage (GB)','jamf_extra_mobile_supervised' => 'Jamf mobile supervised','jamf_school_network_id_help' => 'Find your Network ID under Organization -> Settings -> API in the Jamf School admin console.','jamf_school_api_key_help' => 'Generate under Organization -> Settings -> API in Jamf School. Needs read access to Devices (and Locations if you use group-to-company mapping).',@@ -252,9 +257,9 @@ return ['intune_extra_ownership' => 'Intune Ownership','intune_extra_wifi_mac' => 'Intune Wi-Fi MAC','intune_extra_ethernet_mac' => 'Intune Ethernet MAC',- 'intune_extra_total_storage_bytes' => 'Intune Total Storage (bytes)',- 'intune_extra_free_storage_bytes' => 'Intune Free Storage (bytes)',- 'intune_extra_physical_memory_bytes' => 'Intune Physical Memory (bytes)',+ 'intune_extra_total_storage_gb' => 'Intune Total Storage (GB)',+ 'intune_extra_free_storage_gb' => 'Intune Free Storage (GB)',+ 'intune_extra_physical_memory_gb' => 'Intune Physical Memory (GB)','intune_extra_is_encrypted' => 'Intune Encrypted','intune_extra_jail_broken' => 'Intune Jailbroken','intune_extra_is_supervised' => 'Intune Supervised',@@ -588,8 +593,8 @@ return ['abm_extra_mdm_device_lock_status' => 'AxM MDM Device Lock Status','abm_extra_mdm_lost_mode_status' => 'AxM MDM Lost Mode Status','abm_extra_mdm_device_erase_status' => 'AxM MDM Device Erase Status',- 'abm_extra_mdm_storage_total' => 'AxM MDM Storage Total',- 'abm_extra_mdm_storage_free' => 'AxM MDM Storage Free',+ 'abm_extra_mdm_storage_total_gb' => 'AxM MDM Storage Total (GB)',+ 'abm_extra_mdm_storage_free_gb' => 'AxM MDM Storage Free (GB)',// ManageEngine Endpoint Central adapter.'endpoint_central_label_mode' => 'Deployment',diff --git a/tests/Feature/Migrations/NormalizeSyncAdapterStorageExtrasToGbTest.php b/tests/Feature/Migrations/NormalizeSyncAdapterStorageExtrasToGbTest.phpnew file mode 100644index 0000000000..7d5edcc2f9--- /dev/null+++ b/tests/Feature/Migrations/NormalizeSyncAdapterStorageExtrasToGbTest.php@@ -0,0 +1,144 @@+<?php++namespace Tests\Feature\Migrations;++use App\Models\SyncAdapterInstance;+use Illuminate\Support\Facades\DB;+use Illuminate\Support\Facades\Schema;+use Tests\TestCase;++class NormalizeSyncAdapterStorageExtrasToGbTest extends TestCase+{+ private function runMigration(): void+ {+ $migration = require database_path('migrations/2026_11_03_212634_normalize_sync_adapter_storage_extras_to_gb.php');+ $migration->up();+ }++ private function freshCustomFieldColumn(string $suffix): string+ {+ $column = '_snipeit_test_'.str_replace(' ', '_', strtolower($suffix)).'_'.uniqid();+ Schema::table('assets', function ($table) use ($column) {+ $table->text($column)->nullable();+ });++ return $column;+ }++ public function test_renames_byte_source_mapping_keys_to_gb_in_config_json(): void+ {+ $column = $this->freshCustomFieldColumn('Storage Test A');+ $instance = SyncAdapterInstance::create([+ 'slug' => 'test-intune-'.uniqid(),+ 'adapter_type' => 'intune',+ 'label' => 'Test Intune',+ 'config' => [+ 'mapping.intune_total_storage_bytes' => $column,+ 'mapping.intune_free_storage_bytes' => $column,+ 'mapping.intune_physical_memory_bytes' => $column,+ 'mapping.abm_mdm_storage_total' => $column,+ 'mapping.abm_mdm_storage_free' => $column,+ 'mapping.unrelated_field' => 'something_else',+ ],+ ]);++ $this->runMigration();++ $instance->refresh();+ $config = $instance->config;++ $this->assertArrayNotHasKey('mapping.intune_total_storage_bytes', $config);+ $this->assertArrayNotHasKey('mapping.intune_free_storage_bytes', $config);+ $this->assertArrayNotHasKey('mapping.intune_physical_memory_bytes', $config);+ $this->assertArrayNotHasKey('mapping.abm_mdm_storage_total', $config);+ $this->assertArrayNotHasKey('mapping.abm_mdm_storage_free', $config);++ $this->assertSame($column, $config['mapping.intune_total_storage_gb']);+ $this->assertSame($column, $config['mapping.intune_free_storage_gb']);+ $this->assertSame($column, $config['mapping.intune_physical_memory_gb']);+ $this->assertSame($column, $config['mapping.abm_mdm_storage_total_gb']);+ $this->assertSame($column, $config['mapping.abm_mdm_storage_free_gb']);++ // Non-renamed mappings survive untouched.+ $this->assertSame('something_else', $config['mapping.unrelated_field']);+ }++ public function test_converts_stored_byte_values_in_mapped_columns_to_gb(): void+ {+ $column = $this->freshCustomFieldColumn('Storage Test B');++ SyncAdapterInstance::create([+ 'slug' => 'test-intune-'.uniqid(),+ 'adapter_type' => 'intune',+ 'label' => 'Test Intune',+ 'config' => [+ 'mapping.intune_total_storage_bytes' => $column,+ ],+ ]);++ // Simulate a previously-synced asset with a byte value in the+ // custom field column. 494 GB = 494000000000 bytes.+ $assetId = DB::table('assets')->insertGetId([+ 'name' => 'test-mac-01',+ 'asset_tag' => 'TEST-0001',+ $column => '494000000000',+ 'created_at' => now(),+ 'updated_at' => now(),+ ]);++ $this->runMigration();++ $value = DB::table('assets')->where('id', $assetId)->value($column);+ $this->assertEquals(494, (float) $value);+ }++ public function test_skips_columns_that_are_not_on_the_assets_table(): void+ {+ /*+ * Instance mapping references a custom-field column that no+ * longer exists on assets (admin deleted the custom field).+ * The migration should rename the mapping key without choking.+ */+ $slug = 'test-abm-'.uniqid();+ SyncAdapterInstance::create([+ 'slug' => $slug,+ 'adapter_type' => 'abm',+ 'label' => 'Test AxM',+ 'config' => [+ 'mapping.abm_mdm_storage_total' => '_snipeit_nonexistent_column_999',+ ],+ ]);++ $this->runMigration();++ $instance = SyncAdapterInstance::where('slug', $slug)->firstOrFail();+ $this->assertArrayHasKey('mapping.abm_mdm_storage_total_gb', $instance->config);+ $this->assertArrayNotHasKey('mapping.abm_mdm_storage_total', $instance->config);+ }++ public function test_leaves_null_custom_field_values_alone(): void+ {+ $column = $this->freshCustomFieldColumn('Storage Test C');++ SyncAdapterInstance::create([+ 'slug' => 'test-intune-'.uniqid(),+ 'adapter_type' => 'intune',+ 'label' => 'Test Intune',+ 'config' => [+ 'mapping.intune_total_storage_bytes' => $column,+ ],+ ]);++ $assetId = DB::table('assets')->insertGetId([+ 'name' => 'never-synced',+ 'asset_tag' => 'TEST-NULL',+ $column => null,+ 'created_at' => now(),+ 'updated_at' => now(),+ ]);++ $this->runMigration();++ $this->assertNull(DB::table('assets')->where('id', $assetId)->value($column));+ }+}diff --git a/tests/Feature/SyncAdapters/AppleBusinessManager/MdmDeviceEnrichmentTest.php b/tests/Feature/SyncAdapters/AppleBusinessManager/MdmDeviceEnrichmentTest.phpindex 89c5e38b79..52728e89b9 100644--- a/tests/Feature/SyncAdapters/AppleBusinessManager/MdmDeviceEnrichmentTest.php+++ b/tests/Feature/SyncAdapters/AppleBusinessManager/MdmDeviceEnrichmentTest.php@@ -122,8 +122,8 @@ class MdmDeviceEnrichmentTest extends TestCase'deviceLockStatus' => 'UNLOCKED','lostModeStatus' => 'DISABLED','deviceEraseStatus' => 'NORMAL',- 'storageTotalCapacity' => 494,- 'storageFreeCapacity' => 353,+ 'storageTotalCapacity' => 494000000000,+ 'storageFreeCapacity' => 353000000000,],],]),@@ -146,8 +146,8 @@ class MdmDeviceEnrichmentTest extends TestCase$this->assertSame('UNLOCKED', $record->extra['abm_mdm_device_lock_status']);$this->assertSame('DISABLED', $record->extra['abm_mdm_lost_mode_status']);$this->assertSame('NORMAL', $record->extra['abm_mdm_device_erase_status']);- $this->assertSame(494, $record->extra['abm_mdm_storage_total']);- $this->assertSame(353, $record->extra['abm_mdm_storage_free']);+ $this->assertSame(494, $record->extra['abm_mdm_storage_total_gb']);+ $this->assertSame(353, $record->extra['abm_mdm_storage_free_gb']);}public function test_ethernet_mac_used_when_wifi_missing()diff --git a/tests/Feature/SyncAdapters/Intune/IntuneAdminExtrasTest.php b/tests/Feature/SyncAdapters/Intune/IntuneAdminExtrasTest.phpindex 94f814ad23..208a6d3e6d 100644--- a/tests/Feature/SyncAdapters/Intune/IntuneAdminExtrasTest.php+++ b/tests/Feature/SyncAdapters/Intune/IntuneAdminExtrasTest.php@@ -77,8 +77,8 @@ class IntuneAdminExtrasTest extends TestCase$record = iterator_to_array($adapter->pull())[0];$this->assertSame('01:23:45:67:89:AB', $record->extra['intune_wifi_mac']);- $this->assertSame(494000000000, $record->extra['intune_total_storage_bytes']);- $this->assertSame(353000000000, $record->extra['intune_free_storage_bytes']);+ $this->assertSame(494, $record->extra['intune_total_storage_gb']);+ $this->assertSame(353, $record->extra['intune_free_storage_gb']);$this->assertTrue($record->extra['intune_is_encrypted']);$this->assertSame('Unknown', $record->extra['intune_jail_broken']);$this->assertFalse($record->extra['intune_is_supervised']);@@ -117,7 +117,7 @@ class IntuneAdminExtrasTest extends TestCase$record = iterator_to_array($adapter->pull())[0];$this->assertNull($record->extra['intune_ethernet_mac']);- $this->assertNull($record->extra['intune_physical_memory_bytes']);+ $this->assertNull($record->extra['intune_physical_memory_gb']);}public function test_per_device_enrichment_backfills_ethernet_mac_and_physical_memory()@@ -150,7 +150,8 @@ class IntuneAdminExtrasTest extends TestCase$record = iterator_to_array($adapter->pull())[0];$this->assertSame('DE:AD:BE:EF:00:01', $record->extra['intune_ethernet_mac']);- $this->assertSame(17179869184, $record->extra['intune_physical_memory_bytes']);+ // 17179869184 bytes / 1e9 = 17.179869184, rounded to 17.18 GB.+ $this->assertSame(17.18, $record->extra['intune_physical_memory_gb']);}public function test_admin_defined_extras_overlay_on_vendor_record()diff --git a/tests/Feature/SyncAdapters/Jamf/JamfAdapterTest.php b/tests/Feature/SyncAdapters/Jamf/JamfAdapterTest.phpindex e51edf4fe4..9d3e777949 100644--- a/tests/Feature/SyncAdapters/Jamf/JamfAdapterTest.php+++ b/tests/Feature/SyncAdapters/Jamf/JamfAdapterTest.php@@ -110,6 +110,155 @@ class JamfAdapterTest extends TestCase$this->assertNotNull($record->lastSeen);}+ public function test_computer_ram_and_boot_disk_storage_are_extracted()+ {+ /*+ * Jamf STORAGE section can list more than one disk when an+ * external drive is plugged in at inventory time. The boot disk+ * is the one whose partitions contain a partitionType=BOOT+ * entry. The adapter must land on the internal boot disk's size,+ * not the external drive's or the sum of both.+ */+ $adapter = $this->configuredJamfAdapter();++ Http::fake([+ '*/api/oauth/token' => $this->jamfTokenResponse(),+ '*/api/v1/computers-inventory*' => Http::response([+ 'totalCount' => 1,+ 'results' => [+ $this->jamfComputer(+ id: 42,+ name: 'design-mbp',+ model: 'MacBook Pro',+ totalRamMegabytes: 32768,+ storageDisks: [+ [+ 'device' => 'disk0',+ 'sizeMegabytes' => 1000000,+ 'partitions' => [+ ['name' => 'Macintosh HD', 'partitionType' => 'BOOT'],+ ['name' => 'Recovery', 'partitionType' => 'RECOVERY'],+ ],+ ],+ [+ 'device' => 'disk2',+ 'sizeMegabytes' => 4000000,+ 'partitions' => [+ ['name' => 'External SSD', 'partitionType' => 'OTHER'],+ ],+ ],+ ],+ ),+ ],+ ]),+ ]);++ $records = iterator_to_array($adapter->pull());++ $this->assertCount(1, $records);+ $this->assertSame(32.77, $records[0]->extra['jamf_ram_gb']);+ $this->assertSame(+ 1000,+ $records[0]->extra['jamf_storage_gb'],+ 'Boot disk (disk0, with partitionType=BOOT) wins over the larger external drive.',+ );+ }++ public function test_storage_falls_back_to_first_disk_when_no_boot_partition_tagged()+ {+ /*+ * Older Jamf versions don't always tag a partition as BOOT. In+ * that case fall back to disks[0] because on every modern Mac+ * the internal SSD reports as disk0 and external drives come+ * later. The fallback keeps RAM + storage reporting useful+ * without pretending we have signal we don't.+ */+ $adapter = $this->configuredJamfAdapter();++ Http::fake([+ '*/api/oauth/token' => $this->jamfTokenResponse(),+ '*/api/v1/computers-inventory*' => Http::response([+ 'totalCount' => 1,+ 'results' => [+ $this->jamfComputer(+ id: 42,+ storageDisks: [+ [+ 'device' => 'disk0',+ 'sizeMegabytes' => 500000,+ 'partitions' => [+ ['name' => 'Untagged', 'partitionType' => 'OTHER'],+ ],+ ],+ ],+ ),+ ],+ ]),+ ]);++ $records = iterator_to_array($adapter->pull());++ $this->assertSame(500, $records[0]->extra['jamf_storage_gb']);+ }++ public function test_storage_is_null_when_jamf_returns_no_storage_section()+ {+ $adapter = $this->configuredJamfAdapter();++ Http::fake([+ '*/api/oauth/token' => $this->jamfTokenResponse(),+ '*/api/v1/computers-inventory*' => Http::response([+ 'totalCount' => 1,+ 'results' => [+ $this->jamfComputer(id: 42, totalRamMegabytes: null, storageDisks: null),+ ],+ ]),+ ]);++ $records = iterator_to_array($adapter->pull());++ $this->assertNull($records[0]->extra['jamf_storage_gb']);+ $this->assertNull($records[0]->extra['jamf_ram_gb']);+ }++ public function test_mobile_record_includes_storage_capacity()+ {+ $adapter = $this->configuredJamfAdapter(includeMobile: true);++ Http::fake([+ '*/api/oauth/token' => $this->jamfTokenResponse(),+ '*/api/v1/computers-inventory*' => Http::response(['totalCount' => 0, 'results' => []]),+ '*/api/v2/mobile-devices*' => Http::response([+ 'totalCount' => 1,+ 'results' => [+ [+ 'id' => '77',+ 'name' => 'law-ipad-01',+ 'udid' => 'jamf-mobile-udid-77',+ 'serialNumber' => 'DMPXYZ',+ 'assetTag' => null,+ 'model' => 'iPad Pro',+ 'modelIdentifier' => 'iPad13,1',+ 'deviceType' => 'ios',+ 'osType' => 'iOS',+ 'osVersion' => '17.4',+ 'wifiMacAddress' => null,+ 'ipAddress' => null,+ 'lastInventoryUpdateTimestamp' => null,+ 'managed' => true,+ 'supervised' => true,+ 'capacityMb' => 256000,+ 'location' => ['username' => null, 'emailAddress' => null],+ ],+ ],+ ]),+ ]);++ $records = iterator_to_array($adapter->pull());++ $this->assertSame(256, $records[0]->extra['jamf_mobile_storage_gb']);+ }+public function test_mobile_devices_pulled_when_toggle_is_on(){$adapter = $this->configuredJamfAdapter(includeMobile: true);@@ -289,13 +438,174 @@ class JamfAdapterTest extends TestCase$this->assertSame('throttled-mac', $records[0]->hostname);}- private function configuredJamfAdapter(bool $includeMobile = false): JamfAdapter+ public function test_group_filter_narrows_computers_by_smart_group_membership()+ {+ $adapter = $this->configuredJamfAdapter(groupFilter: 'Law School Macs, 7');++ Http::fake([+ '*/api/oauth/token' => $this->jamfTokenResponse(),+ // Specific member-detail URLs first so Laravel's first-match+ // fake dispatch doesn't catch them in the broader+ // /computergroups list pattern below.+ '*/JSSResource/computergroups/id/3' => Http::response([+ 'computer_group' => [+ 'id' => 3,+ 'name' => 'Law School Macs',+ 'computers' => [+ ['id' => 42, 'name' => 'law-mac-01'],+ ],+ ],+ ]),+ '*/JSSResource/computergroups/id/7' => Http::response([+ 'computer_group' => [+ 'id' => 7,+ 'name' => 'Faculty Loaners',+ 'computers' => [+ ['id' => 99, 'name' => 'loaner-mac-01'],+ ],+ ],+ ]),+ '*/JSSResource/computergroups' => Http::response([+ 'computer_groups' => [+ ['id' => 3, 'name' => 'Law School Macs', 'is_smart' => true],+ ['id' => 7, 'name' => 'Faculty Loaners', 'is_smart' => true],+ ['id' => 11, 'name' => 'Medical School Macs', 'is_smart' => true],+ ],+ ]),+ '*/api/v1/computers-inventory*' => Http::response([+ 'totalCount' => 3,+ 'results' => [+ $this->jamfComputer(id: 42, name: 'law-mac-01', model: 'MacBook Pro'),+ $this->jamfComputer(id: 99, name: 'loaner-mac-01', model: 'MacBook Air'),+ $this->jamfComputer(id: 500, name: 'med-mac-01', model: 'iMac'),+ ],+ ]),+ ]);++ $records = iterator_to_array($adapter->pull());++ $this->assertCount(2, $records);+ $hostnames = array_map(fn ($r) => $r->hostname, $records);+ $this->assertContains('law-mac-01', $hostnames);+ $this->assertContains('loaner-mac-01', $hostnames);+ $this->assertNotContains('med-mac-01', $hostnames);+ }++ public function test_group_filter_also_narrows_mobile_devices_when_mobile_toggle_on()+ {+ $adapter = $this->configuredJamfAdapter(includeMobile: true, groupFilter: 'Law School');++ Http::fake([+ '*/api/oauth/token' => $this->jamfTokenResponse(),+ '*/JSSResource/computergroups/id/3' => Http::response([+ 'computer_group' => [+ 'id' => 3,+ 'name' => 'Law School',+ 'computers' => [+ ['id' => 42, 'name' => 'law-mac-01'],+ ],+ ],+ ]),+ '*/JSSResource/computergroups' => Http::response([+ 'computer_groups' => [+ ['id' => 3, 'name' => 'Law School', 'is_smart' => true],+ ],+ ]),+ '*/JSSResource/mobiledevicegroups/id/8' => Http::response([+ 'mobile_device_group' => [+ 'id' => 8,+ 'name' => 'Law School',+ 'mobile_devices' => [+ ['id' => 10, 'name' => 'law-ipad-01'],+ ],+ ],+ ]),+ '*/JSSResource/mobiledevicegroups' => Http::response([+ 'mobile_device_groups' => [+ ['id' => 8, 'name' => 'Law School', 'is_smart' => true],+ ],+ ]),+ '*/api/v1/computers-inventory*' => Http::response([+ 'totalCount' => 2,+ 'results' => [+ $this->jamfComputer(id: 42, name: 'law-mac-01', model: 'MacBook Pro'),+ $this->jamfComputer(id: 500, name: 'med-mac-01', model: 'iMac'),+ ],+ ]),+ '*/api/v2/mobile-devices*' => Http::response([+ 'totalCount' => 2,+ 'results' => [+ $this->jamfMobileDevice(id: 10, name: 'law-ipad-01', model: 'iPad Pro'),+ $this->jamfMobileDevice(id: 20, name: 'med-ipad-01', model: 'iPad'),+ ],+ ]),+ ]);++ $records = iterator_to_array($adapter->pull());++ $hostnames = array_map(fn ($r) => $r->hostname, $records);+ $this->assertContains('law-mac-01', $hostnames);+ $this->assertContains('law-ipad-01', $hostnames);+ $this->assertNotContains('med-mac-01', $hostnames);+ $this->assertNotContains('med-ipad-01', $hostnames);+ }++ public function test_blank_group_filter_skips_group_resolution_calls()+ {+ $adapter = $this->configuredJamfAdapter(groupFilter: '');++ Http::fake([+ '*/api/oauth/token' => $this->jamfTokenResponse(),+ '*/api/v1/computers-inventory*' => Http::response([+ 'totalCount' => 1,+ 'results' => [$this->jamfComputer(id: 42, name: 'any-mac', model: 'iMac')],+ ]),+ ]);++ iterator_to_array($adapter->pull());++ Http::assertNotSent(fn ($request) => str_contains($request->url(), '/JSSResource/computergroups'));+ Http::assertNotSent(fn ($request) => str_contains($request->url(), '/JSSResource/mobiledevicegroups'));+ }++ public function test_group_filter_unresolvable_entry_does_not_crash_pull()+ {+ $adapter = $this->configuredJamfAdapter(groupFilter: 'Law School, Nonexistent Group');++ Http::fake([+ '*/api/oauth/token' => $this->jamfTokenResponse(),+ '*/JSSResource/computergroups/id/3' => Http::response([+ 'computer_group' => [+ 'id' => 3,+ 'name' => 'Law School',+ 'computers' => [['id' => 42, 'name' => 'law-mac-01']],+ ],+ ]),+ '*/JSSResource/computergroups' => Http::response([+ 'computer_groups' => [+ ['id' => 3, 'name' => 'Law School', 'is_smart' => true],+ ],+ ]),+ '*/api/v1/computers-inventory*' => Http::response([+ 'totalCount' => 1,+ 'results' => [$this->jamfComputer(id: 42, name: 'law-mac-01', model: 'iMac')],+ ]),+ ]);++ $records = iterator_to_array($adapter->pull());++ $this->assertCount(1, $records);+ $this->assertSame('law-mac-01', $records[0]->hostname);+ }++ private function configuredJamfAdapter(bool $includeMobile = false, string $groupFilter = ''): JamfAdapter{$instance = SyncAdapterInstance::where('slug', 'jamf')->firstOrFail();SyncAdapterConfig::put($instance->id, 'url', 'https://example.jamfcloud.com');SyncAdapterConfig::put($instance->id, 'client_id', Crypt::encrypt('fake-jamf-client-id'));SyncAdapterConfig::put($instance->id, 'client_secret', Crypt::encrypt('fake-jamf-client-secret'));SyncAdapterConfig::put($instance->id, 'include_mobile_devices', $includeMobile ? '1' : '0');+ SyncAdapterConfig::put($instance->id, 'group_filter', $groupFilter);return new JamfAdapter($instance->fresh());}@@ -363,6 +673,7 @@ class JamfAdapterTest extends TestCase}/**+ * @param array<int, array<string, mixed>>|null $storageDisks* @return array<string, mixed>*/private function jamfComputer(@@ -374,6 +685,8 @@ class JamfAdapterTest extends TestCase?string $osName = 'macOS',?string $osVersion = null,?string $lastContactTime = null,+ ?int $totalRamMegabytes = null,+ ?array $storageDisks = null,): array {return ['id' => (string) $id,@@ -389,11 +702,13 @@ class JamfAdapterTest extends TestCase'modelIdentifier' => 'Mac'.$id,'serialNumber' => $serialNumber,'macAddress' => $macAddress,+ 'totalRamMegabytes' => $totalRamMegabytes,],'operatingSystem' => ['name' => $osName,'version' => $osVersion,],+ 'storage' => $storageDisks !== null ? ['disks' => $storageDisks] : null,];}}