Skip to content

[OperationalInsights] bug fix ,added exception info returned and extended documentation file #16765

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,8 @@ public class NewAzureOperationalInsightsDataExportCommand : OperationalInsightsB

public override void ExecuteCmdlet()
{
var dataExportParameters = new CreatePSDataExportParameters
{
ResourceGroupName = ResourceGroupName,
WorkspaceName = WorkspaceName,
DataExportName = DataExportName,
TableNames = TableName.ToList(),
DestinationResourceId = ResourceId,
EventHubName = EventHubName,
Enable = Enable
};
var dataExportParameters = new CreatePSDataExportParameters(ResourceGroupName, WorkspaceName, DataExportName, TableName.ToList(), ResourceId, EventHubName, Enable);

if (ShouldProcess(DataExportName, $"Create Data export: {DataExportName}, in workspace: {WorkspaceName}, resource group: {ResourceGroupName}"))
{
WriteObject(this.OperationalInsightsClient.CreateDataExport(ResourceGroupName, dataExportParameters), true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class UpdateAzureOperationalInsightsDataExportCommand : OperationalInsigh

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

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

CreatePSDataExportParameters parameters = new CreatePSDataExportParameters();
CreatePSDataExportParameters parameters; ;

if (this.IsParameterBound(c => c.InputDataExport))
{
var resourceIdentifier = new ResourceIdentifier(this.InputDataExport.Id);
parameters.ResourceGroupName = resourceIdentifier.ResourceGroupName; ;
parameters.WorkspaceName = resourceIdentifier.ParentResource.ToLower().Replace("workspaces/", "");
parameters.DataExportName = resourceIdentifier.ResourceName;
parameters.TableNames = InputDataExport.TableNames;
parameters.DestinationResourceId = InputDataExport.ResourceId;
parameters.EventHubName = InputDataExport.EventHubName;
parameters.Enable = InputDataExport.Enable;
parameters = new CreatePSDataExportParameters(
resourceGroupName: resourceIdentifier.ResourceGroupName,
workspaceName: resourceIdentifier.ParentResource.ToLower().Replace("workspaces/", ""),
dataExportName: resourceIdentifier.ResourceName,
tableNames: InputDataExport.TableNames,
destinationResourceId: InputDataExport.ResourceId,
eventHubName: InputDataExport.EventHubName,
enable: InputDataExport.Enable);
}
else
{
parameters.ResourceGroupName = ResourceGroupName;
parameters.WorkspaceName = WorkspaceName;
parameters.DataExportName = DataExportName;
parameters.TableNames = TableName.ToList();
parameters.DestinationResourceId = DestinationResourceId;
parameters.EventHubName = EventHubName;
parameters.Enable = Enable;
parameters = new CreatePSDataExportParameters(
resourceGroupName: ResourceGroupName,
workspaceName: WorkspaceName,
dataExportName: DataExportName,
tableNames: TableName.ToList(),
destinationResourceId: DestinationResourceId,
eventHubName: EventHubName,
enable: Enable);
}

if (ShouldProcess(DataExportName, $"Update Data export: {DataExportName}, in workspace: {WorkspaceName}, resource group: {ResourceGroupName}"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,43 @@
// ----------------------------------------------------------------------------------

using System.Collections.Generic;
using System.Linq;

namespace Microsoft.Azure.Commands.OperationalInsights.Models
{
public class CreatePSDataExportParameters : OperationalInsightsParametersBase
{
public CreatePSDataExportParameters(string resourceGroupName, string workspaceName, string dataExportName, List<string> tableNames, string destinationResourceId, string eventHubName, bool? enable)
{
this.ResourceGroupName = resourceGroupName;
this.WorkspaceName = workspaceName;
this.DataExportName = dataExportName;
this.TableNames = this.RemoveWhitespace(tableNames);
this.DestinationResourceId = destinationResourceId;
this.EventHubName = eventHubName;
this.Enable = enable;
}

/// <summary>
/// splits by comma and removes leading and trailing whitespaces
/// </summary>
/// <param name="tableNames">list of table names</param>
/// <returns>A list of table names without empty spaces</returns>
private List<string> RemoveWhitespace(List<string> tableNames)
{
List<string> allTableNames = new List<string>();
foreach (var tableName in tableNames)
{
allTableNames = tableName.Split(',').Select(x => x.Trim()).Where(x => !string.IsNullOrWhiteSpace(x)).Union(allTableNames).ToList();
}

return allTableNames;
}

public string DataExportName { get; set; }
public List<string> TableNames { get; set; }
public List<string> TableNames { get; set; }
public string DestinationResourceId { get; set; }
public string EventHubName { get; set; }
public bool? Enable { get; set; }
public string EventHubName { get; set; }
public bool? Enable { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ protected override void WriteExceptionError(Exception exception)
exception = cloudException.CreateFormattedException();
}

// Override the default error message so it will include information passed from Backend
Management.OperationalInsights.Models.ErrorResponseException errorException = exception as Management.OperationalInsights.Models.ErrorResponseException;
if (errorException != null)
{
exception = new Exception(string.Format("{0}\n{1}", errorException.Message, errorException.Response.ReasonPhrase), errorException);
}
base.WriteExceptionError(exception);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Updates a data export.

### Example 1
```powershell
PS C:\> Update-AzOperationalInsightsDataExport -ResourceGroupName {rg-name} -WorkspaceName {workspace-name} -DataExportName {dataExportName} -TableNames {table_names}
PS C:\> Update-AzOperationalInsightsDataExport -ResourceGroupName {rg-name} -WorkspaceName {workspace-name} -DataExportName {dataExportName} -TableNames {table_names} -Enable $true

Name : {dataExportName}
Id : /subscriptions/{subscription}/resourcegroups/{rg-name}/providers/microsoft.operationalinsights/workspaces/{workspace-name}/dataexports/{dataExportName}
Expand All @@ -49,7 +49,7 @@ ResourceId : /subscriptions/{resource_subscription}/resourceGroups/{resour
counts/{storage_name}
DataExportType : StorageAccount
EventHubName :
Enable : false
Enable : true
CreatedDate :
LastModifiedDate :
```
Expand Down