Set-AzureRmDiagnosticSetting in Module 5.1.0 does not work
Description
With 5.1.0 you introduced the new -Name parameter. Great! But unfortunately it does not work and the whole Cmdlet seems to be broken!
Script/Steps for Reproduction
If you specifiy the -name param or not, you will always get the error:
The diagnostic setting 'service' [or whatever name you entered] doesn't exist., Code: ResourceNotFound, Status code:NotFound, Reason phrase: Not Found
Module Version
5.1.0
Environment Data
$PSVersionTable
Debug Output
<Set-AzureRmDiagnosticSetting : Exception type: ErrorResponseException, Message: The diagnostic setting 'service' doesn't exist., Code: ResourceNotFound, Status code:NotFound, Reason phrase: Not Found At line:1 char:1
- Set-AzureRmDiagnosticSetting -ResourceId $r.Id -WorkspaceId /subscrip ...
-
+ CategoryInfo : CloseError: (:) [Set-AzureRmDiagnosticSetting], PSInvalidOperationException + FullyQualifiedErrorId : Microsoft.Azure.Commands.Insights.Diagnostics.SetAzureRmDiagnosticSettingCommand
@DirkBrinkmann Can you include some additional information so we can diagnose this:
Run $DebugPreference="Continue" and then execute the cmdlet and include the debug output.
Run Resolve-AzureRmError after the failure.
I am also confronted with the same problem with @DirkBrinkmann as well. In my case, I'm trying to set up a new diagnostic log for Azure SQL Database as shown below.
Import-Module AzureRM
Get-Module AzureRM
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Script 6.6.0 AzureRM
Get-Module AzureRM.Insights
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Script 5.1.0 AzureRM.Insights {Add-AzureRmAutoscaleSetting, Add-AzureRmLogProfile, Add-A...
$sqlDbInfo = Get-AzureRmSqlDatabase `
-DatabaseName "*****" `
-ServerName "*****" `
-ResourceGroupName "*****"
$storageInfo = Get-AzureRMStorageAccount `
-ResourceGroupName "*****" `
-Name "*****"
Set-AzureRmDiagnosticSetting `
-ResourceId "$($sqlDbInfo.ResourceId)" `
-StorageAccountId "$($storageInfo.Id)" `
-Enabled $true `
-RetentionEnabled $true `
-RetentionInDays 3
警告: 11:17:28 - *** The namespace for all the model classes will change from Microsoft.Azure.Management.Monitor.Management.Models to Microsoft.Azure.Management.Monitor.Models in future releases.
警告: 11:17:28 - *** The namespace for output classes will be uniform for all classes in future releases to make it independent of modifications in the model classes.
警告: 11:17:28 - The arguments Categories and Timegrains now have aliases Category and Timegrain respectively. The plural names will be removed in future releases.
Set-AzureRmDiagnosticSetting : Exception type: ErrorResponseException, Message: The diagnostic setting 'service' doesn't exist., Code: ResourceNotFound, Status code:NotFound, Reason phrase: Not Found
発生場所 行:1 文字:1
+ Set-AzureRmDiagnosticSetting `
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [Set-AzureRmDiagnosticSetting]、PSInvalidOperationException
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.Insights.Diagnostics.SetAzureRmDiagnosticSettingCommand
According to the advice from @markcowl, I will post the debug output.
Message : Exception type: ErrorResponseException, Message: The diagnostic setting 'service' doesn't exist., Code: ResourceNotFound, Status code:NotFound, Reason phrase: Not Found
StackTrace : 場所 Microsoft.Azure.Commands.Insights.MonitorCmdletBase.ExecuteCmdlet()
場所 Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.ProcessRecord()
Exception : System.Management.Automation.PSInvalidOperationException
InvocationInfo : {Set-AzureRmDiagnosticSetting}
Line : Set-AzureRmDiagnosticSetting `
Position : 発生場所 行:1 文字:1
+ Set-AzureRmDiagnosticSetting `
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId : 10
Message : Operation returned an invalid status code 'NotFound'
StackTrace : 場所 Microsoft.Azure.Management.Monitor.DiagnosticSettingsOperations.<GetWithHttpMessagesAsync>d__5.MoveNext()
--- 直前に例外がスローされた場所からのスタック トレースの終わり ---
場所 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
場所 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
場所 Microsoft.Azure.Management.Monitor.DiagnosticSettingsOperationsExtensions.<GetAsync>d__1.MoveNext()
Exception : Microsoft.Azure.Management.Monitor.Models.ErrorResponseException
InvocationInfo : {Set-AzureRmDiagnosticSetting}
Line : Set-AzureRmDiagnosticSetting `
Position : 発生場所 行:1 文字:1
+ Set-AzureRmDiagnosticSetting `
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId : 10
@markcowl: Are you fine with @Orange-MM Output?
We are also facing the same issue. @markcowl Could you please provide an update on this issue?
@markcowl We're also seeing the below exception when passing PT1M as Timegrain.
Set-AzureRmDiagnosticSetting : Metric timegrain 'PT1M' is not available
At D:\Set-AzureRmDiagnosticSetting.ps1:64 char:19
... agnostics = Set-AzureRmDiagnosticSetting -ResourceId $ResourceId -Ena ...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CategoryInfo : CloseError: (:) [Set-AzureRmDiagnosticSetting], ArgumentException
FullyQualifiedErrorId : Microsoft.Azure.Commands.Insights.Diagnostics.SetAzureRmDiagnosticSettingCommand
Also having this issue.
@markcowl: It is additional information.
- This problem occurred when "Set-AzureRmDiagnosticSetting" was executed with the diagnostic setting turned off.
- This problem didn't occur if you executed the "Set-AzureRmDiagnosticSetting" after setting the diagnostic setting to name = "service" from Azure portal and turning it on first.
I'm getting similar results on Get-AzureRmDiagnosticSetting. Prior to that, the issue was that Get-AzureRmDiagnosticSetting wrongly reported the audit log enable status on Key Vault diagnostics (same goes for Storage) as False when it's certainly set to True. So I uninstalled AzureRm entirely and reinstalled to 6.6.0. Now, even though the resource ID is valid and logging is in place, I get 'NotFound' status similar to others.
Latest output as follows:
Get-AzureRmDiagnosticSetting : Operation returned an invalid status code 'NotFound' At line:4 char:1
- Get-AzureRmDiagnosticSetting -ResourceId "/subscriptions/xxxxxxxx-xxx ... ...
-
+ CategoryInfo : CloseError: (:) [Get-AzureRmDiagnosticSetting], ErrorResponseException + FullyQualifiedErrorId : Microsoft.Azure.Commands.Insights.Diagnostics.GetAzureRmDiagnosticSettingCommand
DEBUG: AzureQoSEvent: CommandName - Get-AzureRmDiagnosticSetting; IsSuccess - False; Duration - 00:00:00.9711528; Exception - Microsoft.Azure.Man
agement.Monitor.Models.ErrorResponseException: Operation returned an invalid status code 'NotFound'
at Microsoft.Azure.Management.Monitor.DiagnosticSettingsOperations.
HistoryId: 3
Message : Operation returned an invalid status code 'NotFound'
StackTrace : at Microsoft.Azure.Management.Monitor.DiagnosticSettingsOperations.
Position : At line:4 char:1 + Get-AzureRmDiagnosticSetting -ResourceId "/subscriptions/xxxxxxxx-xxx ... ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ HistoryId : 3
HistoryId: 2
Message : Operation returned an invalid status code 'NotFound'
StackTrace : at Microsoft.Azure.Management.Monitor.DiagnosticSettingsOperations.
DEBUG: AzureQoSEvent: CommandName - Resolve-AzureRmError; IsSuccess - True; Duration - 00:00:00.2659345; Exception - ; DEBUG: Finish sending metric. DEBUG: 7:51:23 AM - ResolveError end processing. DEBUG: 7:51:23 AM - ResolveError end processing.
I'm seeing the same issue when attempting to set diagnostics on Application Gateways.
Message : Exception type: ErrorResponseException, Message: The diagnostic setting 'service' doesn't exist., Code: ResourceNotFound, Status
code:NotFound, Reason phrase: Not Found
StackTrace : at Microsoft.Azure.Commands.Insights.MonitorCmdletBase.ExecuteCmdlet()
at Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.ProcessRecord()
Exception : System.Management.Automation.PSInvalidOperationException
InvocationInfo : {Set-AzureRmDiagnosticSetting}
Line : Set-AzureRmDiagnosticSetting `
Position : At C:\OpsgilityTraining\EnableWAGDiagnostics.ps1:34 char:1
+ Set-AzureRmDiagnosticSetting `
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId : 17
Message : Operation returned an invalid status code 'NotFound'
StackTrace : at Microsoft.Azure.Management.Monitor.DiagnosticSettingsOperations.<GetWithHttpMessagesAsync>d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Azure.Management.Monitor.DiagnosticSettingsOperationsExtensions.<GetAsync>d__1.MoveNext()
Exception : Microsoft.Azure.Management.Monitor.Models.ErrorResponseException
InvocationInfo : {Set-AzureRmDiagnosticSetting}
Line : Set-AzureRmDiagnosticSetting `
Also getting the same issue when trying to simply register a Network Security Group
@markcowl: It is additional information.
I confirmed this problem at AzureRM.Insights Version 5.1.1, just in case. An error occurred just like Version 5.1.0.
@DirkBrinkmann @Orange-MM @ciphertxt @a138076 @jrgithub This should be resolved by: #7021
@gucalder - please close after this fix is in and verified.
This shopuld be fixed here: https://github.com/Azure/azure-powershell/pull/7021 and will hopefully be released in one of the next two releases.
@markcowl Why is this issue closed when fix is still not in the official production-ready release?
"will hopefully be released in one of the next two releases". Why waiting for two releases? The fix is ready or not. Issue is reported 21 days ago. It affects so many users and the regression is so basic and should not even happen with proper testing. This is really bad.
@markcowl : Just updated to Insights Module 5.1.2 It seems to work, BUT: After using the Cmdlet, you don't see any Diagnostic Setting in the Portal OR can retrieve it via get-azurermdiagnosticsettings ....
See attached Screenshot

AND: The Workspace also shows this resource as NOT connected:

Cmdlet Version:

@alexandair The proper verbage should have been 'this will be in one of the next two releases'. This fix came in during the middle of a release process, so it was unclear if it would be included in that release or the next one when merged.
Up until now, we have resolved issues as the fixes are merged. Given that we release every two weeks, this has so far been sufficient. If people feel that this is confusing, we can revisit.
@DirkBrinkmann The new module should be out today. If this doesn't appear to fix your problem, please let us know and we will reopen and prioritize a fix for the next release.
Reopening per Dirk's report
@gucalder Can you validate wither there is some issue with settings added through the Set-* cmdlet as Dirk reports? Is there any reson these would not show up when listing in powershell or the portal?