diff --git a/src/Monitor/Monitor.Test/ScenarioTests/AzureRmDiagnosticSettingTests.cs b/src/Monitor/Monitor.Test/ScenarioTests/AzureRmDiagnosticSettingTests.cs index 0dc9db0e733c..3ed2ff5e0373 100644 --- a/src/Monitor/Monitor.Test/ScenarioTests/AzureRmDiagnosticSettingTests.cs +++ b/src/Monitor/Monitor.Test/ScenarioTests/AzureRmDiagnosticSettingTests.cs @@ -84,5 +84,12 @@ public void TestSetAzureRmDiagnosticSettingLogAnalytics() { TestsController.NewInstance.RunPsTest(_logger, "Test-SetAzureRmDiagnosticSetting-LogAnalytics"); } + + [Fact] + [Trait(Category.AcceptanceType, Category.CheckIn)] + public void TestGetAzDiagnosticSettingCategory() + { + TestsController.NewInstance.RunPsTest(_logger, "Test-GetAzDiagnosticSettingCategory"); + } } } diff --git a/src/Monitor/Monitor.Test/ScenarioTests/AzureRmDiagnosticSettingTests.ps1 b/src/Monitor/Monitor.Test/ScenarioTests/AzureRmDiagnosticSettingTests.ps1 index 3f0fb98c807c..a054574b5e09 100644 --- a/src/Monitor/Monitor.Test/ScenarioTests/AzureRmDiagnosticSettingTests.ps1 +++ b/src/Monitor/Monitor.Test/ScenarioTests/AzureRmDiagnosticSettingTests.ps1 @@ -300,7 +300,36 @@ function Test-SetAzureRmDiagnosticSetting-LogAnalytics } } +<# +.SYNOPSIS +Test Get diagnostic setting supported categories +#> +function Test-GetAzDiagnosticSettingCategory +{ + $ResourceGroupName = 'group' + (getAssetName) + $SubnetConfigName = 'config' + (getAssetName) + $VNetName = 'vn' + (getAssetName) + + try + { + $rg = New-AzResourceGroup -Name $ResourceGroupName -Location 'eastus' + $subnet = New-AzVirtualNetworkSubnetConfig -Name $SubnetConfigName -AddressPrefix "10.0.1.0/24" + $vn = New-AzVirtualNetwork -Name $VNetName -ResourceGroupName $ResourceGroupName -Location 'eastus' -AddressPrefix "10.0.0.0/16" -Subnet $subnet + $id = $vn.Id + $log = Get-AzDiagnosticSettingCategory -TargetResourceId $id -Name 'VMProtectionAlerts' + $metric = Get-AzDiagnosticSettingCategory -TargetResourceId $id -Name 'AllMetrics' + + Assert-AreEqual 'Logs' $log.CategoryType + Assert-AreEqual 'Metrics' $metric.CategoryType + + Remove-AzVirtualNetwork -ResourceGroupName $ResourceGroupName -Name $VNetName -Force + } + finally + { + Remove-AzResourceGroup -Name $ResourceGroupName + } +} # TODO add more complicated scenarios after we have a definitive subscription \ No newline at end of file diff --git a/src/Monitor/Monitor/Az.Monitor.psd1 b/src/Monitor/Monitor/Az.Monitor.psd1 index 9af9d3556172..7f48ac7b42e1 100644 --- a/src/Monitor/Monitor/Az.Monitor.psd1 +++ b/src/Monitor/Monitor/Az.Monitor.psd1 @@ -76,7 +76,10 @@ FunctionsToExport = @() # Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export. CmdletsToExport = 'Get-AzMetricDefinition', 'Get-AzMetric', 'Remove-AzLogProfile', 'Get-AzLogProfile', 'Add-AzLogProfile', 'Get-AzActivityLog', + 'New-AzDiagnosticSetting', + 'New-AzDiagnosticDetailSetting', 'Set-AzDiagnosticSetting', 'Get-AzDiagnosticSetting', + 'Get-AzDiagnosticSettingCategory', 'Remove-AzDiagnosticSetting', 'New-AzAutoscaleNotification', 'New-AzAutoscaleProfile', 'New-AzAutoscaleRule', 'Add-AzAutoscaleSetting', 'Get-AzAutoscaleHistory', diff --git a/src/Monitor/Monitor/ChangeLog.md b/src/Monitor/Monitor/ChangeLog.md index fad3d1adb92a..e66871f489ef 100644 --- a/src/Monitor/Monitor/ChangeLog.md +++ b/src/Monitor/Monitor/ChangeLog.md @@ -19,6 +19,10 @@ --> ## Upcoming Release +* Added new cmdlets: + `Get-AzDiagnosticSettingCategory`, + `New-AzDiagnosticSetting`, + `New-AzDiagnosticDetailSetting` ## Version 2.2.0 * Fixed the bug that warning message cannot be suppressed. [#12889] diff --git a/src/Monitor/Monitor/Monitor.format.ps1xml b/src/Monitor/Monitor/Monitor.format.ps1xml index d113b5f447d6..338ceffbeac2 100644 --- a/src/Monitor/Monitor/Monitor.format.ps1xml +++ b/src/Monitor/Monitor/Monitor.format.ps1xml @@ -22,5 +22,35 @@ + + Microsoft.Azure.Commands.Insights.OutputClasses.PSDiagnosticSettingCategory + + Microsoft.Azure.Commands.Insights.OutputClasses.PSDiagnosticSettingCategory + + + + + + + + Id + + + + Name + + + + Type + + + + CategoryType + + + + + + diff --git a/src/Monitor/Monitor/OutputClasses/PSLogSettings.cs b/src/Monitor/Monitor/OutputClasses/PSLogSettings.cs index 716028b61d36..cfd9a7b2d1ea 100644 --- a/src/Monitor/Monitor/OutputClasses/PSLogSettings.cs +++ b/src/Monitor/Monitor/OutputClasses/PSLogSettings.cs @@ -20,16 +20,24 @@ namespace Microsoft.Azure.Commands.Insights.OutputClasses /// /// Wrapps around the LogSettings /// - public class PSLogSettings : Microsoft.Azure.Management.Monitor.Management.Models.LogSettings + public class PSLogSettings : PSDiagnosticDetailSettings { /// /// Initializes a new instance of the PSLogSettings class. /// - public PSLogSettings(LogSettings logSettings) : base(logSettings) + public PSLogSettings(LogSettings logSettings) + { + if (logSettings != null) + { + this.Enabled = logSettings.Enabled; + this.Category = logSettings.Category; + this.RetentionPolicy = new PSRetentionPolicy(logSettings.RetentionPolicy); + } + this.CategoryType = PSDiagnosticSettingCategoryType.Logs; + } + + public PSLogSettings() { - this.Enabled = logSettings.Enabled; - this.Category = logSettings.Category; - this.RetentionPolicy = new Management.Monitor.Management.Models.RetentionPolicy(logSettings.RetentionPolicy); } /// @@ -45,5 +53,15 @@ public override string ToString() output.Append("RetentionPolicy : " + RetentionPolicy.ToString(1)); return output.ToString(); } + + public LogSettings GetLogSetting() + { + return new LogSettings() + { + Enabled = this.Enabled, + Category = this.Category, + RetentionPolicy = this.RetentionPolicy + }; + } } } diff --git a/src/Monitor/Monitor/OutputClasses/PSMetricSettings.cs b/src/Monitor/Monitor/OutputClasses/PSMetricSettings.cs index 5bb25a88bf8b..5b7d56d02cfe 100644 --- a/src/Monitor/Monitor/OutputClasses/PSMetricSettings.cs +++ b/src/Monitor/Monitor/OutputClasses/PSMetricSettings.cs @@ -21,15 +21,29 @@ namespace Microsoft.Azure.Commands.Insights.OutputClasses /// /// Wrapps around the MetricSettings /// - public class PSMetricSettings : Management.Monitor.Management.Models.MetricSettings + public class PSMetricSettings : PSDiagnosticDetailSettings { /// /// Initializes a new instance of the PSMetricSettings class. /// - public PSMetricSettings(MetricSettings metricSettings) : base(metricSettings) + public PSMetricSettings(MetricSettings metricSettings) { + if (metricSettings != null) + { + this.Category = metricSettings.Category; + this.Enabled = metricSettings.Enabled; + this.RetentionPolicy = new PSRetentionPolicy(metricSettings.RetentionPolicy); + this.TimeGrain = metricSettings.TimeGrain ?? default(System.TimeSpan); + } + this.CategoryType = PSDiagnosticSettingCategoryType.Metrics; } + public PSMetricSettings() + { + } + + public System.TimeSpan TimeGrain { get; set; } + /// /// A string representation of the PSMetricSettings /// @@ -40,9 +54,20 @@ public override string ToString() output.AppendLine(); output.AppendLine("Category : " + Category); output.AppendLine("Enabled : " + Enabled); - output.AppendLine("TimeGrain : " + XmlConvert.ToString(TimeGrain)); + output.AppendLine("TimeGrain : " + XmlConvert.ToString((System.TimeSpan)TimeGrain)); output.Append("RetentionPolicy : " + RetentionPolicy.ToString(1)); return output.ToString(); } + + public MetricSettings GetMetricSetting() + { + return new MetricSettings() + { + Enabled = this.Enabled, + Category = this.Category, + RetentionPolicy = this.RetentionPolicy, + TimeGrain = this.TimeGrain + }; + } } } diff --git a/src/Monitor/Monitor/OutputClasses/PSRetentionPolicy.cs b/src/Monitor/Monitor/OutputClasses/PSRetentionPolicy.cs index 74d6b86e9890..4193f060285e 100644 --- a/src/Monitor/Monitor/OutputClasses/PSRetentionPolicy.cs +++ b/src/Monitor/Monitor/OutputClasses/PSRetentionPolicy.cs @@ -21,6 +21,10 @@ namespace Microsoft.Azure.Commands.Insights.OutputClasses /// public class PSRetentionPolicy : Microsoft.Azure.Management.Monitor.Management.Models.RetentionPolicy { + public PSRetentionPolicy() + { + } + /// /// Initializes a new instance of the PSRetention class /// diff --git a/src/Monitor/Monitor/OutputClasses/PSServiceDiagnosticSettings.cs b/src/Monitor/Monitor/OutputClasses/PSServiceDiagnosticSettings.cs index e6395025dc02..2e7805913417 100644 --- a/src/Monitor/Monitor/OutputClasses/PSServiceDiagnosticSettings.cs +++ b/src/Monitor/Monitor/OutputClasses/PSServiceDiagnosticSettings.cs @@ -32,18 +32,15 @@ public class PSServiceDiagnosticSettings : DiagnosticSettingsResource /// public IDictionary Tags { get; set; } - /// - /// Sets or gets the Logs of the Diagnostic Setting. - /// This property in transitional until the namesace change is taken - /// - public new IList Logs { get; set; } + //public new string Id { get; set; } - /// - /// Sets or gets the Logs of the Diagnostic Setting. - /// This property in transitional until the namesace change is taken - /// - public new IList Metrics { get; set; } + //public new string Name { get; set; } = "service"; + public PSServiceDiagnosticSettings() { } + + public PSServiceDiagnosticSettings(string id = default(string), string name = default(string)) : base(id, name) + { + } /// /// Initializes a new instance of the PSServiceDiagnosticSettings class. @@ -65,19 +62,19 @@ public PSServiceDiagnosticSettings(DiagnosticSettingsResource serviceDiagnosticS if (serviceDiagnosticSettings.Metrics != null) { - this.Metrics = new List(); + this.Metrics = new List(); foreach (MetricSettings metricSettings in serviceDiagnosticSettings.Metrics) { - this.Metrics.Add(new PSMetricSettings(metricSettings)); + this.Metrics.Add(metricSettings); } } if (serviceDiagnosticSettings.Logs != null) { - this.Logs = new List(); + this.Logs = new List(); foreach (LogSettings logSettings in serviceDiagnosticSettings.Logs) { - this.Logs.Add(new PSLogSettings(logSettings)); + this.Logs.Add(logSettings); } } diff --git a/src/Monitor/Monitor/TransitionalClasses/RetentionPolicy.cs b/src/Monitor/Monitor/TransitionalClasses/RetentionPolicy.cs index e468c7132033..8f1e3b5c0a34 100644 --- a/src/Monitor/Monitor/TransitionalClasses/RetentionPolicy.cs +++ b/src/Monitor/Monitor/TransitionalClasses/RetentionPolicy.cs @@ -36,6 +36,10 @@ public RetentionPolicy(Monitor.Models.RetentionPolicy retentionPolicy) } } + public RetentionPolicy() + { + } + /// /// A string representation of the PSRetentionPolicy /// diff --git a/src/Monitor/Monitor/help/Az.Monitor.md b/src/Monitor/Monitor/help/Az.Monitor.md index 7eb82fd191d2..6bf521be611e 100644 --- a/src/Monitor/Monitor/help/Az.Monitor.md +++ b/src/Monitor/Monitor/help/Az.Monitor.md @@ -56,6 +56,9 @@ Gets Autoscale settings. ### [Get-AzDiagnosticSetting](Get-AzDiagnosticSetting.md) Gets the logged categories and time grains. +### [Get-AzDiagnosticSettingCategory](Get-AzDiagnosticSettingCategory.md) +Get or list supported diagnostic setting category for Azure resource. + ### [Get-AzInsightsPrivateLinkScope](Get-AzInsightsPrivateLinkScope.md) Get private link scope @@ -104,6 +107,12 @@ Creates an Autoscale rule. ### [New-AzAutoscaleWebhook](New-AzAutoscaleWebhook.md) Creates an Autoscale webhook. +### [New-AzDiagnosticDetailSetting](New-AzDiagnosticDetailSetting.md) +Create PSDiagnosticDetailSetting Object, type could be metric or log + +### [New-AzDiagnosticSetting](New-AzDiagnosticSetting.md) +Create PSServiceDiagnosticSettings object. + ### [New-AzInsightsPrivateLinkScope](New-AzInsightsPrivateLinkScope.md) create private link scope diff --git a/tools/StaticAnalysis/Exceptions/Az.Monitor/SignatureIssues.csv b/tools/StaticAnalysis/Exceptions/Az.Monitor/SignatureIssues.csv index 31c081f3f5c0..bcbed4ea1e8a 100644 --- a/tools/StaticAnalysis/Exceptions/Az.Monitor/SignatureIssues.csv +++ b/tools/StaticAnalysis/Exceptions/Az.Monitor/SignatureIssues.csv @@ -10,4 +10,7 @@ "Microsoft.Azure.PowerShell.Cmdlets.Monitor.dll","Microsoft.Azure.Commands.Insights.ScheduledQueryRules.NewScheduledQueryRuleTriggerConditionCommand","New-AzScheduledQueryRuleTriggerCondition","1","8100","New-AzScheduledQueryRuleTriggerCondition Does not support ShouldProcess but the cmdlet verb New indicates that it should.","Determine if the cmdlet should implement ShouldProcess and if so determine if it should implement Force / ShouldContinue" "Microsoft.Azure.PowerShell.Cmdlets.Monitor.dll","Microsoft.Azure.Commands.Insights.PrivateLinkScopes.NewAzureInsightsPrivateLinkScope","New-AzInsightsPrivateLinkScope","1","8410","Parameter Tags of cmdlet New-AzInsightsPrivateLinkScope does not follow the enforced naming convention of using a singular noun for a parameter name.","Consider using a singular noun for the parameter name." "Microsoft.Azure.PowerShell.Cmdlets.Monitor.dll","Microsoft.Azure.Commands.Insights.PrivateLinkScopes.UpdateAzureInsightsPrivateLinkScope","Update-AzInsightsPrivateLinkScope","1","8410","Parameter Tags of cmdlet Update-AzInsightsPrivateLinkScope does not follow the enforced naming convention of using a singular noun for a parameter name.","Consider using a singular noun for the parameter name." -"Microsoft.Azure.PowerShell.Cmdlets.Monitor.dll","Microsoft.Azure.Commands.Insights.Diagnostics.SetAzureRmDiagnosticSettingCommand","Set-AzDiagnosticSetting","1","8410","Parameter EnableMetrics of cmdlet Set-AzDiagnosticSetting does not follow the enforced naming convention of using a singular noun for a parameter name.","Consider using a singular noun for the parameter name." \ No newline at end of file +"Microsoft.Azure.PowerShell.Cmdlets.Monitor.dll","Microsoft.Azure.Commands.Insights.Diagnostics.SetAzureRmDiagnosticSettingCommand","Set-AzDiagnosticSetting","1","8410","Parameter EnableMetrics of cmdlet Set-AzDiagnosticSetting does not follow the enforced naming convention of using a singular noun for a parameter name.","Consider using a singular noun for the parameter name." +"Microsoft.Azure.PowerShell.Cmdlets.Monitor.dll","Microsoft.Azure.Commands.Insights.Diagnostics.NewAzureRmDiagnosticDetailSettingCommand","New-AzDiagnosticDetailSetting","1","8100","New-AzDiagnosticDetailSetting Does not support ShouldProcess but the cmdlet verb New indicates that it should.","Determine if the cmdlet should implement ShouldProcess and if so determine if it should implement Force / ShouldContinue" +"Microsoft.Azure.PowerShell.Cmdlets.Monitor.dll","Microsoft.Azure.Commands.Insights.Diagnostics.NewAzureRmDiagnosticDetailSettingCommand","New-AzDiagnosticDetailSetting","1","8510","Cmdlet 'New-AzDiagnosticDetailSetting' has multiple parameter sets, but no defined default parameter set.","Define a default parameter set in the cmdlet attribute." +"Microsoft.Azure.PowerShell.Cmdlets.Monitor.dll","Microsoft.Azure.Commands.Insights.Diagnostics.NewAzureRmDiagnosticSettingCommand","New-AzDiagnosticSetting","1","8100","New-AzDiagnosticSetting Does not support ShouldProcess but the cmdlet verb New indicates that it should.","Determine if the cmdlet should implement ShouldProcess and if so determine if it should implement Force / ShouldContinue" \ No newline at end of file