如何使用Azure API检索“日志搜索”警报规则

时间:2019-03-11 12:18:11

标签: azure alerts

我已经使用Azure门户创建了“日志搜索”警报规则,并且希望检索其配置,以便可以自动创建它。对于其他没有问题的警报规则,我已经做到了。

问题在于,我找不到调用该API来检索规则的。我希望在调用https://management.azure.com/subscriptions/{subscriptionId}/providers/microsoft.insights/scheduledQueryRules时找到它,但是返回一个空列表。 (我已经三遍检查了subscriptionId是正确的)

我可以在Azure门户中看到规则,也可以从包含的资源组中列出资源:

The rule as seen in the Azure Portal

GET https://management.azure.com/subscriptions/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX/resourceGroups/dev-shared/resources?api-version=2018-05-01

{
  "value": [
    {
      "id": "/subscriptions/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX/resourceGroups/dev-shared/providers/Microsoft.Insights/actiongroups/Development",
      "name": "Development",
      "type": "Microsoft.Insights/actiongroups",
      "location": "global"
    },
    // This is the alert rule that I am looking for:
    {
      "id": "/subscriptions/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX/resourceGroups/dev-shared/providers/microsoft.insights/scheduledqueryrules/dev-thelistlogs|7719d32a-4617-46bf-91e8-3f6977076d52|139d8419-a218-4774-b9a5-7c513f87384d|6fa515f3-b78e-4087-9621-ed5a14e62903",
      "name": "dev-thelistlogs|7719d32a-4617-46bf-91e8-3f6977076d52|139d8419-a218-4774-b9a5-7c513f87384d|6fa515f3-b78e-4087-9621-ed5a14e62903",
      "type": "microsoft.insights/scheduledqueryrules",
      "location": "westeurope",
      "tags": {
        "hidden-link:/subscriptions/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX/resourceGroups/dev-shared/providers/Microsoft.OperationalInsights/workspaces/dev-thelistlogs": "Resource"
      }
    },
    {
      "id": "/subscriptions/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX/resourceGroups/dev-shared/providers/Microsoft.OperationalInsights/workspaces/dev-thelistlogs",
      "name": "dev-thelistlogs",
      "type": "Microsoft.OperationalInsights/workspaces",
      "location": "westeurope"
    }
  ]
}

我也无法在Azure资源浏览器中找到规则。

我一直在尝试各种与警报,日志分析,指标等远程相关的API,但都没有成功。

如何使用Azure API检索此规则的详细信息?

编辑

从我的答案可以看出,我找到了一种检索详细信息的方法。仍然我想知道为什么ScheduledQueryRules列表api不返回该规则?

编辑2

能够检索规则详细信息后,我继续使用资源管理器模板创建了一个类似于该规则的新规则。事实证明,这条新规则是由API返回的,但是原始规则仍然缺失。

1 个答案:

答案 0 :(得分:0)

我找到了一种方法,首先列出资源组中的资源,找出警报规则的名称,然后使用N*5*3检索该规则的详细信息:

GET https://management.azure.com/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/microsoft.insights/scheduledQueryRules/{ruleName}