fix #135 avoid failing device import/enrol when unable to set AD description

This commit is contained in:
Gary Sharp
2023-10-12 17:37:42 +11:00
parent 6740a7479a
commit b6945d9bbd
7 changed files with 72 additions and 12 deletions
+10 -2
View File
@@ -5,6 +5,7 @@ using Disco.Services.Authorization;
using Disco.Services.Documents; using Disco.Services.Documents;
using Disco.Services.Expressions; using Disco.Services.Expressions;
using Disco.Services.Interop.ActiveDirectory; using Disco.Services.Interop.ActiveDirectory;
using Disco.Services.Logging;
using Disco.Services.Users; using Disco.Services.Users;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@@ -188,8 +189,15 @@ namespace Disco.Services
if (ActiveDirectory.IsValidDomainAccountId(d.DeviceDomainId)) if (ActiveDirectory.IsValidDomainAccountId(d.DeviceDomainId))
{ {
var adMachineAccount = ActiveDirectory.RetrieveADMachineAccount(d.DeviceDomainId); var adMachineAccount = ActiveDirectory.RetrieveADMachineAccount(d.DeviceDomainId);
if (adMachineAccount != null) try
adMachineAccount.SetDescription(d); {
if (adMachineAccount != null)
adMachineAccount.SetDescription(d);
}
catch (Exception ex)
{
SystemLog.LogWarning($"Unable to update AD Machine Account Description for {d.DeviceDomainId}: {ex.Message}");
}
} }
return newDua; return newDua;
@@ -579,11 +579,18 @@ namespace Disco.Services.Devices.Enrolment
if (adMachineAccount != null && !adMachineAccount.IsCriticalSystemObject) if (adMachineAccount != null && !adMachineAccount.IsCriticalSystemObject)
{ {
EnrolmentLog.LogSessionProgress(sessionId, 75, "Updating Active Directory Computer Account Properties"); EnrolmentLog.LogSessionProgress(sessionId, 75, "Updating Active Directory Computer Account Properties");
// Use non-Wlan Adapter with fastest speed try
var macAddress = Request.Hardware?.NetworkAdapters?.Where(na => !na.IsWlanAdapter).OrderByDescending(na => na.Speed).Select(na => na.MACAddress).FirstOrDefault(); {
adMachineAccount.UpdateNetbootGUID(Request.Hardware.UUID, macAddress); // Use non-Wlan Adapter with fastest speed
if (RepoDevice.AssignedUser != null) var macAddress = Request.Hardware?.NetworkAdapters?.Where(na => !na.IsWlanAdapter).OrderByDescending(na => na.Speed).Select(na => na.MACAddress).FirstOrDefault();
adMachineAccount.SetDescription(RepoDevice); adMachineAccount.UpdateNetbootGUID(Request.Hardware.UUID, macAddress);
if (RepoDevice.AssignedUser != null)
adMachineAccount.SetDescription(RepoDevice);
}
catch (Exception ex)
{
EnrolmentLog.LogSessionWarning(sessionId, $"Unable to update AD Machine Account attributes: {ex.Message}");
}
} }
if (RepoDevice.DeviceProfile.DistributionType == DeviceProfile.DistributionTypes.OneToOne) if (RepoDevice.DeviceProfile.DistributionType == DeviceProfile.DistributionTypes.OneToOne)
{ {
@@ -2,6 +2,7 @@
using Disco.Models.Repository; using Disco.Models.Repository;
using Disco.Models.Services.Devices.Importing; using Disco.Models.Services.Devices.Importing;
using Disco.Services.Interop.ActiveDirectory; using Disco.Services.Interop.ActiveDirectory;
using Disco.Services.Logging;
using Disco.Services.Users; using Disco.Services.Users;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@@ -147,7 +148,15 @@ namespace Disco.Services.Devices.Importing.Fields
if (adAccount != null && !adAccount.IsCriticalSystemObject) if (adAccount != null && !adAccount.IsCriticalSystemObject)
{ {
adAccount.SetDescription(Device); try
{
adAccount.SetDescription(Device);
}
catch (Exception ex)
{
SystemLog.LogWarning($"Unable to update AD Machine Account Description for {Device.DeviceDomainId}: {ex.Message}");
throw;
}
DeviceADDescriptionSet = true; DeviceADDescriptionSet = true;
} }
} }
@@ -2,6 +2,7 @@
using Disco.Models.Repository; using Disco.Models.Repository;
using Disco.Models.Services.Devices.Importing; using Disco.Models.Services.Devices.Importing;
using Disco.Services.Interop.ActiveDirectory; using Disco.Services.Interop.ActiveDirectory;
using Disco.Services.Logging;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Data; using System.Data;
@@ -116,7 +117,15 @@ namespace Disco.Services.Devices.Importing.Fields
if (!DeviceADDescriptionSet) if (!DeviceADDescriptionSet)
{ {
adAccount.SetDescription(Device); try
{
adAccount.SetDescription(Device);
}
catch (Exception ex)
{
SystemLog.LogWarning($"Unable to update AD Machine Account Description for {Device.DeviceDomainId}: {ex.Message}");
throw;
}
DeviceADDescriptionSet = true; DeviceADDescriptionSet = true;
} }
} }
@@ -2,6 +2,7 @@
using Disco.Models.Repository; using Disco.Models.Repository;
using Disco.Models.Services.Devices.Importing; using Disco.Models.Services.Devices.Importing;
using Disco.Services.Interop.ActiveDirectory; using Disco.Services.Interop.ActiveDirectory;
using Disco.Services.Logging;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Data; using System.Data;
@@ -120,7 +121,15 @@ namespace Disco.Services.Devices.Importing.Fields
if (!DeviceADDescriptionSet) if (!DeviceADDescriptionSet)
{ {
adAccount.SetDescription(Device); try
{
adAccount.SetDescription(Device);
}
catch (Exception ex)
{
SystemLog.LogWarning($"Unable to update AD Machine Account Description for {Device.DeviceDomainId}: {ex.Message}");
throw;
}
DeviceADDescriptionSet = true; DeviceADDescriptionSet = true;
} }
} }
@@ -2,6 +2,7 @@
using Disco.Models.Repository; using Disco.Models.Repository;
using Disco.Models.Services.Devices.Importing; using Disco.Models.Services.Devices.Importing;
using Disco.Services.Interop.ActiveDirectory; using Disco.Services.Interop.ActiveDirectory;
using Disco.Services.Logging;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Data; using System.Data;
@@ -94,7 +95,15 @@ namespace Disco.Services.Devices.Importing.Fields
if (adAccount != null && !adAccount.IsCriticalSystemObject) if (adAccount != null && !adAccount.IsCriticalSystemObject)
{ {
adAccount.SetDescription(Device); try
{
adAccount.SetDescription(Device);
}
catch (Exception ex)
{
SystemLog.LogWarning($"Unable to update AD Machine Account Description for {Device.DeviceDomainId}: {ex.Message}");
throw;
}
DeviceADDescriptionSet = true; DeviceADDescriptionSet = true;
} }
} }
@@ -2,6 +2,7 @@
using Disco.Models.Repository; using Disco.Models.Repository;
using Disco.Models.Services.Devices.Importing; using Disco.Models.Services.Devices.Importing;
using Disco.Services.Interop.ActiveDirectory; using Disco.Services.Interop.ActiveDirectory;
using Disco.Services.Logging;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Data; using System.Data;
@@ -90,7 +91,15 @@ namespace Disco.Services.Devices.Importing.Fields
if (adAccount != null && !adAccount.IsCriticalSystemObject) if (adAccount != null && !adAccount.IsCriticalSystemObject)
{ {
adAccount.SetDescription(Device); try
{
adAccount.SetDescription(Device);
}
catch (Exception ex)
{
SystemLog.LogWarning($"Unable to update AD Machine Account Description for {Device.DeviceDomainId}: {ex.Message}");
throw;
}
DeviceADDescriptionSet = true; DeviceADDescriptionSet = true;
} }
} }