From 159b0b469e21fae37db551bcf3e00af0a24dee3c Mon Sep 17 00:00:00 2001 From: rajeshbal65 Date: Fri, 23 Apr 2021 13:32:41 +0530 Subject: [PATCH 1/3] subscription_id column might displaying wrong value in azure_diagnostic_setting table. Closes #98 --- azure/table_azure_diagnostic_setting.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/azure/table_azure_diagnostic_setting.go b/azure/table_azure_diagnostic_setting.go index 210bef9f..aa7262b3 100644 --- a/azure/table_azure_diagnostic_setting.go +++ b/azure/table_azure_diagnostic_setting.go @@ -2,8 +2,10 @@ package azure import ( "context" + "strings" "github.com/Azure/azure-sdk-for-go/profiles/2020-09-01/monitor/mgmt/insights" + "github.com/turbot/go-kit/types" "github.com/turbot/steampipe-plugin-sdk/grpc/proto" "github.com/turbot/steampipe-plugin-sdk/plugin/transform" @@ -115,7 +117,7 @@ func tableAzureDiagnosticSetting(_ context.Context) *plugin.Table { Name: "subscription_id", Description: ColumnDescriptionSubscription, Type: proto.ColumnType_STRING, - Transform: transform.FromField("ID").Transform(idToSubscriptionID), + Transform: transform.FromField("ID").Transform(diagnosticSettingSubscriptionID), }, }, } @@ -170,3 +172,11 @@ func getDiagnosticSetting(ctx context.Context, d *plugin.QueryData, h *plugin.Hy return op, nil } + +//// TRANSFORM FUNCTION + +func diagnosticSettingSubscriptionID(ctx context.Context, d *transform.TransformData) (interface{}, error) { + id := types.SafeString(d.Value) + subscriptionid := strings.Split(id, "/")[1] + return subscriptionid, nil +} From 25d985e902c4625a418d0128b496b13d1761932c Mon Sep 17 00:00:00 2001 From: rajeshbal65 Date: Fri, 23 Apr 2021 16:51:40 +0530 Subject: [PATCH 2/3] Fixed resource Group column to populate correct value --- azure/table_azure_diagnostic_setting.go | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/azure/table_azure_diagnostic_setting.go b/azure/table_azure_diagnostic_setting.go index aa7262b3..62519aa2 100644 --- a/azure/table_azure_diagnostic_setting.go +++ b/azure/table_azure_diagnostic_setting.go @@ -111,7 +111,8 @@ func tableAzureDiagnosticSetting(_ context.Context) *plugin.Table { Name: "resource_group", Description: ColumnDescriptionResourceGroup, Type: proto.ColumnType_STRING, - Transform: transform.FromField("ID").Transform(extractResourceGroupFromID), + Hydrate: getDiagnosticSettingResourceGroup, + Transform: transform.FromValue(), }, { Name: "subscription_id", @@ -180,3 +181,24 @@ func diagnosticSettingSubscriptionID(ctx context.Context, d *transform.Transform subscriptionid := strings.Split(id, "/")[1] return subscriptionid, nil } + +func getDiagnosticSettingResourceGroup(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { + plugin.Logger(ctx).Trace("getDiagnosticSettingResourceGroup") + + var resourseGroupID string + storage_account_id := h.Item.(insights.DiagnosticSettingsResource).StorageAccountID + event_hub_authorization_rule_id := h.Item.(insights.DiagnosticSettingsResource).EventHubAuthorizationRuleID + workspace_id := h.Item.(insights.DiagnosticSettingsResource).WorkspaceID + + if storage_account_id != nil { + resourseGroupID = strings.Split(*storage_account_id, "/")[4] + } else if event_hub_authorization_rule_id != nil { + resourseGroupID = strings.Split(*event_hub_authorization_rule_id, "/")[4] + } else { + resourseGroupID = strings.Split(*workspace_id, "/")[4] + } + + plugin.Logger(ctx).Trace("resourseGroupID", resourseGroupID) + + return resourseGroupID, nil +} From b233118c6711d4023033fd92497a334d83b1ff76 Mon Sep 17 00:00:00 2001 From: rajeshbal65 Date: Fri, 23 Apr 2021 17:21:16 +0530 Subject: [PATCH 3/3] update --- azure/table_azure_diagnostic_setting.go | 27 ++++++++----------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/azure/table_azure_diagnostic_setting.go b/azure/table_azure_diagnostic_setting.go index 62519aa2..02ae4e0e 100644 --- a/azure/table_azure_diagnostic_setting.go +++ b/azure/table_azure_diagnostic_setting.go @@ -111,8 +111,7 @@ func tableAzureDiagnosticSetting(_ context.Context) *plugin.Table { Name: "resource_group", Description: ColumnDescriptionResourceGroup, Type: proto.ColumnType_STRING, - Hydrate: getDiagnosticSettingResourceGroup, - Transform: transform.FromValue(), + Transform: transform.From(diagnosticSettingResourceGroup), }, { Name: "subscription_id", @@ -182,23 +181,13 @@ func diagnosticSettingSubscriptionID(ctx context.Context, d *transform.Transform return subscriptionid, nil } -func getDiagnosticSettingResourceGroup(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { - plugin.Logger(ctx).Trace("getDiagnosticSettingResourceGroup") - - var resourseGroupID string - storage_account_id := h.Item.(insights.DiagnosticSettingsResource).StorageAccountID - event_hub_authorization_rule_id := h.Item.(insights.DiagnosticSettingsResource).EventHubAuthorizationRuleID - workspace_id := h.Item.(insights.DiagnosticSettingsResource).WorkspaceID - - if storage_account_id != nil { - resourseGroupID = strings.Split(*storage_account_id, "/")[4] - } else if event_hub_authorization_rule_id != nil { - resourseGroupID = strings.Split(*event_hub_authorization_rule_id, "/")[4] +func diagnosticSettingResourceGroup(ctx context.Context, d *transform.TransformData) (interface{}, error) { + item := d.HydrateItem.(insights.DiagnosticSettingsResource) + if item.StorageAccountID != nil { + return strings.Split(*item.StorageAccountID, "/")[4], nil + } else if item.EventHubAuthorizationRuleID != nil { + return strings.Split(*item.EventHubAuthorizationRuleID, "/")[4], nil } else { - resourseGroupID = strings.Split(*workspace_id, "/")[4] + return strings.Split(*item.WorkspaceID, "/")[4], nil } - - plugin.Logger(ctx).Trace("resourseGroupID", resourseGroupID) - - return resourseGroupID, nil }