0

I am using Rest api method to start runbook. I am getting output after execution of runbook using rest API but not getting errors with that

API i am using to get output is

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. In this link(https://learn.microsoft.com/en-us/rest/api/automation/job/get) I can see ErrorResponse there but dont know how to use it.

I need rest api to get errors in runbook.

Ac9293
  • 65
  • 1
  • 12

2 Answers2

0

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. It has no connection with Azure Automation job error.

Secondly, AFAIK currently there is no direct supported REST API to get Azure Automation job's error information. 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.

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.

Scenario 1 - Job has only error stream but no output stream and output of get output API:

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

Scenario 2 - Job has only output stream but no error stream and output of get output API:

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

KrishnaG
  • 3,340
  • 2
  • 6
  • 16
  • pretty sure there is an api to get job output, because portal gets it somehow – 4c74356b41 Aug 19 '19 at 12:36
  • Yes, we have API to get job output as shared in above answer. But I don't think it includes error stream data as well. Please confirm if you are sure that it includes error stream as well. – KrishnaG Aug 19 '19 at 12:38
  • what do you mean? on the portal you can see both stderr\stdout. without oms – 4c74356b41 Aug 19 '19 at 12:39
  • What i mean is, on the portal we have various tabs (like output, error, exception, all logs, etc.) under a particular job's tile. And get job output API probably gets content from output tab !? but not from other tab's like error, exception, etc. – KrishnaG Aug 19 '19 at 12:41
  • why not? you never used azure automation runbooks? you can see individual streams – 4c74356b41 Aug 19 '19 at 12:43
  • Updated screenshots for illustration to confirm that get output API fetches output stream content but not other streams content. Hope this helps you!! – KrishnaG Aug 19 '19 at 14:09
  • Thanks Krishna. but i need API to get error. I see it is not there – Ac9293 Aug 20 '19 at 05:20
0

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. Use the job api to get the job name. I don't think the UI is displaying job name. That's why I had to use the jobs API to get the same. 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

Step 2: Use the job name with job stream 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

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://learn.microsoft.com/en-us/rest/api/automation/jobstream/listbyjob

bala
  • 93
  • 2
  • 9