Skip to content
adatum
  • Home
  •  About adatum
  •  Learn Azure Bicep
  •  SCOM Web API
flight sky earth space Azure

Recording available: ARM template deployment scripts

  • 23/10/202007/01/2025
  • by Martin Ehrnst

Sign up for our next livestream; How to deploy resources using CI/CD

In our Infrastructure as code live stream series, Marcel Zehner and I covered a new feature in the Azure IAC space. Namely deployment scripts. With deployment scripts for Azure, you can run PowerShell or Bash (CLI) scripts within your ARM templates.

You may have heard of Custom script extension for Azure Windows VMs, this is sort of the same thing. Making you able to call external systems during deployment, or perform the last-mile configuration to your infrastructure.

Deployment scripts recording

You can find all our recordings on youtube and all code examples on github

Share this:

  • Share on LinkedIn (Opens in new window) LinkedIn
  • Share on X (Opens in new window) X
  • Share on Reddit (Opens in new window) Reddit
Conferences

IT Pro announcements from Microsoft Build

  • 20/05/202007/01/2025
  • by Martin Ehrnst

Microsoft Build is Microsoft prime developer conference, where Microsoft Ignite is the conference for your traditional IT pros. However, the traditional IT pro role has changed significantly in recent years, and Build is therefore interesting to us, and a lot of great “infrastructure” announcements were released at Build this year. Below I have picked out a few announcements I find most interesting.

Azure Resource Manager templates

ARM language improvements

Azure resource manager templates are very powerful. However, one of its Achilles heels is its verbosity. At build we got a small sneak peek on how Microsoft is looking in to improve ARM template language. Sign up here to get more information.

What-If analysis

I have deployed a lot of templates in recent years. And when I first saw a preview of the new what-if command I was thrilled. The ability to check what impact your template would make is a very important feature that is now available.

PowerShell or CLI inline in the templates

I’m not sure I like this one- the ability to actually write PowerShell or CLI scripts within ARM templates via Deployment Script is now in Public Preview.

ARM templates tend to be very complex already. And while this feature will solve a lot of issues, I am pretty sure we can manage to create a lot of new ones as well. I suggest a very humble approach to this feature.

Azure infrastructure

Azure Peering service generally available. Providing the fastest route from on-premises to your Azure resources. At first this looks like a new name for Express Route, but Azure Peering is not private. Instead it uses the largest ISPs around the world to quickly get you on Microsofts backbone.

Azure Arc enabled kubernetes

Azure Arc provides a range of capabilities for managing servers, Kubernetes, and Azure data services across clouds, datacenters, and edge locations.

Azure Arc was introduced at Microsoft Ignite in 2019. At build, Microsoft announced Arc for kubernetes in preview. With Arc for Kubernetes, we are able to use management tools in Azure like Azure policy and Azure monitor. For clusters running on-premises or in another cloud, public or private. For companies using for example RedHat OpenShift on-premises, and AKS in Azure. You can have a unified experience for both environments.

Read more about Azure Arc for kubernetes here

Azure Security and Azure AD

Azure AD now has a feature called ‘external identities’ in public preview. I’m not sure about all the news. But it seems to be a revamped Azure AD B2c. I will look more in to it later.

Azure Security Center is updated with a secure score API. To me this is great as integration to internal portals will be much easier. In other news, the ability to suppress alerts is now publicly available!

More Azure AD news can be found here

Build 2020 book of news

I will continue to update this list throughout Build and hopefully test drive some of the new features. In the meantime, you can find the complete list of Build 2020 announcements in the book of news

Share this:

  • Share on LinkedIn (Opens in new window) LinkedIn
  • Share on X (Opens in new window) X
  • Share on Reddit (Opens in new window) Reddit
Azure

Working with Azure Monitor Rest API

  • 29/02/202007/01/2025
  • by Martin Ehrnst

It might be an edge case, or you are creating your own integration. But chances are, after fiddling around with Azure Monitor, you encounter a situation where you would have work with its API.
Personally, I have numerous situations over the last years, that required me to integrate directly with Azure Management APIs

In this blog post, I will help you get started using the APIs, hopefully making it less intimidating. All code examples will use PowerShell.

Create SPN and assign it to your subscription RBAC

I am using a service principal in order to connect programmatically to Azure. SPNs are created in Azure Active Directory as Application Registrations. You can choose whether you want to do this via the portal, or by using PowerShell.

After creating (or using an existing SPN) grant the application appropriate access. For simplicity, I am using contributor to my subscription. That might be best for you as well, but one should always use the least privileged assignment needed.

Consider the above as a prerequisite for you to continue.

