Here alert setup based on status of a runbook job is mentioned. Can alerts also be made based on the errors present in the errors tab(as given below). So status might say 'completed' but there will be errors in the 'Errors' tab, I am talking about such a situation.
1 Answers
I have tried to reproduce this use case and I believe that alerts can be made based on the errors present in the errors tab i.e., by forwarding job data to Log Analytics and by using below kusto query in your log alert rule.
AzureDiagnostics
| where ResourceProvider == "MICROSOFT.AUTOMATION" and RunbookName_s == "<YourRunbookName>"
| where ResultDescription startswith "Write-Error"
Illustration:
- Create a runbook with the content Write-Error -Message "This is an error message". For example, check below screenshot.
- Publish the runbook and execute it. Then as shown in below screenshot, you will be able to see the errors present in the Errors tab.
Go to Logs tile of your Log Analytics workspace to which you have forwarded the Azure Automation job data and then run below kusto query to verify if the logs are forwarded or not. For reference, check below screenshot as well.
AzureDiagnostics | where ResourceProvider == "MICROSOFT.AUTOMATION" and RunbookName_s == "test6_error" | project TimeGenerated, Category, ResultType, ResultDescription, StreamType_s
As you can see JobStreams category recorded the error thats present in Errors tab in the Azure Automation job so our kusto query can be something like shown below.
AzureDiagnostics
| where ResourceProvider == "MICROSOFT.AUTOMATION" and RunbookName_s == "test6_error"
| where ResultDescription startswith "Write-Error"
| project TimeGenerated, Category, ResultType, ResultDescription, StreamType_s

- 3,340
- 2
- 6
- 16