代码之家  ›  专栏  ›  技术社区  ›  jschmitter

如何通过ARM模板将Azure活动监视器连接到日志分析工作区

  •  0
  • jschmitter  · 技术社区  · 5 年前

    如何使用ARM模板将Azure活动日志连接到日志分析工作区?我可以通过门户连接它:

    enter image description here

    或者使用 powershell .

    但是我已经搜索了很广的范围,找不到关于如何使用ARM模板(或者目前是否可行)进行此操作的文档。

    我还尝试在Azure资源浏览器中创建连接并查看资源结构(并通过在PowerShell中获取资源),但是在进行连接之前和之后,JSON没有区别。

    更新:

    我尝试了基于 this documentation ,我是这样申请的:

    {
        "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
        "contentVersion": "1.0.0.0",
        "parameters": {},
        "resources": [
            {
                "name": "my-loganalytics-workspace-name/AzureActivityLog",
                "type": "Microsoft.OperationalInsights/workspaces/dataSources",
                "apiVersion": "2015-11-01-preview",
                "tags": {},
                "properties": {},
                "kind": "AzureActivityLog"
            }
        ]
    }
    

    但是部署没有完成(已经运行了30分钟),并且有一个模糊的错误:

    {
        "id": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxxxxxxx/resourceGroups/my-resource-group/providers/Microsoft.Resources/deployments/template/operations/A886A53AFF9B2E6C",
        "operationId": "A886A53AFF9B2E6C",
        "properties": {
            "provisioningOperation": "Create",
            "provisioningState": "Running",
            "timestamp": "2019-03-25T13:54:32.2320046Z",
            "duration": "PT21M58.8224235S",
            "trackingId": "47915902-f795-482a-a408-de408cd78a30",
            "serviceRequestId": "8c153090-c33d-4819-b9c4-8226df6a861e",
            "statusCode": "InternalServerError",
            "statusMessage": {
                "Message": "An error has occurred."
            },
            "targetResource": {
                "id": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxxxxxxx/resourceGroups/my-resource-group/providers/Microsoft.OperationalInsights/workspaces/my-log-analytics-workspace/dataSources/AzureActivityLog",
                "resourceType": "Microsoft.OperationalInsights/workspaces/dataSources",
                "resourceName": "my-log-analytics-workspace/AzureActivityLog"
            }
        }
    }
    
    0 回复  |  直到 5 年前
        1
  •  1
  •   KrishnaG    5 年前

    是的,可以使用门户或PowerShell,如此处所述--gt; Connecting Azure Activity Log to Log Analytics instance using PowerShell

    我已经使用门户或PowerShell创建了它,并且可以使用PowerShell获取这些详细信息,如下面的屏幕截图所示,其中resourceID参数显示了资源类型“microsoft.operationalingsights/workspace/datasources”。

    enter image description here

    enter image description here

    因此,最可能的情况是也可以通过ARM模板的方式实现,因为我看到了资源类型“microsoft.operationalinsights/workspace/datasources”的ARM模板引用,如图所示--gt; https://docs.microsoft.com/en-us/azure/templates/microsoft.operationalinsights/2015-11-01-preview/workspaces/datasources

    希望这有帮助!!干杯!!

        2
  •  0
  •   jschmitter    5 年前

    我找到了一个有效的示例模板 here .

    所以我的原始模板需要一个不同的名称(必须包括subscriptionID)和 linkedResourceId properties :

    {
        "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
        "contentVersion": "1.0.0.0",
        "parameters": {},
        "resources": [
            {
                "name": "[concat('my-loganalytics-workspace-name', '/', subscription().subscriptionId)]",
                "type": "Microsoft.OperationalInsights/workspaces/dataSources",
                "apiVersion": "2015-11-01-preview",
                "tags": {},
                "properties": {
                    "linkedResourceId": "[concat(subscription().Id, '/providers/microsoft.insights/eventTypes/management')]"
                },
                "kind": "AzureActivityLog"
            }
        ]
    }