Anyone can be a developer - logic apps from Azure

As we go further and further down the rabbit hole that is Azure it becomes more and more apparent how good the platform is. However logic apps takes that to a whole new level - anyone can develop useful code with this - it's amazing (and this is coming from a very cynical 20 year DBA veteran....).

To demonstrate this i am going to show a simple example of what it can do - in this sample i want to know anytime something happens in my Azure subscription and write an audit record of that - i.e. someone adds a VM or some PaaS resource i want to know when this was done (there are other ways to do the same thing but just bear with me for this example).

I pick this as a sample that happens to be an Azure based event - but it doesn't have to be - the thing can hook up to loads of other things.

So first things first - lets navigate to the logic apps section i the portal and click add:

Fill in some data - give it any old name you like set the subscription, the resource group and the location.

 Now its added OK

 Now we say the initial thing we want to trigger on - in my sample i choose event grid event for Azure - but there are loads - a few other shown in the screenshot below

Once i choose that it prompt me to login to Azure to select some settings

Now we have multiple tenants so we get a drop down - you may likely have just one. I click sign in then log in through the normal microsoft process (note there is a service principal option to use a dedicated account that way should you wish)

Once logged in i then click the continue button

Now i'm prompted for some values - which i just select from a drop down

I choose the relevant ones - in this case and 'subscription' level events.

And I'm done - that initial trigger captures any data broadcast from the Azure event system for the subscription I'm interested in - but so far does nothing with it - so lets change that and add a new step and click add action.

This time i choose SQL server and the insert row action

I get prompted again for connection information (if as in my case its Azure SQL i actually get a list to just choose from) - then i just enter username and password.

It then gives me a list of tables, i choose the 'auditlog' table i created - it then shows me all the columns in that table. I click into each one and I'm then presented with a list of the data objects returned from the previous step and i just click the one value i want which then becomes the column value inserted

(for reference this is the create table statement should you want it)

create TABLE auditlog (eventtype nvarchar(max),eventtime nvarchar(max),subject nvarchar(max), topic nvarchar(max),fulleventdata nvarchar(max))

This was all working great until i hit a little wrinkle with trying to insert the main data object from the previous step - it seems the fact that this is a complex json object is confusing the code (which is also defined in json format) - so i have to manually type the text into the code editor rather than using the designer - this is shown below - i think this is likely because this connector is a preview feature and still has a couple of 'features'. I simple do a concat of a null string at the beginning and end - this then seems to cast it as a string rather than a json object and all is well.

Once i do that and return to the main screen i see this in the designer - so it seems there should be some way of launching a function wizard here to do the same thing i did in the code editor - it just didn't seem to fire automatically for me.

Once that is done i can run it as a test by clicking the run button at the top of the screen - which gives me some nice debug and a green tick to say all is well.

I can then log into my Azure SQL DB and query the data back - using the SQL operation Studio - a nice event addition (for me at least as a mac user).

So there we have it - a fully functioning audit trail - with no code (well other than that little wrinkle with the SQL column) - I'm seriously impressed.

Anyone could do this - you could build an entire workflow/scheduling type tool this way - with multiple dependencies and parallel tasks etc. Fetch files from server x, process then and send the results to some web service then send a message to an MS teams channel or send an email.

The possibilities are endless!


Post a Comment