|
| 1 | +--- |
| 2 | +title: "Troubleshoot extension" |
| 3 | +description: "Describes how to troubleshoot SQL Server enabled by Azure Arc extension." |
| 4 | +author: MikeRayMSFT |
| 5 | +ms.author: mikeray |
| 6 | +ms.date: 06/03/2024 |
| 7 | +ms.topic: troubleshooting-general |
| 8 | +--- |
| 9 | + |
| 10 | +# Troubleshoot Azure extension for SQL Server |
| 11 | + |
| 12 | +[!INCLUDE [sqlserver](../../includes/applies-to-version/sqlserver.md)] |
| 13 | + |
| 14 | +This article provides two examples that return a list of servers with unhealthy extensions. |
| 15 | + |
| 16 | +## Identify unhealthy extensions |
| 17 | + |
| 18 | +This query returns instances of SQL Server on servers with extensions installed, but not healthy. The dates are hard-coded into the query. It returns resources where the extension status is unhealthy, or the extension last upload time isn't in May 2024 (`2024/05`) or June 2024 (`2024/06`). Replace those dates for your resources. |
| 19 | + |
| 20 | +```kusto |
| 21 | +resources |
| 22 | +| where type == "microsoft.hybridcompute/machines/extensions" |
| 23 | +| where properties.type in ("WindowsAgent.SqlServer","LinuxAgent.SqlServer") |
| 24 | +| where properties.instanceView.status.message !contains "SQL Server Extension Agent: Healthy" or (properties.instanceView.status.message !contains "timestampUTC : 2024/05" and properties.instanceView.status.message !contains "timestampUTC : 2024/06") or properties.instanceView.status.message !contains "uploadStatus : OK" |
| 25 | +| project id, resourceGroup, subscriptionId, |
| 26 | + ExtensionHealth = iif(properties.instanceView.status.message !contains "SQL Server Extension Agent: Healthy", "Unhealthy", "Healthy"), |
| 27 | + LastUpdloadTimestamp = iif(indexof(properties.instanceView.status.message,"timestampUTC : ") > 0, iif(properties.instanceView.status.message !contains "timestampUTC : 2024/06", substring(properties.instanceView.status.message,indexof(properties.instanceView.status.message,"timestampUTC : ") + 15, 10),"Recent"),"no timestamp"), |
| 28 | + LastUploadStatus = iif(indexof(properties.instanceView.status.message,"uploadStatus : OK") > 0, "OK", "Unhealthy"), |
| 29 | + Message = properties.instanceView.status.message |
| 30 | +``` |
| 31 | + |
| 32 | +To identify possible specific problems, review the value in the **Message** property from the query results. |
| 33 | + |
| 34 | +#### Identify unhealthy extension (PowerShell) |
| 35 | + |
| 36 | +This example runs in PowerShell. With PowerShell, you can run with dates that aren't hard coded. The example returns resource where the extension status is unhealthy, or the extension last upload time isn't in this month or the previous month. |
| 37 | + |
| 38 | +```powershell |
| 39 | +# PowerShell script to execute an Azure Resource Graph query using Azure CLI |
| 40 | +# where the extension status is unhealthy or the extension last upload time isn't in this month or the previous month. |
| 41 | +
|
| 42 | +# Requires the Az.ResourceGraph PowerShell module |
| 43 | +
|
| 44 | +# Login to Azure if needed |
| 45 | +#az login |
| 46 | +
|
| 47 | +$currentYear = (Get-Date).Year |
| 48 | +$currentMonth = "{0:D2}" -f (Get-Date).Month |
| 49 | +$previousMonth = "{0:D2}" -f ((Get-Date).Month-1) |
| 50 | +$currentDay = "{0:D2}" -f (Get-Date).Day |
| 51 | +$currentYearMonth = "$currentYear/$currentMonth" |
| 52 | +$previousYearMonth = "$currentYear/$previousMonth" |
| 53 | +$currentDate = "$currentYear/$currentMonth/$currentDay" |
| 54 | +
|
| 55 | +# Define the Azure Resource Graph query |
| 56 | +$query = @" |
| 57 | +Resources |
| 58 | +| where type == 'microsoft.hybridcompute/machines/extensions' |
| 59 | +| where properties.type in ('WindowsAgent.SqlServer','LinuxAgent.SqlServer') |
| 60 | +| where properties.instanceView.status.message !contains 'SQL Server Extension Agent: Healthy' |
| 61 | + or (properties.instanceView.status.message !contains 'timestampUTC : $previousYearMonth' |
| 62 | + and properties.instanceView.status.message !contains 'timestampUTC : $currentYearMonth') |
| 63 | + or properties.instanceView.status.message !contains 'uploadStatus : OK' |
| 64 | +| project id, resourceGroup, subscriptionId, |
| 65 | + ExtensionHealth = iif(properties.instanceView.status.message !contains 'SQL Server Extension Agent: Healthy', 'Unhealthy', 'Healthy'), |
| 66 | + LastUpdloadTimestamp = iif(indexof(properties.instanceView.status.message,'timestampUTC : ') > 0, iif(properties.instanceView.status.message !contains 'timestampUTC : $currentYearMonth', substring(properties.instanceView.status.message,indexof(properties.instanceView.status.message,'timestampUTC : ') + 15, 10),'Recent'),'no timestamp'), |
| 67 | + LastUploadStatus = iif(indexof(properties.instanceView.status.message,'uploadStatus : OK') > 0, 'OK', 'Unhealthy'), |
| 68 | + Message = properties.instanceView.status.message |
| 69 | +"@ |
| 70 | +
|
| 71 | +# Execute the Azure Resource Graph query |
| 72 | +$result = Search-AzGraph -Query $query |
| 73 | +
|
| 74 | +# Output the results |
| 75 | +$result | Format-Table -Property ExtensionHealth, LastUpdloadTimestamp, LastUploadStatus, Message |
| 76 | +``` |
| 77 | + |
| 78 | +To identify possible specific problems, review the value in the **Message** column from the results. |
0 commit comments