Skip to content

Commit

Permalink
Added column server_configurations in azure_mysql_server table. Closes
Browse files Browse the repository at this point in the history
  • Loading branch information
bigdatasourav authored Jan 5, 2022
1 parent 89d9e9b commit f9a78d6
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 0 deletions.
58 changes: 58 additions & 0 deletions azure/table_azure_mysql_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,13 @@ func tableAzureMySQLServer(_ context.Context) *plugin.Table {
Type: proto.ColumnType_JSON,
Transform: transform.From(extractMySQLServerPrivateEndpointConnections),
},
{
Name: "server_configurations",
Description: "The server configurations(parameters) details of the server.",
Type: proto.ColumnType_JSON,
Hydrate: listMySQLServersConfigurations,
Transform: transform.FromValue(),
},
{
Name: "server_keys",
Description: "The server keys of the server.",
Expand Down Expand Up @@ -352,6 +359,37 @@ func listMySQLServersServerKeys(ctx context.Context, d *plugin.QueryData, h *plu
return mySQLServersServerKeys, nil
}

func listMySQLServersConfigurations(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {
plugin.Logger(ctx).Trace("listMySQLServersConfigurations")

server := h.Item.(mysql.Server)
resourceGroup := strings.Split(string(*server.ID), "/")[4]
serverName := *server.Name

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

client := mysql.NewConfigurationsClientWithBaseURI(session.ResourceManagerEndpoint, subscriptionID)
client.Authorizer = session.Authorizer

op, err := client.ListByServer(ctx, resourceGroup, serverName)
if err != nil {
plugin.Logger(ctx).Error("listMySQLServersConfigurations", "list", err)
return nil, err
}

var mySQLServersConfigurations []map[string]interface{}

for _, i := range *op.Value {
mySQLServersConfigurations = append(mySQLServersConfigurations, extractMySQLServersconfiguration(i))
}

return mySQLServersConfigurations, nil
}

//// TRANSFORM FUNCTION

// If we return the API response directly, the output will not provide the properties of PrivateEndpointConnections
Expand Down Expand Up @@ -419,3 +457,23 @@ func extractMySQLServersServerKey(i mysql.ServerKey) map[string]interface{} {
}
return mySQLServersServerKey
}

// If we return the API response directly, the output will not provide the properties of Configurations
func extractMySQLServersconfiguration(i mysql.Configuration) map[string]interface{} {
mySQLServersconfiguration := make(map[string]interface{})

if i.ID != nil {
mySQLServersconfiguration["ID"] = *i.ID
}
if i.Name != nil {
mySQLServersconfiguration["Name"] = *i.Name
}
if i.Type != nil {
mySQLServersconfiguration["Type"] = *i.Type
}
if i.ConfigurationProperties != nil {
mySQLServersconfiguration["ConfigurationProperties"] = *i.ConfigurationProperties
}

return mySQLServersconfiguration
}
62 changes: 62 additions & 0 deletions docs/tables/azure_mysql_server.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,65 @@ from
azure_mysql_server,
jsonb_array_elements(server_keys) as keys;
```

### List server configuration details

**Note:** `Server configurations` is the same as `Server parameters` as shown in Azure MySQL server console

```sql
select
name as server_name,
id as server_id,
configurations ->> 'Name' as configuration_name,
configurations -> 'ConfigurationProperties' ->> 'value' as value
from
azure_mysql_server,
jsonb_array_elements(server_configurations) as configurations;
```

### Current state of audit_log_enabled parameter for the servers

```sql
select
name as server_name,
id as server_id,
configurations ->> 'Name' as configuration_name,
configurations -> 'ConfigurationProperties' ->> 'value' as value
from
azure_mysql_server,
jsonb_array_elements(server_configurations) as configurations
where
configurations ->> 'Name' = 'audit_log_enabled';
```

### List servers with slow_query_log parameter enabled

```sql
select
name as server_name,
id as server_id,
configurations ->> 'Name' as configuration_name,
configurations -> 'ConfigurationProperties' ->> 'value' as value
from
azure_mysql_server,
jsonb_array_elements(server_configurations) as configurations
where
configurations ->'ConfigurationProperties' ->> 'value' = 'ON'
and configurations ->> 'Name' = 'slow_query_log';
```

### List servers with log_output parameter set to file

```sql
select
name as server_name,
id as server_id,
configurations ->> 'Name' as configuration_name,
configurations -> 'ConfigurationProperties' ->> 'value' as value
from
azure_mysql_server,
jsonb_array_elements(server_configurations) as configurations
where
configurations ->'ConfigurationProperties' ->> 'value' = 'FILE'
and configurations ->> 'Name' = 'log_output';
```

0 comments on commit f9a78d6

Please sign in to comment.