Skip to content

Commit 62607fa

Browse files
[OperationalInsights] bug fix ,added exception info returned and extended documentation file (Azure#16765)
* removed positional argument that caused a bug: whenever passing -TableName'Heartbeat1_CL, Heartbeat1_CL' the values which will be passed will be -TableNameHeartbeat1_CL and Heartbeat1_CL' added extended error message when ErrorResponseException is thrown * removing spaces from TableNames * Update NewAzureOperationalInsightsDataExportCommand.cs Co-authored-by: Yunchi Wang <54880216+wyunchi-ms@users.noreply.github.com>
1 parent 6d890d1 commit 62607fa

File tree

5 files changed

+59
-31
lines changed

5 files changed

+59
-31
lines changed

src/OperationalInsights/OperationalInsights/DataExports/NewAzureOperationalInsightsDataExportCommand.cs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,8 @@ public class NewAzureOperationalInsightsDataExportCommand : OperationalInsightsB
5252

5353
public override void ExecuteCmdlet()
5454
{
55-
var dataExportParameters = new CreatePSDataExportParameters
56-
{
57-
ResourceGroupName = ResourceGroupName,
58-
WorkspaceName = WorkspaceName,
59-
DataExportName = DataExportName,
60-
TableNames = TableName.ToList(),
61-
DestinationResourceId = ResourceId,
62-
EventHubName = EventHubName,
63-
Enable = Enable
64-
};
55+
var dataExportParameters = new CreatePSDataExportParameters(ResourceGroupName, WorkspaceName, DataExportName, TableName.ToList(), ResourceId, EventHubName, Enable);
56+
6557
if (ShouldProcess(DataExportName, $"Create Data export: {DataExportName}, in workspace: {WorkspaceName}, resource group: {ResourceGroupName}"))
6658
{
6759
WriteObject(this.OperationalInsightsClient.CreateDataExport(ResourceGroupName, dataExportParameters), true);

src/OperationalInsights/OperationalInsights/DataExports/UpdateAzureOperationalInsightsDataExportCommand.cs

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public class UpdateAzureOperationalInsightsDataExportCommand : OperationalInsigh
5050

5151
[Parameter(Mandatory = false, ParameterSetName = UpdateByNameParameterSet,
5252
HelpMessage = "An array of tables to export, for example: [“Heartbeat, SecurityEvent”].")]
53-
public string[] TableName{ get; set; }
53+
public string[] TableName { get; set; }
5454

5555
[Parameter(Mandatory = false, ParameterSetName = UpdateByNameParameterSet,
5656
HelpMessage = "The destination resource ID. This can be copied from the Properties entry of the destination resource in Azure.")]
@@ -74,28 +74,30 @@ public override void ExecuteCmdlet()
7474
this.DataExportName = resourceIdentifier.ResourceName;
7575
}
7676

77-
CreatePSDataExportParameters parameters = new CreatePSDataExportParameters();
77+
CreatePSDataExportParameters parameters; ;
7878

7979
if (this.IsParameterBound(c => c.InputDataExport))
8080
{
8181
var resourceIdentifier = new ResourceIdentifier(this.InputDataExport.Id);
82-
parameters.ResourceGroupName = resourceIdentifier.ResourceGroupName; ;
83-
parameters.WorkspaceName = resourceIdentifier.ParentResource.ToLower().Replace("workspaces/", "");
84-
parameters.DataExportName = resourceIdentifier.ResourceName;
85-
parameters.TableNames = InputDataExport.TableNames;
86-
parameters.DestinationResourceId = InputDataExport.ResourceId;
87-
parameters.EventHubName = InputDataExport.EventHubName;
88-
parameters.Enable = InputDataExport.Enable;
82+
parameters = new CreatePSDataExportParameters(
83+
resourceGroupName: resourceIdentifier.ResourceGroupName,
84+
workspaceName: resourceIdentifier.ParentResource.ToLower().Replace("workspaces/", ""),
85+
dataExportName: resourceIdentifier.ResourceName,
86+
tableNames: InputDataExport.TableNames,
87+
destinationResourceId: InputDataExport.ResourceId,
88+
eventHubName: InputDataExport.EventHubName,
89+
enable: InputDataExport.Enable);
8990
}
9091
else
9192
{
92-
parameters.ResourceGroupName = ResourceGroupName;
93-
parameters.WorkspaceName = WorkspaceName;
94-
parameters.DataExportName = DataExportName;
95-
parameters.TableNames = TableName.ToList();
96-
parameters.DestinationResourceId = DestinationResourceId;
97-
parameters.EventHubName = EventHubName;
98-
parameters.Enable = Enable;
93+
parameters = new CreatePSDataExportParameters(
94+
resourceGroupName: ResourceGroupName,
95+
workspaceName: WorkspaceName,
96+
dataExportName: DataExportName,
97+
tableNames: TableName.ToList(),
98+
destinationResourceId: DestinationResourceId,
99+
eventHubName: EventHubName,
100+
enable: Enable);
99101
}
100102

101103
if (ShouldProcess(DataExportName, $"Update Data export: {DataExportName}, in workspace: {WorkspaceName}, resource group: {ResourceGroupName}"))

src/OperationalInsights/OperationalInsights/Models/CreatePSDataExportParameters.cs

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,43 @@
1212
// ----------------------------------------------------------------------------------
1313

1414
using System.Collections.Generic;
15+
using System.Linq;
1516

1617
namespace Microsoft.Azure.Commands.OperationalInsights.Models
1718
{
1819
public class CreatePSDataExportParameters : OperationalInsightsParametersBase
1920
{
21+
public CreatePSDataExportParameters(string resourceGroupName, string workspaceName, string dataExportName, List<string> tableNames, string destinationResourceId, string eventHubName, bool? enable)
22+
{
23+
this.ResourceGroupName = resourceGroupName;
24+
this.WorkspaceName = workspaceName;
25+
this.DataExportName = dataExportName;
26+
this.TableNames = this.RemoveWhitespace(tableNames);
27+
this.DestinationResourceId = destinationResourceId;
28+
this.EventHubName = eventHubName;
29+
this.Enable = enable;
30+
}
31+
32+
/// <summary>
33+
/// splits by comma and removes leading and trailing whitespaces
34+
/// </summary>
35+
/// <param name="tableNames">list of table names</param>
36+
/// <returns>A list of table names without empty spaces</returns>
37+
private List<string> RemoveWhitespace(List<string> tableNames)
38+
{
39+
List<string> allTableNames = new List<string>();
40+
foreach (var tableName in tableNames)
41+
{
42+
allTableNames = tableName.Split(',').Select(x => x.Trim()).Where(x => !string.IsNullOrWhiteSpace(x)).Union(allTableNames).ToList();
43+
}
44+
45+
return allTableNames;
46+
}
47+
2048
public string DataExportName { get; set; }
21-
public List<string> TableNames { get; set; }
49+
public List<string> TableNames { get; set; }
2250
public string DestinationResourceId { get; set; }
23-
public string EventHubName { get; set; }
24-
public bool? Enable { get; set; }
51+
public string EventHubName { get; set; }
52+
public bool? Enable { get; set; }
2553
}
2654
}

src/OperationalInsights/OperationalInsights/OperationalInsightsBaseCmdlet.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ protected override void WriteExceptionError(Exception exception)
6565
exception = cloudException.CreateFormattedException();
6666
}
6767

68+
// Override the default error message so it will include information passed from Backend
69+
Management.OperationalInsights.Models.ErrorResponseException errorException = exception as Management.OperationalInsights.Models.ErrorResponseException;
70+
if (errorException != null)
71+
{
72+
exception = new Exception(string.Format("{0}\n{1}", errorException.Message, errorException.Response.ReasonPhrase), errorException);
73+
}
6874
base.WriteExceptionError(exception);
6975
}
7076
}

src/OperationalInsights/OperationalInsights/help/Update-AzOperationalInsightsDataExport.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Updates a data export.
3838

3939
### Example 1
4040
```powershell
41-
PS C:\> Update-AzOperationalInsightsDataExport -ResourceGroupName {rg-name} -WorkspaceName {workspace-name} -DataExportName {dataExportName} -TableNames {table_names}
41+
PS C:\> Update-AzOperationalInsightsDataExport -ResourceGroupName {rg-name} -WorkspaceName {workspace-name} -DataExportName {dataExportName} -TableNames {table_names} -Enable $true
4242
4343
Name : {dataExportName}
4444
Id : /subscriptions/{subscription}/resourcegroups/{rg-name}/providers/microsoft.operationalinsights/workspaces/{workspace-name}/dataexports/{dataExportName}
@@ -49,7 +49,7 @@ ResourceId : /subscriptions/{resource_subscription}/resourceGroups/{resour
4949
counts/{storage_name}
5050
DataExportType : StorageAccount
5151
EventHubName :
52-
Enable : false
52+
Enable : true
5353
CreatedDate :
5454
LastModifiedDate :
5555
```

0 commit comments

Comments
 (0)