Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
dzhurdzhina
Advisor
Advisor
Imagine the scenario where you have an application deployed on SAP Cloud Platform but you are also using a Function App (or any other resource) on Microsoft AzureIs there a common way to receive alerts if something goes wrong for both the environments – SAP Cloud Platform as well as Microsoft Azure? Already yes and it is called SAP Cloud Platform Alert Notification. For the sake of simplicity we will call it only Alert Notification. 

Throughout this blog post, we'll explore a scenario for multi-cloud solution that includes an application running in SAP Cloud Platform. It communicates to a function app living in Microsoft Azure. Following the best practices – the one raises alerts for problems by Alert Notification, the other one – by Azure Monitor. Both "speaking" different languages. In the next 15 minutes we will unify those languages as Azure Monitor and Alert Notification are now integrated. Together, we'll walk through the integration setup and we'll receive an alert from our function app as an email sent by Alert Notification.

Note: The email could be replaced by any other delivery channel in the Alert Notification portfolio. We'll use this one due to its straightforward configuration.



 

Before starting, we have a couple of prerequisites: 


Set up Alert Notification






This step includes both getting credentials for posting events to Alert Notification as well as instructioning the service what to do when events from Azure Monitor arrive. Let's start:

0. Instantiate Alert Notification, if you haven’t done so : )


  1. WIthin your Alert Notification instance view in the SAP Cloud Cockpit, create a technical client with BASIC authentication mechanism and ALERT_WRITE permission:






  1. Once created, you will be provided with client id and client secret – make sure to save them in a secure place, so that we could make use of them later.

  2. In the Export or Import menu, paste the following configuration in the Import text field and click Import:

    Note: Make sure to replace the email address placeholder with one you have access to.
    {
    "conditions": [
    {
    "name": "AnyAzureMonitorAlert",
    "propertyKey": "eventType",
    "predicate": "CONTAINS",
    "propertyValue": "AzureMonitorAlert"
    }
    ],
    "actions": [
    {
    "name": "NotifyMeByEmail",
    "state": "ENABLED",
    "destination": "<your_email@he.re>",
    "useHtml": false,
    "type": "EMAIL"
    }
    ],
    "subscriptions": [
    {
    "name": "azure-monitor-events",
    "conditions": [
    "AnyAzureMonitorAlert"
    ],
    "actions": [
    "NotifyMeByEmail"
    ],
    "state": "ENABLED"
    }
    ]
    }​


  3. Within several seconds, you'll receive an email containing a confirmation code as well as a confirmation link. Make sure to confirm you email action either using the link or the confirmation code in the SAP Cloud Cockpit.


You could later fine-tune the imported configuration to best match you needs. Playing around with conditions and combining them to subscriptions, you could achieve different granularity levels.

Set up a Function App






To fulfill our scenario, we'll create a demo function app that we will connect to Azure Monitor in the next section. Of course, if you already have an existing solution that you could connect to Azure Monitor, you could safely skip this step. But note that if you decide to do so, you'll need to adapt accordingly the rules provided in the next section as well as you should simulate alerts on your own.

Let's start creating the Function app:

  1. From the Azure portal menu or the Home page, select Create a resource

  2. In the New page, select Compute > Function App

  3. Fill in the required fields – you could replicate the example values that we've used for the demo:

  4. In the newly created function app, select Functions, and then select + Add

  5. Choose function type HTTP trigger

  6. In your function, select Code + Test and copy-paste the following snippet:
    exports = async function (context, req) {
    const isErrorRequest = (req.query.isError || (req.body && req.body.isError));


    if (isErrorRequest) {
    throw new Error("This is a simulated error in order to trigger Azure Monitor alert");
    }


    res = {
    // status: 200, /* Defaults to 200 */
    body: "Phew, no error was thrown this time"
    };
    }​


  7. Test the function by clicking on Run. You should see something like this:




 

Set up Azure Monitor






It's time to configure the actual monitoring and alerting. If you've decided to skip the previous section, you'll need to adapt some of the steps below according to your own solution.

Let's do it:

  1. In the Azure portal search box, enter logic apps, and select Logic Apps

  2. On the Logic Apps page, select Add

  3. Populate the required fields – you could use the example values that we've provided for the demo:

  4. Once deployment completes, select Go to resource

  5. From Development Tools section, select Logic app designer, then When a HTTP request is received

  6. Copy-Paste the following snippet in Request Body JSON Schema:
    {
    "type": "object",
    "properties": {
    "schemaId": {
    "type": "string"
    },
    "data": {
    "type": "object",
    "properties": {
    "essentials": {
    "type": "object",
    "properties": {
    "alertId": {
    "type": "string"
    },
    "alertRule": {
    "type": "string"
    },
    "severity": {
    "type": "string"
    },
    "signalType": {
    "type": "string"
    },
    "monitorCondition": {
    "type": "string"
    },
    "monitoringService": {
    "type": "string"
    },
    "alertTargetIDs": {
    "type": "array",
    "items": {
    "type": "string"
    }
    },
    "originAlertId": {
    "type": "string"
    },
    "firedDateTime": {
    "type": "string"
    },
    "resolvedDateTime": {
    "type": "string"
    },
    "description": {
    "type": "string"
    },
    "essentialsVersion": {
    "type": "string"
    },
    "alertContextVersion": {
    "type": "string"
    }
    }
    },
    "alertContext": {
    "type": "object",
    "properties": {}
    }
    }
    }
    }
    }​


  7. Select New Step, then HTTP

  8. Populate the required fields:


  9. Save the logic app

  10. From your Resource group view, in the Monitoring section select Alerts,then Manage actions, then Add action group

  11. Populate the required fields in the Basics tab – you could use the example values that we've used for the demo:

  12. In the Actions tab, select the previously created logic app

  13. Make sure to Enable the common alert schema

  14. Once done with the action group, go back to the Alert view and select New alert rule

  15. In the Create alert rule view:

    • as a target resource, select the previously created function app;

    • create a condition to match Whenever the count exceptions count is greater than 1 count

    • assign the previously created action group




 

Execute the scenario






Let's now flood our function up with errors, so that Azure Monitor will detect its troubles. You should make use of your preferred API client to execute 2-3 times POST requests against it. In the demo here, we'll use Postman:

  • get your function app URL by navigating to its page, then Code + Test, then select Get Function URL and copy it;

  • paste it as an URL in you API client;

  • use the following payload as a body:
    {
    "isError": true
    }



Within a couple of minutes, you'll receive an email like this:



 

For further information about the integration scenario between Azure Monitor and SAP Cloud Platform Alert Notification, check the SAP Help Portal page.




This blog post is part of a series of blog posts related to integration between third-party monitoring tools and SAP Cloud Platform Alert Notification service. We will continuously add newly released integrations to the series, so stay tuned!

We ask you – our customers and partners – to join us in our integration journey! Tell us what you use for monitoring solutions, what you need to integrate with them; tell us your experience, and what your alerting needs are!