简体   繁体   English

需要使用 rest api 调用获取 azure 自动化运行手册错误

[英]Need to get azure automation runbook error using rest api call

I am using Rest api method to start runbook.我正在使用 Rest api 方法来启动 Runbook。 I am getting output after execution of runbook using rest API but not getting errors with that我在使用 rest API 执行 Runbook 后得到输出,但没有得到错误

API i am using to get output is我用来获取输出的 API 是

GET https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation/automationAccounts/{automationAccountName}/jobs/{jobName}/output?api-version=2017-05-15-preview

But not getting any API to get errors.但是没有得到任何 API 来获取错误。 In this link( https://docs.microsoft.com/en-us/rest/api/automation/job/get ) I can see ErrorResponse there but dont know how to use it.在此链接( https://docs.microsoft.com/en-us/rest/api/automation/job/get )中,我可以在那里看到 ErrorResponse 但不知道如何使用它。

I need rest api to get errors in runbook.我需要休息 api 才能在 Runbook 中获取错误。

Firstly, the 'ErrorResponse' which you see in Job - Get or Job - Get Output REST API's basically talks about response of that particular REST API's operation.首先,您在Job - GetJob - Get Output REST API 中看到的“ErrorResponse”基本上是关于该特定 REST API 操作的响应。 It has no connection with Azure Automation job error.它与 Azure 自动化作业错误无关。

Secondly, AFAIK currently there is no direct supported REST API to get Azure Automation job's error information.其次,AFAIK 目前没有直接支持的 REST API 来获取 Azure 自动化作业的错误信息。 If interested, you may share your feedback as feature request here .如果有兴趣,您可以在此处分享您的反馈作为功能请求。 However, if you want to get Azure Automation job's error information then we can forward job status and job streams from Azure Automation to Azure Monitor logs as explained in this document and then leverage Azure Log Analytics REST API to fetch Azure Automation job's error information where you may have to provide query something like shown below.但是,如果您想获取 Azure 自动化作业的错误信息,那么我们可以按照文档中的说明将作业状态和作业流从 Azure 自动化转发到 Azure Monitor 日志,然后利用Azure Log Analytics REST API来获取 Azure 自动化作业的错误信息。可能必须提供如下所示的查询。

AzureDiagnostics 
| where ResourceProvider == "MICROSOFT.AUTOMATION" and Category == "JobStreams" and StreamType_s == "Error" and JobId_g == "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
| summarize AggregatedValue = count() by JobId_g

Hope this helps!!希望这可以帮助!!

UPDATE :更新

Please find below screenshots for illustration that only output stream content is being captured by get output API.请查看以下屏幕截图,以说明 get output API 仅捕获输出流内容。

Scenario 1 - Job has only error stream but no output stream and output of get output API :场景 1 - 作业只有错误流,但没有输出流和获取输出 API 的输出

在此处输入图片说明

在此处输入图片说明

在此处输入图片说明

在此处输入图片说明

在此处输入图片说明

Scenario 2 - Job has only output stream but no error stream and output of get output API :场景 2 - 作业只有输出流但没有错误流和获取输出 API 的输出

在此处输入图片说明

在此处输入图片说明

在此处输入图片说明

在此处输入图片说明

在此处输入图片说明

I encountered the same situation where my application needed to know whether a job ended with errors or not.我遇到了同样的情况,我的应用程序需要知道作业是否以错误结束。 Since there is no straight forward way to do it, I figured out a work around.由于没有直接的方法可以做到这一点,我想出了一个解决方法。

Step 1: I assume you have the job ID.第 1 步:我假设您有工作 ID。 Use the job api to get the job name .使用作业 api 获取作业名称 I don't think the UI is displaying job name.我认为 UI 没有显示作业名称。 That's why I had to use the jobs API to get the same.这就是为什么我必须使用作业 API 来获得相同的结果。 eg.例如。

https://management.azure.com/subscriptions/{SUBSCRIPTION_ID}/resourceGroups/{RESOURCE_GROUP_NAME}/providers/Microsoft.Automation/automationAccounts/{AUTOMATION_ACCOUNT_NAME}/jobs/{JOB_ID}/?api-version=2017-05-15-preview https://management.azure.com/subscriptions/{SUBSCRIPTION_ID}/resourceGroups/{RESOURCE_GROUP_NAME}/providers/Microsoft.Automation/automationAccounts/{AUTOMATION_ACCOUNT_NAME}/jobs/{JOB_ID}/?api-version=2017-05-15 -预览

Step 2: Use the job name with job stream API.第 2 步:将作业名称与作业流 API 结合使用。 eg.例如。 https://management.azure.com/subscriptions/{SUBSCRIPTION_ID}/resourceGroups/{RESOURCE_GROUP}/providers/Microsoft.Automation/automationAccounts/{AUTOMATION_ACCOUNT_NAME}/jobs/{JOB_NAME}/streams/?&api-version=2017-05-15-preview https://management.azure.com/subscriptions/{SUBSCRIPTION_ID}/resourceGroups/{RESOURCE_GROUP}/providers/Microsoft.Automation/automationAccounts/{AUTOMATION_ACCOUNT_NAME}/jobs/{JOB_NAME}/streams/?&api-version=2017-05 -15-预览

This will return all the outputs including the error.这将返回包括错误在内的所有输出。

 {"value" = [{
   "id": "...",
   "properties": 
    {
      "jobStreamId": "...",
      "summary": "Resource group not found",
      "time": "2021-04-05T13:37:04.3629685+00:00",
      "streamType": "Error"
    }
 }
]}

The output format is defined in the official documentation here.输出格式在此处的官方文档中定义。 https://docs.microsoft.com/en-us/rest/api/automation/jobstream/listbyjob https://docs.microsoft.com/en-us/rest/api/automation/jobstream/listbyjob

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM