Skip to content

Commit

Permalink
Update Diagnostic settings details in table azure_eventhub_namespace. C…
Browse files Browse the repository at this point in the history
…loses #212 (#226)
  • Loading branch information
bigdatasourav authored Aug 3, 2021
1 parent b57b078 commit 7c1279b
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions azure/table_azure_eventhub_namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"strings"

"github.com/Azure/azure-sdk-for-go/profiles/2020-09-01/monitor/mgmt/insights"
"github.com/Azure/azure-sdk-for-go/services/preview/eventhub/mgmt/2018-01-01-preview/eventhub"
"github.com/turbot/steampipe-plugin-sdk/grpc/proto"
"github.com/turbot/steampipe-plugin-sdk/plugin"
Expand Down Expand Up @@ -119,6 +120,13 @@ func tableAzureEventHubNamespace(_ context.Context) *plugin.Table {
Type: proto.ColumnType_BOOL,
Transform: transform.FromField("EHNamespaceProperties.ZoneRedundant"),
},
{
Name: "diagnostic_settings",
Description: "A list of active diagnostic settings for the eventhub namespace.",
Type: proto.ColumnType_JSON,
Hydrate: listEventHubNamespaceDiagnosticSettings,
Transform: transform.FromValue(),
},
{
Name: "encryption",
Description: "Properties of BYOK encryption description.",
Expand Down Expand Up @@ -265,3 +273,44 @@ func getNetworkRuleSet(ctx context.Context, d *plugin.QueryData, h *plugin.Hydra

return op, nil
}

func listEventHubNamespaceDiagnosticSettings(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {
plugin.Logger(ctx).Trace("listEventHubNamespaceDiagnosticSettings")
id := *h.Item.(eventhub.EHNamespace).ID

// Create session
session, err := GetNewSession(ctx, d, "MANAGEMENT")
if err != nil {
return nil, err
}
subscriptionID := session.SubscriptionID

client := insights.NewDiagnosticSettingsClient(subscriptionID)
client.Authorizer = session.Authorizer

op, err := client.List(ctx, id)
if err != nil {
return nil, err
}

// If we return the API response directly, the output only gives
// the contents of DiagnosticSettings
var diagnosticSettings []map[string]interface{}
for _, i := range *op.Value {
objectMap := make(map[string]interface{})
if i.ID != nil {
objectMap["id"] = i.ID
}
if i.Name != nil {
objectMap["name"] = i.Name
}
if i.Type != nil {
objectMap["type"] = i.Type
}
if i.DiagnosticSettings != nil {
objectMap["properties"] = i.DiagnosticSettings
}
diagnosticSettings = append(diagnosticSettings, objectMap)
}
return diagnosticSettings, nil
}

0 comments on commit 7c1279b

Please sign in to comment.