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

Added column diagnostic_settings to azure_storage_account table. #432

Merged
merged 3 commits into from
Jan 5, 2022
Merged
Show file tree
Hide file tree
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
51 changes: 51 additions & 0 deletions azure/table_azure_storage_account.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/storage/mgmt/2019-06-01/storage"
"github.com/Azure/go-autorest/autorest"
"github.com/tombuildsstuff/giovanni/storage/2018-11-09/queue/queues"
Expand Down Expand Up @@ -339,6 +340,13 @@ func tableAzureStorageAccount(_ context.Context) *plugin.Table {
Type: proto.ColumnType_STRING,
Transform: transform.FromField("Account.AccountProperties.SecondaryLocation"),
},
{
Name: "diagnostic_settings",
Description: "A list of active diagnostic settings for the storage account.",
Type: proto.ColumnType_JSON,
Hydrate: listStorageAccountDiagnosticSettings,
Transform: transform.FromValue(),
},
{
Name: "encryption_scope",
Description: "Encryption scope details for the storage account.",
Expand Down Expand Up @@ -723,6 +731,49 @@ func getAzureStorageAccountQueueProperties(ctx context.Context, d *plugin.QueryD
return nil, nil
}

func listStorageAccountDiagnosticSettings(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {
plugin.Logger(ctx).Trace("listStorageAccountDiagnosticSettings")
accountData := h.Item.(*storageAccountInfo)
id := *accountData.Account.ID

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

client := insights.NewDiagnosticSettingsClientWithBaseURI(session.ResourceManagerEndpoint, 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 top level
// 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["DiagnosticSettings"] = i.DiagnosticSettings
}
diagnosticSettings = append(diagnosticSettings, objectMap)
}

return diagnosticSettings, nil
}

// If we return the API response directly, the output only gives the top level property
func storageAccountEncryptionScopeMap(scope storage.EncryptionScope) map[string]interface{} {
objMap := make(map[string]interface{})
Expand Down
10 changes: 10 additions & 0 deletions docs/tables/azure_storage_account.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,13 @@ from
where
lifecycle_management_policy -> 'properties' -> 'policy' -> 'rules' is null;
```

### List diagnostic settings details

```sql
select
name,
jsonb_pretty(diagnostic_settings) as diagnostic_settings
from
azure_storage_account;
```