Search code examples
pythonazureazure-functionsazure-alerts

How to consume Azure Alert payload to HTTP trigger azure function


I am trying to consume the payload that azure alert is sending while calling an Azure function.

def main(req: func.HttpRequest) -> func.HttpResponse:
    logging.info('Python HTTP trigger function processed a request.')
    req_body = req.get_json()
    print(req_body)

but not getting anything in req_body variable. Anyone on how to consume it in python azure function.


Solution

  • If you want to use azure alert to trigger Azure Function, please refer to the following steps

    1. Create Azure Function. My code is as below
    def main(req: func.HttpRequest) -> func.HttpResponse:
        logging.info('Python HTTP trigger function processed a request.')
    
      
        req_body = req.get_json()
        logging.info(req_body)
        return func.HttpResponse(
                 "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.",
                 status_code=200
        )
    
    1. Create alert

      a. Define condition

      b. Define action group enter image description here

    2. Test enter image description here