At this point, you should have an application registration, a secret, and a role assignment on your subscription. We can now use this to acquire an access token and connect to Azure Monitor’s REST API.

Connect to Azure Monitor API using PowerShell

Azure Monitor APIs are a part of the Azure Management APIs. I will, therefore, use these names interchangeably. Also keep in mind, that all other APIs under Azure Management will follow the same methods I demonstrate for Azure Monitor.

To query data we need to authenticate. In the example below, I am using client credentials to acquire the access token. Microsoft’s official example is using the ADAL method, connecting with your identity. I have never had the use for this, as I am usually writing integrations service-to-service.
If you are creating an interactive portal and want to leverage the user’s authorization, ADAL (or MSAL) are probably better.


Retrieve Azure Monitor alert rules

I have no idea why you are exploring Azure Monitors API. Providing an integration solution is therefore not possible. But my gut feeling is that alerts and metrics is a good place to start.

When working with alerts, we need to work with multiple endpoints. Depending on what you are working on, these are the most common;

  • Alert rules*
  • Alert incidents
  • Metric Alerts
  • Metric Alert status

We can start with one of the basics, retrieve the current configured alert rules. To do that, we need to know what kind it is. The classic alert rules (old type) use a single endpoint, while the current use it’s own.

Below I have included three endpoints and a screenshot. As you can see, all the information that you expect is to be found in the output. From here we can start to explore the alert rule by accessing its properties.

Azure monitor rest api metric alert rule output

Get resource metrics from Azure Monitors API

Metrics is another fundamental in monitoring. When we work with the API in the context of metrics. You can explore the available metrics for each resource type by using the Metric Definitions endpoint.

Actual metrics values require a bit more when it comes to the actual query. The official documentation describes everything pretty well, but I have provided an example for a VM below. This example shows the basics of how you get data from one metric and one VM. You can add multiple metrics to one query, and do additional filtering using the OData filter.


Manage alerts, updating status, etc.

Viewing configured alert rules, looking at disk metrics for a VM. What about alerts. The actual things that send you emails- can we work with them using this API? Yes, you can.

Like I said. Providing an integration solution in this blog post isn’t possible. but most integrations I have seen with Azure Monitor or other monitoring solutions have had some kind of functionality to handle active alerts. Personally, I have created one for SquaredUp earlier, where we could acknowledge alerts in Azure Monitor as well as our on-premises SCOM installation.

Before we wrap up. Let’s take a look at how we can interact with an active alert. I have configured a very naggy alert rule, creating a lot of noise, and I want to change the status of those alerts. Armed with PowerShell and the alerts management endpoints everything is possible.

Summary

This blog post has covered the basics regarding the Azure Monitor REST API and PowerShell. With the examples above and the official documentation, you can start creating your own solutions and integrations.

While we have only covered how to get data out of Azure Monitor, you should know it’s also possible to inject data. By using the HTTP data collector API and the Metric store possibilities are ‘endless’.

Integrations ideas

  • Alert remediation/handling from a ticketing system
  • Dashboarding with third-party or custom web integration
  • Teams/Slack/IM connector
  • Custom application metrics or logs

In my examples, I have purposely not included how new alert rules are created, as I believe this should be done through ARM. If that is your use case, you should know it is possible and fully supported.

This blog post was originally published in November 2017. Rewritten for Azure Spring Clean 2020 and to reflect changes to Azure Monitor API

Share this:

  • Share on LinkedIn (Opens in new window) LinkedIn
  • Share on X (Opens in new window) X
  • Share on Reddit (Opens in new window) Reddit

Posts pagination

1 2 3 4 … 6

Popular blog posts

  • Windows Admin Center with SquaredUp/SCOM
  • Sending SMS with Azure functions and Twilio
  • Hunting quick closing SCOM alerts
  • 2018 summary
  • Azure Application registrations, Enterprise Apps, and managed identities

Categories

Automation Azure Azure Active Directory Azure Bicep Azure DevOps Azure Functions Azure Lighthouse Azure Logic Apps Azure Monitor Azure Policy Community Conferences CSP Monitoring DevOps GitHub Guest blogs Infrastructure As Code Kubernetes Microsoft CSP MPAuthoring OMS Operations Manager Podcast Powershell Uncategorised Windows Admin Center Windows Server

Follow Martin Ehrnst

  • X
  • LinkedIn

RSS feed RSS - Posts

RSS feed RSS - Comments

Microsoft Azure MVP

Martin Ehrnst Microsoft Azure MVP
Adatum.no use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it. Cookie Policy
Theme by Colorlib Powered by WordPress