簡體   English   中英

如何使用Azure API檢索“日志搜索”警報規則

[英]How to retrieve a “Log Search” alert rule using the Azure API

我已經使用Azure門戶創建了“日志搜索”警報規則,並且想要檢索其配置,以便可以自動創建它。 對於其他沒有問題的警報規則,我已經這樣做了。

問題是我找不到要調用哪個API來檢索規則 我希望在調用https://management.azure.com/subscriptions/{subscriptionId}/providers/microsoft.insights/scheduledQueryRules時找到它,但是返回一個空列表。 (我已經三遍檢查了subscriptionId是否正確)

我可以在Azure門戶中看到該規則,也可以從包含的資源組中列出資源:

在Azure門戶中看到的規則

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會返回此新規則,但原始規則仍然缺失。

我找到了一種方法,首先列出資源組中的資源,弄清楚警報規則的名稱,然后使用GET https://management.azure.com/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/microsoft.insights/scheduledQueryRules/{ruleName}檢索該規則的詳細信息GET https://management.azure.com/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/microsoft.insights/scheduledQueryRules/{ruleName}

GET https://management.azure.com/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

{
  "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"
  },
  "kind": null,
  "etag": "\"dc011985-0000-0000-0000-5c8641250000\"",
  "properties": {
    "description": "temp2",
    "displayName": "temp2",
    "enabled": "true",
    "lastUpdatedTime": "2019-03-11T11:06:13.5080064Z",
    "provisioningState": "Succeeded",
    "source": {
      "query": "<omitted>",
      "dataSourceId": "/subscriptions/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX/resourceGroups/dev-shared/providers/Microsoft.OperationalInsights/workspaces/dev-thelistlogs",
      "queryType": "ResultCount"
    },
    "schedule": {
      "frequencyInMinutes": 5,
      "timeWindowInMinutes": 5
    },
    "action": {
      "severity": "1",
      "aznsAction": {
        "actionGroup": [
          "/subscriptions/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX/resourcegroups/dev-shared/providers/microsoft.insights/actiongroups/development"
        ],
        "emailSubject": null,
        "customWebhookPayload": "{ \"alertname\":\"#alertrulename\", \"IncludeSearchResults\":true }"
      },
      "trigger": {
        "thresholdOperator": "GreaterThan",
        "threshold": 0
      },
      "odata.type": "Microsoft.WindowsAzure.Management.Monitoring.Alerts.Models.Microsoft.AppInsights.Nexus.DataContracts.Resources.ScheduledQueryRules.AlertingAction"
    }
  }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM