Azure Function App with PowerShell — Periodically Get Azure Service Health Events

  • Az PowerShell/CLI
  • REST API
  • Other programming languages

Prerequisite Actions

  1. Create an Azure Function App by following the steps mentioned here. Please ensure to use “PowerShell” as your runtime stack
  2. Configure the environment to have Az.ResourceGraph PowerShell module installed. The reason for installed Az.ResourceGraph module is that we are leveraging Azure Resource Graph API to query the needed information. If you would like to know more how this is done, please check this site. The same could also be accomplished via REST API.
- Remove the last line of ‘Az.*’ = ‘5.*’
- Replace it with 'Az.ResourceGraph' = '0.8.0' #The latest version
#The content should look like below
# This file enables modules to be automatically managed by the Functions service.
# See https://aka.ms/functionsmanageddependency for additional information.
#
@{
# For latest supported version, go to 'https://www.powershellgallery.com/packages/Az'.
# To use the Az module in your function app, please uncomment the line below.
'Az.ResourceGraph' = '0.8.0'
}

Demonstration

# Input bindings are passed in via param block.
param($Timer)
# Get the current universal time in the default string format.
$currentUTCtime = (Get-Date).ToUniversalTime()
# The 'IsPastDue' property is 'true' when the current function invocation is later than scheduled.if ($Timer.IsPastDue)
{
Write-Host "PowerShell timer is running late!"
}
# Write an information log with the current time.
Write-Host "PowerShell timer trigger function ran! TIME: $currentUTCtime"
#Write the installed module "Az.ResourceGraph"
Get-Module -Name Az.ResourceGraph | Write-Output
#Write to host of the queries Azure service health events
Search-AzGraph -Query "servicehealthresources | where type == 'microsoft.resourcehealth/events' | project subscriptionId, Status=properties.Status, TrackingId=properties.TrackingId, EventType=properties.EventType, Title=properties.Title" | Write-Output

--

--

--

Learning new things about Kubernetes every day. Hopefully, the learning notes could help people on the same journey!

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

How I learned to stop worrying and love Git

Six of my Favourite HashiCorp Packer Tricks

Qiskit-Optimization module Internals -Part 2

Clean Code

Top Cloud Tech Startups

Deep Dive Into Containerization In Relation To HPC

ToDo App In Django Part 1: Django Installation And Setup | CodeSnail

TornadoFX: Multithreading with EventBus

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Jonathan

Jonathan

Learning new things about Kubernetes every day. Hopefully, the learning notes could help people on the same journey!

More from Medium

Using SignalR with Azure Functions and Event Hubs

Batch Message Handling in Azure function

Secure your Environment Variable inside Azure Function using Key Vault.

Build 22 — Hybrid Announcements