Skip to content
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

Add Diagnostic settings details in table azure_eventhub_namespace. Closes #212 #226

Merged
merged 2 commits into from
Aug 3, 2021
Merged
Changes from 1 commit
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
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 resource.",
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
}