diff --git a/azure/table_azure_eventhub_namespace.go b/azure/table_azure_eventhub_namespace.go index 413d4e60..352a1a1b 100644 --- a/azure/table_azure_eventhub_namespace.go +++ b/azure/table_azure_eventhub_namespace.go @@ -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" @@ -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.", @@ -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 +}