Skip to content

Commit

Permalink
Added column diagnostic_settings to azure_storage_account table. (#432)
Browse files Browse the repository at this point in the history
  • Loading branch information
bigdatasourav authored Jan 5, 2022
1 parent f9a78d6 commit 3263b6e
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
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 @@ -733,6 +741,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;
```

0 comments on commit 3263b6e

Please sign in to comment.