skip to Main Content

I have an azure function that checks if a blob file exists or not. This function returns true or false, and I want to send an alert if the outout is false. (This function is in python)

3

Answers


  1. Given that you haven’t provided any sample code, the first thing you should look at is the developer reference to ensure your logs are being created correctly:

    https://learn.microsoft.com/en-us/azure/azure-functions/functions-reference-python?tabs=asgi%2Cazurecli-linux%2Capplication-level#logging

    I’d recommend you look at the Monitor Azure Functions page and ensure you have Application Insights enabled.

    https://learn.microsoft.com/en-us/azure/azure-functions/functions-monitoring

    Then you can use the following guide on how to query and analyse the App Insights data:

    https://learn.microsoft.com/en-us/azure/azure-functions/analyze-telemetry-data

    You may have to timeslice or aggregate the data for failures in x number of minutes.

    Login or Signup to reply.
  2. You could add mail functionality to the function itself, using the MS Graph API. The function would need Mail.Send permission. For sending email from a Python function you could look at this resource.

    If you need to send the email outwith Azure, just invoke the HTTP function via its URL, check the output and send the email if required. You could make the function return some JSON for example:

    {
      "result": true
    }
    
    Login or Signup to reply.
  3. Created a function in python, if any blob doesn’t exist in container, then it will send a mail through Microsoft graph API.

    Python Function

    import logging
    import json
    import msal
    from azure.storage.blob import BlobClient
    
    import azure.functions as func
    def main(req: func.HttpRequest) -> func.HttpResponse:
    logging.info('function processed a request.')
    connection_string = "DefaultEndpointsProtocol=https;AccountName=functionblob28789;AccountKey=xxxxxx.windows.net"
    
    container_name = "images"
    blob = BlobClient.from_connection_string(conn_str=connection_string, container_name=container_name)
    files = blob.GetBlobsAsync()
    condition = false
    if files = ! null
    condition = true
    else
    // Send a mail using Microsoft graph API.
    
    print(condition)
    

    In else part you can send a mail by using Microsoft Graph API.

    Refer the following documentation for sending an email via Microsoft Graph API by Raymond.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search