How to monitor for newly created Azure Subscriptions? - azure

I want to monitor for newly created Azure Subscriptions. Ideally, I would like to subscribe to events at the management group level and ingest them on event grid. What would be the best way to accomplish this?
On my research there is no native way for event grid to subscribe to events on the Management Group or Tenant Level.

As you mentioned, there is no native way to add an event grid at management group level.
However, you can use a polling technique (Azure TimerTrigger Function) with a REST GET request to obtain a list of all subscriptions, comparing to previously state and publishing its diference to the AEG custom topic.

Related

Is it possible to detect an table/queue/fileShare creation with eventGrid?

In the MS documentation, at the resources of EventGrid Azure Blob Storage as event sources. There is nothing about table/queue/fileShare creations.
I saw also custom events in EventGrid, so i wondered if it is possible to use table/queue/fileShare creations as custom events. If yes, how?
Unfortunately, there is no direct way you can pass events like table/queue/fileshare creation to Event grid. Event grid supports mostly blob actions like what is listed HERE.
As a work around, you can look at is using alerts. Click on "Alerts" under the Monitoring tab on the left pane of your storage account. There are different types of actions available by which you can pass the administrative events to Azure functions, logic apps or webhooks. If you really need the events in Event grid, you can use logic apps/functions to pass those events/alerts to Event grid.
You may need to do some more filtering before doing this though to get exactly what you want. Else you may end up getting all the admin activities which I don't think you would need.
For example, what I setup below alerted me on creation and deletion of queues(among other things). I would also get alerts for List of storage keys and other admin activities.

Is there a way to trigger a Logic App on a deletion of a record in an Azure SQL table?

Is there a way to trigger a Logic App on a deletion of a record in an Azure SQL table?
I've checked the SQL Connector and there is only When an item is created and When an item is modified, which gives me the C and U in CRUD, but sadly there isn't an out-of-the-box trigger for the D.
I can think of some awful way of polling to get record deletions, but I'm hoping that there is a cleaner solution that some bright person has come up with, however I've had no joy with the Google searching.
I would look at the Azure Event Grid. Azure Event Grid allows you to easily build applications with event-based architectures. First, select the Azure resource you would like to subscribe to, and then give the event handler or WebHook endpoint to send the event to. Event Grid has built-in support for events coming from Azure services, like storage blobs and resource groups. Event Grid also has support for your own events, using custom topics.
I would suggest monitoring the resource group and triggering it off the deletion from the RG. There is a tutorial that shows this same concept with a VM but you should be able to modify it to meet your needs with an Azure SQL DB.
https://learn.microsoft.com/en-us/azure/event-grid/monitor-virtual-machine-changes-event-grid-logic-app
I added an on delete trigger which adds the id of the deleted record to a secondary table. I have the logic app look for modifications on the secondary table.

Is it possible to receive an event when a new resource is created

I would like to run some automation to take some actions whenever a new resource is created in One of my subscriptions in Azure. Is this possible?
You can use Azure Event grid for this, a solution that is built for exactly this purpose. Taken from https://learn.microsoft.com/en-us/azure/event-grid/overview
Azure Event Grid allows you to easily build applications with event-based architectures. You select the Azure resource you would like to subscribe to, and give the event handler or WebHook endpoint to send the event to. Event Grid has built-in support for events coming from Azure services, like storage blobs and resource groups.
You basically create a subscription to a certain event (such as specific resources being created) that can then be picked up by a webhook, or processed by Azure Automation or Azure Functions

Multiple EventTypes in Azure EventGrid Topic

What is the best practices around Azure EventGrid topics and Events?
Is it a bad idea to publish different event-types to the same Azure EventGrid topic?
e.g. multiple different domain events
When do we need different topics?
A single shared Topic for an entire application?
One Topic per Aggregate Root type?
One Topic per Event Type?
Any suggestions would be welcome as there are no clear answers
Part2.
What if I want to integrate with various Azure Logic Apps?
if multiple logic apps react to the same topic, would they steal messages from each-other?
Do each logic app create some invisible subscription?
No, it is not a bad idea to publish different event-types to the same Azure EventGrid topic: if the events are related to the same resource, it does make sense to publish them to the same EventGrid topic. Taking the example of a HR application, you can have EmployeeAdded and EmployeeRemoved events published on the same "employee" topic.
On the question on when different topics would be needed, I think it depends on a few factors such as how you are modelling the resources in your application, the events of interest on those resources, security model around which parts of the system should be able to publish to the topic / creation of event subscriptions on the topic. Ideally, all types of events for the same resource type (such as the "employee" resource type in the example above) can be on the same topic. When your system has more types of resources, you may want to create separate topics for each of them. Also, the desired security model has to be taken into account as well (e.g. let's say you want to restrict access to who can receive certain types of events).
Regarding the question about logic apps, if you create multiple logic apps that handle events from the same topic, each of them creates an event subscription on the same topic, and Event Grid would deliver the events on that topic to each of the event subscriptions. So, each logic app would receive the same event individually, and can process it independent of the other apps.
The Azure Event Grid (AEG) is not a generic Pub/Sub model. This model is based on the source of the events, where each event source (topicType) is handling own interest.
Subscriber subscribes an interest to the event source (topic) using a subscription. Note, that the AEG allows to subscribe only one topic in the subscription. There is a limit 500 subscriptions per topic.
In other words, if there is a multiple interest for event source (topic) by the same subscriber, this model requires to create a multiple subscriptions (one per topic) per subscriber. The filtering of the interest is possible only within the same topic.
The source of events in the AEG can be extended by custom topics (maximum 100 per Azure Subscription).
Based on the above, I do recommend for custom topics use the same model like is built-in for azure event sources (topicTypes) with a multiple eventTypes, which can be simplified a continuously deployment over environments.
To the Part2: The AEG doesn't use an 'invisible' subscription as a part of the integration. Every subscription created to the topic is visible and accessable, for example using a REST API
Update:
Azure Event Grid recently release (in preview - version 2018-09-15-preview) a new feature which can be helped for your solution using an Event Domain and Domain Topics, more details here.
You can use an updated tool Azure Event Grid Tester for testing all new preview release features, which they are not yet implemented in the Azure portal UI.

How to get Azure Webapp start/stop events to Azure Functions

I have a requirement when webapp is started or stoped my azure function should be called. I have gone through Azure Grid Events, using Subscription as Resource Group but it does not capture any event on WebApp. So Azure Function is not called.
Is it possible to achieve this using Event Grid? I dont want to create use Custom Events.
Is it possible to achieve this using Event Grid? I dont want to create use Custom Events.
In short answer, it is not possbile to do that currenctly. We could get more information about Event grid from this tutorial.
Currently, the following Azure services support sending events to Event Grid:
Azure Subscriptions (management operations)
Custom Topics
Event Hubs
IoT Hub
Resource Groups (management operations)
Service Bus
Storage Blob
Storage General-purpose v2 (GPv2)
Note: It supports part of the region currently.
As Thomas mentioned that you could try to application insights paired with availability monitoring alert.

Resources