azure-powershell icon indicating copy to clipboard operation
azure-powershell copied to clipboard

Set-AzureRmDiagnosticSetting in Module 5.1.0 does not work

Open DirkBrinkmann opened this issue 8 years ago • 43 comments

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 avatar Aug 02 '18 09:08 DirkBrinkmann

@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.

markcowl avatar Aug 02 '18 23:08 markcowl

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

Orange-MM avatar Aug 03 '18 02:08 Orange-MM

@markcowl: Are you fine with @Orange-MM Output?

DirkBrinkmann avatar Aug 03 '18 05:08 DirkBrinkmann

We are also facing the same issue. @markcowl Could you please provide an update on this issue?

vinaydam avatar Aug 07 '18 10:08 vinaydam

@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

amoghnatu avatar Aug 07 '18 11:08 amoghnatu

Also having this issue.

seanke avatar Aug 07 '18 23:08 seanke

@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.

Orange-MM avatar Aug 08 '18 01:08 Orange-MM

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.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.d__1.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.Get(IDiagnosticSettingsOperations operations, String resourceUri, String name) at Microsoft.Azure.Commands.Insights.Diagnostics.GetAzureRmDiagnosticSettingCommand.ProcessRecordInternal() at Microsoft.Azure.Commands.Insights.MonitorCmdletBase.ExecuteCmdlet() at Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.ProcessRecord(); DEBUG: Finish sending metric. DEBUG: 7:51:22 AM - GetAzureRmDiagnosticSettingCommand end processing. DEBUG: 7:51:22 AM - GetAzureRmDiagnosticSettingCommand end processing. DEBUG: 7:51:22 AM - ResolveError begin processing with ParameterSet 'AnyErrorParameterSet'. DEBUG: 7:51:22 AM - using account id '[email protected]'...

HistoryId: 3

Message : Operation returned an invalid status code 'NotFound' StackTrace : at Microsoft.Azure.Management.Monitor.DiagnosticSettingsOperations.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.d__1.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.Get(IDiagnosticSettingsOperations operations, String resourceUri, String name) at Microsoft.Azure.Commands.Insights.Diagnostics.GetAzureRmDiagnosticSettingCommand.ProcessRecordInternal() at Microsoft.Azure.Commands.Insights.MonitorCmdletBase.ExecuteCmdlet() at Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.ProcessRecord() Exception : Microsoft.Azure.Management.Monitor.Models.ErrorResponseException InvocationInfo : {Get-AzureRmDiagnosticSetting} Line : Get-AzureRmDiagnosticSetting -ResourceId "/subscriptions/xxxxxxxx-xxx ...x-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/xxxres/providers/Microsoft.KeyVault/vaults/xxvault"

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.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.d__1.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.Get(IDiagnosticSettingsOperations operations, String resourceUri, String name) at Microsoft.Azure.Commands.Insights.Diagnostics.GetAzureRmDiagnosticSettingCommand.ProcessRecordInternal() at Microsoft.Azure.Commands.Insights.MonitorCmdletBase.ExecuteCmdlet() at Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.ProcessRecord() Exception : Microsoft.Azure.Management.Monitor.Models.ErrorResponseException InvocationInfo : {Get-AzureRmDiagnosticSetting} Line : Get-AzureRmDiagnosticSetting -ResourceId "/subscriptions/xxxxxxxx-xxx ...x-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/xxxres/providers/Microsoft.KeyVault/vaults/xxvault" Position : At line:2 char:1 + Get-AzureRmDiagnosticSetting -ResourceId "/subscriptions/xxxxxxxx-xxx ... ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ HistoryId : 2

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.

jrgithub avatar Aug 08 '18 12:08 jrgithub

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 `

ciphertxt avatar Aug 08 '18 17:08 ciphertxt

Also getting the same issue when trying to simply register a Network Security Group

Lachlan-White avatar Aug 10 '18 04:08 Lachlan-White

@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.

Orange-MM avatar Aug 16 '18 08:08 Orange-MM

@DirkBrinkmann @Orange-MM @ciphertxt @a138076 @jrgithub This should be resolved by: #7021

markcowl avatar Aug 22 '18 23:08 markcowl

@gucalder - please close after this fix is in and verified.

markcowl avatar Aug 22 '18 23:08 markcowl

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 avatar Aug 23 '18 23:08 markcowl

@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.

alexandair avatar Aug 24 '18 08:08 alexandair

@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 image

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

image

Cmdlet Version: image

DirkBrinkmann avatar Aug 29 '18 07:08 DirkBrinkmann

@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.

markcowl avatar Aug 29 '18 18:08 markcowl

@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.

markcowl avatar Aug 29 '18 18:08 markcowl

Reopening per Dirk's report

markcowl avatar Aug 29 '18 23:08 markcowl

@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?

markcowl avatar Aug 29 '18 23:08 markcowl