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_servicebus_namespace. Closes #215 #225

Merged
merged 2 commits into from
Aug 3, 2021
Merged
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
49 changes: 49 additions & 0 deletions azure/table_azure_servicebus_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/servicebus/mgmt/2018-01-01-preview/servicebus"
"github.com/turbot/steampipe-plugin-sdk/grpc/proto"
"github.com/turbot/steampipe-plugin-sdk/plugin"
Expand Down Expand Up @@ -95,6 +96,13 @@ func tableAzureServiceBusNamespace(_ context.Context) *plugin.Table {
Type: proto.ColumnType_TIMESTAMP,
Transform: transform.FromField("SBNamespaceProperties.UpdatedAt").Transform(convertDateToTime),
},
{
Name: "diagnostic_settings",
Description: "A list of active diagnostic settings for the servicebus namespace.",
Type: proto.ColumnType_JSON,
Hydrate: listServiceBusNamespaceDiagnosticSettings,
Transform: transform.FromValue(),
},
{
Name: "encryption",
Description: "Specifies the properties of BYOK encryption configuration. Customer-managed key encryption at rest (Bring Your Own Key) is only available on Premium namespaces.",
Expand Down Expand Up @@ -236,3 +244,44 @@ func getServiceBusNamespaceNetworkRuleSet(ctx context.Context, d *plugin.QueryDa

return op, nil
}

func listServiceBusNamespaceDiagnosticSettings(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {
plugin.Logger(ctx).Trace("listServiceBusNamespaceDiagnosticSettings")
id := *h.Item.(servicebus.SBNamespace).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
}