Skip to content

Commit

Permalink
refactor dignostic setting
Browse files Browse the repository at this point in the history
  • Loading branch information
VeryEarly committed Nov 23, 2020
1 parent cfca026 commit 1591835
Show file tree
Hide file tree
Showing 12 changed files with 156 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions src/Monitor/Monitor/Az.Monitor.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
4 changes: 4 additions & 0 deletions src/Monitor/Monitor/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
30 changes: 30 additions & 0 deletions src/Monitor/Monitor/Monitor.format.ps1xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,35 @@
</CustomEntries>
</CustomControl>
</View>
<View>
<Name>Microsoft.Azure.Commands.Insights.OutputClasses.PSDiagnosticSettingCategory</Name>
<ViewSelectedBy>
<TypeName>Microsoft.Azure.Commands.Insights.OutputClasses.PSDiagnosticSettingCategory</TypeName>
</ViewSelectedBy>
<ListControl>
<ListEntries>
<ListEntry>
<ListItems>
<ListItem>
<Label>Id</Label>
<PropertyName>Id</PropertyName>
</ListItem>
<ListItem>
<Label>Name</Label>
<PropertyName>Name</PropertyName>
</ListItem>
<ListItem>
<Label>Type</Label>
<PropertyName>Type</PropertyName>
</ListItem>
<ListItem>
<Label>CategoryType</Label>
<PropertyName>CategoryType</PropertyName>
</ListItem>
</ListItems>
</ListEntry>
</ListEntries>
</ListControl>
</View>
</ViewDefinitions>
</Configuration>
28 changes: 23 additions & 5 deletions src/Monitor/Monitor/OutputClasses/PSLogSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,24 @@ namespace Microsoft.Azure.Commands.Insights.OutputClasses
/// <summary>
/// Wrapps around the LogSettings
/// </summary>
public class PSLogSettings : Microsoft.Azure.Management.Monitor.Management.Models.LogSettings
public class PSLogSettings : PSDiagnosticDetailSettings
{
/// <summary>
/// Initializes a new instance of the PSLogSettings class.
/// </summary>
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);
}

/// <summary>
Expand All @@ -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
};
}
}
}
31 changes: 28 additions & 3 deletions src/Monitor/Monitor/OutputClasses/PSMetricSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,29 @@ namespace Microsoft.Azure.Commands.Insights.OutputClasses
/// <summary>
/// Wrapps around the MetricSettings
/// </summary>
public class PSMetricSettings : Management.Monitor.Management.Models.MetricSettings
public class PSMetricSettings : PSDiagnosticDetailSettings
{
/// <summary>
/// Initializes a new instance of the PSMetricSettings class.
/// </summary>
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; }

/// <summary>
/// A string representation of the PSMetricSettings
/// </summary>
Expand All @@ -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
};
}
}
}
4 changes: 4 additions & 0 deletions src/Monitor/Monitor/OutputClasses/PSRetentionPolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ namespace Microsoft.Azure.Commands.Insights.OutputClasses
/// </summary>
public class PSRetentionPolicy : Microsoft.Azure.Management.Monitor.Management.Models.RetentionPolicy
{
public PSRetentionPolicy()
{
}

/// <summary>
/// Initializes a new instance of the PSRetention class
/// </summary>
Expand Down
25 changes: 11 additions & 14 deletions src/Monitor/Monitor/OutputClasses/PSServiceDiagnosticSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,15 @@ public class PSServiceDiagnosticSettings : DiagnosticSettingsResource
/// </summary>
public IDictionary<string, string> Tags { get; set; }

/// <summary>
/// Sets or gets the Logs of the Diagnostic Setting.
/// This property in transitional until the namesace change is taken
/// </summary>
public new IList<Microsoft.Azure.Management.Monitor.Management.Models.LogSettings> Logs { get; set; }
//public new string Id { get; set; }

/// <summary>
/// Sets or gets the Logs of the Diagnostic Setting.
/// This property in transitional until the namesace change is taken
/// </summary>
public new IList<Microsoft.Azure.Management.Monitor.Management.Models.MetricSettings> 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)
{
}

/// <summary>
/// Initializes a new instance of the PSServiceDiagnosticSettings class.
Expand All @@ -65,19 +62,19 @@ public PSServiceDiagnosticSettings(DiagnosticSettingsResource serviceDiagnosticS

if (serviceDiagnosticSettings.Metrics != null)
{
this.Metrics = new List<Management.Monitor.Management.Models.MetricSettings>();
this.Metrics = new List<MetricSettings>();
foreach (MetricSettings metricSettings in serviceDiagnosticSettings.Metrics)
{
this.Metrics.Add(new PSMetricSettings(metricSettings));
this.Metrics.Add(metricSettings);
}
}

if (serviceDiagnosticSettings.Logs != null)
{
this.Logs = new List<Management.Monitor.Management.Models.LogSettings>();
this.Logs = new List<LogSettings>();
foreach (LogSettings logSettings in serviceDiagnosticSettings.Logs)
{
this.Logs.Add(new PSLogSettings(logSettings));
this.Logs.Add(logSettings);
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/Monitor/Monitor/TransitionalClasses/RetentionPolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ public RetentionPolicy(Monitor.Models.RetentionPolicy retentionPolicy)
}
}

public RetentionPolicy()
{
}

/// <summary>
/// A string representation of the PSRetentionPolicy
/// </summary>
Expand Down
9 changes: 9 additions & 0 deletions src/Monitor/Monitor/help/Az.Monitor.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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."
"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"

0 comments on commit 1591835

Please sign in to comment.