diff --git a/azure/table_azure_storage_account.go b/azure/table_azure_storage_account.go index 4bc9408f..230ce209 100644 --- a/azure/table_azure_storage_account.go +++ b/azure/table_azure_storage_account.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/storage/mgmt/2019-06-01/storage" "github.com/Azure/go-autorest/autorest" "github.com/tombuildsstuff/giovanni/storage/2018-11-09/queue/queues" @@ -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.", @@ -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{}) diff --git a/docs/tables/azure_storage_account.md b/docs/tables/azure_storage_account.md index a0418998..dbb8f8e6 100644 --- a/docs/tables/azure_storage_account.md +++ b/docs/tables/azure_storage_account.md @@ -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; +``` \ No newline at end of file