Setting up the LHM check Azure function
Create a Function App by
...
going to the
...
Azure Portal, searching for “Function Apps” and clicking Create. Follow the rest of the wizard and make sure you create the Application Insights for the Function App as well (this will be needed in the alert creation stage later).
Create the system assigned managed identity for your Function App by going to your Function app’s Identity section and setting the Status from Off to On. You need this in order for the script to pull the client secret from the KeyVault.
...
Copy the Object ID from the identity page and go to your KeyVaults Access policies. Here you will create a new policy which will grant List and Get rights for Secrets for the Function Apps Identity (search for it by using it’s object ID.
Next you will be creating the local function project. This part of the process
...
takes place in your terminal.
Make sure the pre-requisites are
...
fulfilled. The following command creates the local project:
Code Block |
---|
func init <PROJECT NAME> --python # give it your function app name
cd <PROJECT NAME> |
...
# the func init creates this folder |
After going into the function folder you will pull the necessary files for the monitoring function and unzip it in the current folder:
Code Block |
---|
wget <URL TBD> unzip -j bplm-check.zip |
The core files unarchived above is being defined by the following 4 files:
Code Block |
---|
bplm-check/bplmcheck.py bplm-check/.env bplm-check/__init__.py requirements.txt |
The other files in the archive are azure provided files which contain metadata pertaining to the monitor. They are:
Code Block |
---|
bplm-check/function.json
bplm-check/host.json
bplm-check/readme.md |
Note: the function is based on the TimeTrigger template and is configured to run every 30 mins. The cron expression can be found inside this file
Code Block |
---|
bplm-check/function.json |
Your current function folder should contain the following:
Code Block |
---|
.gitignore
.vscode
bplm-check
getting_started.md
host.json
local.settings.json
requirements.txt |
Note: the bplm-check
directory contains the files outlined above.
At this point, you can publish the function to the Function App you’ve created above by issuing:
Code Block |
---|
func azure functionapp publish <FUNCTION APP NAME> -b remote |
Checking the Azure Function App at this point should show you the function you’ve just published.
...
Test it out by clicking on it, going to
Code + Test
and hit theTest/Run
button. If you are not seeing the output in the console of this page, you can go to theMonitor
page to see the logs. Successful runs look like this.
...
Note: These log messages get publish to the Application Insights that’s tide to the Function App, which is where we’re setting up the alert based on the ERROR message count in these logs.
Setting up the alert
With the information successfully being sent to Azure, you can now set up an Alert.
...