1
votes

I am trying to deploy a solution with Logic Apps whose log data I would like to go to a Log Analytics workspace. This is easy to configure in the portal via Diagnostic Settings > Add Diagnostic Setting > check 'Send to Log Analytics' and select a pre-existing workspace.

However I can't see from looking at the exported templates for the Logic App, for the workspace, or for the whole resource group, how you configure this link in an ARM template. The documentation doesn't seem to mention this setting at all either.

1

1 Answers

4
votes

here's an example to stream to event hub\storage account\log analytics:

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "logicAppName": {
            "type": "string",
            "metadata": {
                "description": "Name of the Logic App that will be created."
            }
        },
        "testUri": {
            "type": "string",
            "defaultValue": "https://azure.microsoft.com/status/feed/"
        },
        "settingName": {
            "type": "string",
            "metadata": {
                "description": "Name of the setting. Name for the diagnostic setting resource. Eg. 'archiveToStorage' or 'forSecurityTeam'."
            }
        },
        "storageAccountName": {
            "type": "string",
            "metadata": {
                "description": "Name of the Storage Account in which Diagnostic Logs should be saved."
            }
        },
        "eventHubAuthorizationRuleId": {
            "type": "string",
            "metadata": {
                "description": "Resource ID of the event hub authorization rule for the Event Hubs namespace in which the event hub should be created or streamed to."
            }
        },
        "eventHubName": {
            "type": "string",
            "metadata": {
                "description": "Optional. Name of the event hub within the namespace to which logs are streamed. Without this, an event hub is created for each log category."
            }
        },
        "workspaceId": {
            "type": "string",
            "metadata": {
                "description": "Log Analytics workspace ID for the Log Analytics workspace to which logs will be sent."
            }
        }
    },
    "variables": {},
    "resources": [
        {
            "type": "Microsoft.Logic/workflows",
            "name": "[parameters('logicAppName')]",
            "apiVersion": "2016-06-01",
            "location": "[resourceGroup().location]",
            "properties": {
                "definition": {
                    "$schema": "https://schema.management.azure.com/schemas/2016-06-01/Microsoft.Logic.json",
                    "contentVersion": "1.0.0.0",
                    "parameters": {
                        "testURI": {
                            "type": "string",
                            "defaultValue": "[parameters('testUri')]"
                        }
                    },
                    "triggers": {
                        "recurrence": {
                            "type": "recurrence",
                            "recurrence": {
                                "frequency": "Hour",
                                "interval": 1
                            }
                        }
                    },
                    "actions": {
                        "http": {
                            "type": "Http",
                            "inputs": {
                                "method": "GET",
                                "uri": "@parameters('testUri')"
                            },
                            "runAfter": {}
                        }
                    },
                    "outputs": {}
                },
                "parameters": {}
            },
            "resources": [
                {
                    "type": "providers/diagnosticSettings",
                    "name": "[concat('Microsoft.Insights/', parameters('settingName'))]",
                    "dependsOn": [
                        "[resourceId('Microsoft.Logic/workflows', parameters('logicAppName'))]"
                    ],
                    "apiVersion": "2017-05-01-preview",
                    "properties": {
                        "name": "[parameters('settingName')]",
                        "storageAccountId": "[resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccountName'))]",
                        "eventHubAuthorizationRuleId": "[parameters('eventHubAuthorizationRuleId')]",
                        "eventHubName": "[parameters('eventHubName')]",
                        "workspaceId": "[parameters('workspaceId')]",
                        "logs": [
                            {
                                "category": "WorkflowRuntime",
                                "enabled": true,
                                "retentionPolicy": {
                                    "days": 0,
                                    "enabled": false
                                }
                            }
                        ],
                        "metrics": [
                            {
                                "timeGrain": "PT1M",
                                "enabled": true,
                                "retentionPolicy": {
                                    "enabled": false,
                                    "days": 0
                                }
                            }
                        ]
                    }
                }
            ]
        }
    ]
}

https://docs.microsoft.com/en-us/azure/azure-monitor/platform/diagnostic-logs-stream-template