管理解决方案(预览版)中的视图Views in management solutions (Preview)

备注

这是用于创建当前处于预览版的管理解决方案的初步文档。This is preliminary documentation for creating management solutions which are currently in preview. 如下所述的全部架构均会有变动。Any schema described below is subject to change.

管理解决方案通常包括一个或多个用来可视化数据的视图。Management solutions will typically include one or more views to visualize data. 本文介绍如何导出视图设计器所创建的视图,并将其包含在管理解决方案中。This article describes how to export a view created by the View Designer and include it in a management solution.

备注

本文中的示例使用管理解决方案需要或通用的参数和变量,在 Azure 中设计和开发解决方案中对它们进行了介绍The samples in this article use parameters and variables that are either required or common to management solutions and described in Design and build a management solution in Azure

先决条件Prerequisites

本文假设已经熟悉如何创建管理解决方案及解决方案文件的结构。This article assumes that you're already familiar with how to create a management solution and the structure of a solution file.

概述Overview

若要在管理解决方案中包含视图,则需要在解决方案文件中为其创建资源To include a view in a management solution, you create a resource for it in the solution file. 描述视图详细配置的 JSON 通常很复杂,普通的解决方案作者无法手动进行创建。The JSON that describes the view's detailed configuration is typically complex though and not something that a typical solution author would be able to create manually. 最常见方法是使用 视图设计器创建视图,并将其导出,然后再将其详细配置添加到解决方案。The most common method is to create the view using the View Designer, export it, and then add its detailed configuration to the solution.

将视图添加到解决方案的基本步骤如下所示。The basic steps to add a view to a solution are as follows. 每个步骤都在后续相应部分进行了详细介绍。Each step is described in further detail in the sections below.

  1. 将视图导出到文件。Export the view to a file.
  2. 在解决方案中创建视图资源。Create the view resource in the solution.
  3. 添加视图详细信息。Add the view details.

将视图导出到文件Export the view to a file

按照Log Analytics 视图设计器中的说明将视图导出到文件。Follow the instructions at Log Analytics View Designer to export a view to a file. 导出的文件是与解决方案文件具有相同元素的 JSON 格式The exported file will be in JSON format with the same elements as the solution file.

视图文件的 resources 元素将具有表示 Log Analytics 工作区的 Microsoft.OperationalInsights/workspaces 类型的资源。The resources element of the view file will have a resource with a type of Microsoft.OperationalInsights/workspaces that represents the Log Analytics workspace. 此元素将具有表示此视图的 views 类型的子元素,并包含其详细配置。This element will have a subelement with a type of views that represents the view and contains its detailed configuration. 复制此元素的详细信息,然后将其复制到解决方案中。You will copy the details of this element and then copy it into your solution.

在解决方案中创建视图资源Create the view resource in the solution

将以下视图将资源添加到解决方案文件的 resources 元素。Add the following view resource to the resources element of your solution file. 这会使用以下描述的必须同时添加的变量。This uses variables that are described below that you must also add. 注意:仪表板OverviewTile 属性是占位符,将使用导出的视图文件中的相应属性对齐进行覆盖。Note that the Dashboard and OverviewTile properties are placeholders that you will overwrite with the corresponding properties from the exported view file.

{
    "apiVersion": "[variables('LogAnalyticsApiVersion')]",
    "name": "[concat(parameters('workspaceName'), '/', variables('ViewName'))]",
    "type": "Microsoft.OperationalInsights/workspaces/views",
    "location": "[parameters('workspaceregionId')]",
    "id": "[Concat('/subscriptions/', subscription().subscriptionId, '/resourceGroups/', resourceGroup().name, '/providers/Microsoft.OperationalInsights/workspaces/', parameters('workspaceName'),'/views/', variables('ViewName'))]",
    "dependson": [
        ],
    "properties": {
        "Id": "[variables('ViewName')]",
        "Name": "[variables('ViewName')]",
        "DisplayName": "[variables('ViewName')]",
        "Description": "",
        "Author": "[variables('ViewAuthor')]",
        "Source": "Local",
        "Dashboard": ,
        "OverviewTile":
    }
}

将以下变量添加到解决方案文件的 variables 元素,并将值替换为解决方案的值。Add the following variables to the variables element of the solution file and replace the values to those for your solution.

"LogAnalyticsApiVersion": "<api-version>",
"ViewAuthor": "Your name."
"ViewDescription": "Optional description of the view."
"ViewName": "Provide a name for the view here."

注意:可以从导出的视图文件复制整个视图资源,但需要对其进行以下更改才能在解决方案中生效。Note that you could copy the entire view resource from your exported view file, but you would need to make the following changes for it to work in your solution.

  • 视图资源的类型需要从视图更改为 Microsoft.OperationalInsights/workspacesThe type for the view resource needs to be changed from views to Microsoft.OperationalInsights/workspaces.
  • 视图资源的名称属性需要更改为包括工作区名称。The name property for the view resource needs to be changed to include the workspace name.
  • 工作区中的依赖关系需要删除,因为并未在解决方案中定义工作区资源。The dependency on the workspace needs to be removed since the workspace resource isn't defined in the solution.
  • 需要将 DisplayName 属性添加到视图。DisplayName property needs to be added to the view. Id名称DisplayName 必须完全匹配。The Id, Name, and DisplayName must all match.
  • 必须更改参数名称,以匹配所需的参数集。Parameter names must be changed to match the required set of parameters.
  • 变量应在解决方案中进行定义,并在适当的属性中使用。Variables should be defined in the solution and used in the appropriate properties.

