Repository: cloud-custodian/cloud-custodian

Issue:
Azure - Custom pyformat in output_dir - {policy} variable is expanded as policy instead of policy name
I'm trying to use the built in pyformat feature to add the subscription id in the output path for each policy run log using 
```azure://<storage-account-name>.blob.core.windows.net/custodianlogs/{account_id}/{policy}/{now:%Y/%m/%d/%H/}```.

**Note**: In all examples, I replaced my actual storage account name with `<storage-account-name>`

When using this format, {account_id} is replaced with the subscription id however, {policy} is not the policy name but instead the entire policy json.

```
"output_dir": "azure://<storage-account-name>.blob.core.windows.net/custodianlogs/00000000-0000-0000-0000-000000/{'name': 'rg-find-empty', 'description': 'Find any empty resource groups from subscription\\n', 'resource': 'azure.resourcegroup', 'mode': {'type': 'azure-periodic', 'schedule': '0 30 9 * * *', 'provision-options': {'servicePlan': {'name': 'custodian', 'skuTier': 'Basic', 'skuName': 'B2', 'resourceGroupName': 'custodian'}}, 'execution-options': {'output_dir': 'azure://<storage-account-name>.blob.core.windows.net/custodianlogs/{account_id}/{policy}/{now:%Y/%m/%d/%H/}'}}, 'filters': [{'type': 'empty-group'}]}/2018/11/01/23/"
```

I also noticed that `/2018/11/01/23/` is hard-coded in the output_dir path now instead of `{now:%Y/%m/%d/%H/}`

## Example
```yaml
policies:
    - name: rg-find-empty
      description: |
        Find any empty resource groups from subscription
      resource: azure.resourcegroup
      mode:
        type: azure-periodic
        schedule: '0 30 9 * * *'
        provision-options:
          servicePlan:
            name: custodian
            skuTier: Basic
            skuName: B2
            resourceGroupName: custodian
        execution-options:
          output_dir: azure://<storage-account-name>.blob.core.windows.net/custodianlogs/{account_id}/{policy}/{now:%Y/%m/%d/%H/}
      filters:
        - type: empty-group
```

## config.json output
```json
{
  "policies": [
    {
      "name": "rg-find-empty",
      "description": "Find any empty resource groups from subscription\n",
      "resource": "azure.resourcegroup",
      "mode": {
        "type": "azure-periodic",
        "schedule": "0 30 9 * * *",
        "provision-options": {
          "servicePlan": {
            "name": "custodian",
            "skuTier": "Basic",
            "skuName": "B2",
            "resourceGroupName": "custodian"
          }
        },
        "execution-options": {
          "output_dir": "azure://<storage-account-name>.blob.core.windows.net/custodianlogs/00000000-0000-0000-0000-000000/{'name': 'rg-find-empty', 'description': 'Find any empty resource groups from subscription\\n', 'resource': 'azure.resourcegroup', 'mode': {'type': 'azure-periodic', 'schedule': '0 30 9 * * *', 'provision-options': {'servicePlan': {'name': 'custodian', 'skuTier': 'Basic', 'skuName': 'B2', 'resourceGroupName': 'custodian'}}, 'execution-options': {'output_dir': 'azure://<storage-account-name>.blob.core.windows.net/custodianlogs/{account_id}/{policy}/{now:%Y/%m/%d/%H/}'}}, 'filters': [{'type': 'empty-group'}]}/2018/11/01/23/"
        }
      },
      "filters": [
        {
          "type": "empty-group"
        }
      ]
    }
  ]
}
```

/cc @stefangordon @aluong @noelbundick


Discussion:

Resolving patch:
diff --git a/c7n/output.py b/c7n/output.py
--- a/c7n/output.py
+++ b/c7n/output.py
@@ -414,7 +414,7 @@ def get_output_vars(self):
         data = {
             'account_id': self.ctx.options.account_id,
             'region': self.ctx.options.region,
-            'policy': self.ctx.policy.name,
+            'policy_name': self.ctx.policy.name,
             'now': datetime.utcnow(),
             'uuid': str(uuid.uuid4())}
         return data
diff --git a/tools/c7n_azure/c7n_azure/output.py b/tools/c7n_azure/c7n_azure/output.py
--- a/tools/c7n_azure/c7n_azure/output.py
+++ b/tools/c7n_azure/c7n_azure/output.py
@@ -41,7 +41,7 @@ class AzureStorageOutput(DirectoryOutput):
 
     """
 
-    DEFAULT_BLOB_FOLDER_PREFIX = '{policy}/{now:%Y/%m/%d/%H/}'
+    DEFAULT_BLOB_FOLDER_PREFIX = '{policy_name}/{now:%Y/%m/%d/%H/}'
 
     def __init__(self, ctx, config=None):
         self.ctx = ctx


Test patch:
diff --git a/tools/c7n_azure/tests/test_output.py b/tools/c7n_azure/tests/test_output.py
--- a/tools/c7n_azure/tests/test_output.py
+++ b/tools/c7n_azure/tests/test_output.py
@@ -76,7 +76,7 @@ def test_azure_output_get_default_output_dir(self):
 
         AzureStorageOutput.get_output_vars = mock.Mock(
             return_value={
-                'policy': 'MyPolicy',
+                'policy_name': 'MyPolicy',
                 'now': date(2018, 10, 1)
             })
 
@@ -92,11 +92,11 @@ def test_azure_output_get_custom_output_dir(self):
         AzureStorageOutput.get_output_vars = mock.Mock(
             return_value={
                 'account_id': 'MyAccountId',
-                'policy': 'MyPolicy',
+                'policy_name': 'MyPolicy',
                 'now': date(2018, 10, 1)
             })
 
-        output = self.get_azure_output('{account_id}/{policy}/{now:%Y}')
+        output = self.get_azure_output('{account_id}/{policy_name}/{now:%Y}')
         path = output.get_output_path(output.config['url'])
         self.assertEqual(path,
                          'azure://mystorage.blob.core.windows.net/logs/MyAccountId/MyPolicy/2018')