2

I am in learning phase of Azure. Recently I was working on setting up alerts to get an email notification when Azure runbook fails. I am testing it on a test runbook which has a simple code to display "Hello" and for deliberately failing the runbook, I am mis-spelling Write-Output command as Write-Output11 just to test the failure. The runbook is created using powershell and I am using try-catch block to catch the error

The runbook is marked as Failed as Write-Output11 is not a valid command

I have setup a simple Alert which will detect this runbook and check for its Failed state
The condition used while setting up alert is

Runbook Name = Test_Runbook
Status = Failed

Alert Logic
Operator = Greater than or equal to
Aggregation Type = Total
Threshold Value = 0
Unit = Count
Aggregation Granularity = 1 min
Frequency of Evaluation = Every 1 min

The runbook fails everytime I execute it(as Write-Output11 is invalid command) but alerts are not triggered to detect the runbook failure.
Please advise what wrong I am setting up?

2 Answers2

2

@Shampy Takkar - Following through below steps , was able to get an alert for job failure.

  1. Enable diagnostic logs for the Azure automation account

  2. You can confirm the output of query is giving you expected result on failed runbooks/jobs. You can add any additional filters needed to scope the query

    AzureDiagnostics | where ResourceProvider == "MICROSOFT.AUTOMATION" and OperationName == "Job" and ResultType == "Failed" | sort by TimeGenerated asc

  3. Create a "new alert rule" using the above query with threshold value and frequency at which the alert needs to trigger.

enter image description here

  1. Created a action group to get an notification via email and also on text. You can always use other options within action groups for notification.

  2. Ran the Runbook to make it fail and was able to get an email alert and also a text.

Hope the information helps, please let me know if you have any further queries.

bharathn-msft
  • 877
  • 5
  • 10
  • Thanks, I was able to get it working using same steps – Shampy Takkar Aug 02 '21 at 11:50
  • Thank you @ShampyTakkar for your response and glad to hear that you got it working with same steps. Please do accept the answer so that other community members can also be benefited by this thread. – bharathn-msft Aug 02 '21 at 15:54
0

If you want to create alert based on runbook completion status(e.g. Failed) it’s sufficient to follow 3 links

  1. Create a Log Analytics workspace if it doesn’t exist yet.
  2. Enable diagnostic logs for the Azure automation account, if it is not enabled yet.
  3. Create a metric alert based on runbook completion status.

Possible statuses are listed in Job statuses.

If you want to have more complex query, follow instructions from “Query the logs” section of “Forward Azure Automation diagnostic logs to Azure Monitor” article

In your Automation account, under Monitoring, select Logs. Under All Queries, select Automation Jobs.

Michael Freidgeim
  • 26,542
  • 16
  • 152
  • 170