Log Analytics API 版本Log Analytics API version

资源管理器模板中定义的所有 Log Analytics 资源均包含 apiVersion 属性,该属性将定义资源应使用的 API 版本。All Log Analytics resources defined in a Resource Manager template have a property apiVersion that defines the version of the API the resource should use. 对于使用旧版查询语言和升级版查询语言的具有查询的视图,此版本有所不同。This version is different for views with queries that use the legacy and the upgraded query language.

下表指定了旧版和升级版工作区中视图的 Log Analytics API 版本:The following table specifies the Log Analytics API versions for views in legacy and upgraded workspaces:

工作区版本Workspace version API 版本API version 查询Query
v1(旧版)v1 (legacy) 2015-11-01-preview2015-11-01-preview 旧版格式。Legacy format.
示例:Type=Event EventLevelName = ErrorExample: Type=Event EventLevelName = Error
v2(升级版)v2 (upgraded) 2015-11-01-preview2015-11-01-preview 旧版格式。Legacy format. 在安装时转换为升级版格式。Converted to upgraded format on install.
示例:Type=Event EventLevelName = ErrorExample: Type=Event EventLevelName = Error
转换为:Event | where EventLevelName == "Error"Converted to: Event | where EventLevelName == "Error"
v2(升级版)v2 (upgraded) 2017-03-03-preview2017-03-03-preview 升级版格式。Upgrade format.
示例:Event | where EventLevelName == "Error"Example: Event | where EventLevelName == "Error"

添加视图详细信息Add the view details

导出的视图文件中的视图资源会在 properties 属性中包含两个元素,名称分别为仪表板OverviewTile它们包含视图的详细配置。The view resource in the exported view file will contain two elements in the properties element named Dashboard and OverviewTile which contain the detailed configuration of the view. 将这两个元素及其内容复制解决方案文件中的视图资源的 properties 元素。Copy these two elements and their contents into the properties element of the view resource in your solution file.

示例Example

例如,下面的示例演示包含视图的简单解决方案文件。For example, the following sample shows a simple solution file with a view. 由于空间原因,省略号 (...) 表示仪表板OverviewTile 内容。Ellipses (...) are shown for the Dashboard and OverviewTile contents for space reasons.

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "workspaceName": {
            "type": "string"
        },
        "accountName": {
            "type": "string"
        },
        "workspaceRegionId": {
            "type": "string"
        },
        "regionId": {
            "type": "string"
        },
        "pricingTier": {
            "type": "string"
        }
    },
    "variables": {
        "SolutionVersion": "1.1",
        "SolutionPublisher": "Contoso",
        "SolutionName": "Contoso Solution",
        "LogAnalyticsApiVersion": "2015-11-01-preview",
        "ViewAuthor":  "user@contoso.com",
        "ViewDescription":  "This is a sample view.",
        "ViewName":  "Contoso View"
    },
    "resources": [
        {
            "name": "[concat(variables('SolutionName'), '(' ,parameters('workspacename'), ')')]",
            "location": "[parameters('workspaceRegionId')]",
            "tags": { },
            "type": "Microsoft.OperationsManagement/solutions",
            "apiVersion": "[variables('LogAnalyticsApiVersion')]",
            "dependsOn": [
                "[concat('Microsoft.OperationalInsights/workspaces/', parameters('workspacename'), '/views/', variables('ViewName'))]"
            ],
            "properties": {
                "workspaceResourceId": "[concat(resourceGroup().id, '/providers/Microsoft.OperationalInsights/workspaces/', parameters('workspacename'))]",
                "referencedResources": [
                ],
                "containedResources": [
                    "[concat('Microsoft.OperationalInsights/workspaces/', parameters('workspaceName'), '/views/', variables('ViewName'))]"
                ]
            },
            "plan": {
                "name": "[concat(variables('SolutionName'), '(' ,parameters('workspaceName'), ')')]",
                "Version": "[variables('SolutionVersion')]",
                "product": "ContosoSolution",
                "publisher": "[variables('SolutionPublisher')]",
                "promotionCode": ""
            }
        },
        {
            "apiVersion": "[variables('LogAnalyticsApiVersion')]",
            "name": "[concat(parameters('workspaceName'), '/', variables('ViewName'))]",
            "type": "Microsoft.OperationalInsights/workspaces/views",
            "location": "[parameters('workspaceregionId')]",
            "id": "[Concat('/subscriptions/', subscription().subscriptionId, '/resourceGroups/', resourceGroup().name, '/providers/Microsoft.OperationalInsights/workspaces/', parameters('workspaceName'),'/views/', variables('ViewName'))]",
            "dependson": [
            ],
            "properties": {
                "Id": "[variables('ViewName')]",
                "Name": "[variables('ViewName')]",
                "DisplayName": "[variables('ViewName')]",
                "Description": "[variables('ViewDescription')]",
                "Author": "[variables('ViewAuthor')]",
                "Source": "Local",
                "Dashboard": ...,
                "OverviewTile": ...
            }
        }
      ]
}

后续步骤Next steps