Following on from my earlier post “Monitor Azure events with Logic Apps” I’ll now show how to add additional control within the Logic App to only alert on events related to virtual machine changes and how to surface additional event information in the email.
Firstly edit the Logic App in the designer and click the + between the event and email steps and choose Add an action.
From the Choose an action screen select Control.
Select Condition.
Click into the “Choose a value” box, select Expression and enter triggerBody()?[‘data’][‘operationName’] and click ok.
In the next box select “is equal to” and in the value box enter Microsoft.Compute/virtualMachine.
Drag the “Send an email” action into the “If true” box.
These changes ensure the Logic App will only send an email for operations related to virtual machines.
If you would like to include additional event information in the email beyond those in the Dynamic content selection it’s easy to achieve. From the Logic App page click on runs history. Click on “When a resource event occurs” and you can see the JSON on the event. Click “Show raw outputs” to see the full JSON generated by the event.
You can include values from the JSON in the email using the expression box. Go back to the “Send an email” action and click on the email body. In the Expression box enter the path to the JSON value, e.g. triggerBody()?[‘data’][‘operationName’] to include the operation name or triggerBody()[‘data’][‘claims’][‘http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name’%5D to include the name of the user that carried out the action.