Skip to Content

Receive Alerts in Your On-Premise System Using Java Web Tomcat 8

Requires Customer/Partner License
Configure a connection with an on-premise system to receive alert notifications locally.
You will learn
  • How to connect with an on-premise system so that your alerts will be processed locally
nikolasimeonov77Nikola SimeonovSeptember 15, 2022
Created by
nikolasimeonov77
September 17, 2018
Contributors
nikolasimeonov77
thecodester

Prerequisites

  • You have a productive global account and a subaccount.
    For more information, See Getting Started with a Customer Account in the Neo Environment.
  • You have active resources (applications) to receive alerts for.
  • You have installed Maven. See Welcome to Apache Maven.
  • You have installed SAP BTP SDK for the Neo environment (Java Web Tomcat 8) and set up the Console Client. See Setting Up the Development Environment.
  • You have Installed SAP JVM. See (Optional) Install SAP JVM.
  • You have configured the environment variables as you specify the JAVA HOME variable to the jre folder of the installed SAP JVM and the Path variable to the bin folder of the installed Apache Maven.
  • You have downloaded and initially configured the Cloud Connector.
    For this tutorial, you can use the portable version. For more information, see Cloud Connector.

This tutorial describes the configuration with a Java Web Tomcat 8 runtime. However, you can change these settings to match with your runtime environment.

To learn more about the whole scenario, read Receiving Alerts in the Corporate On-Premise System.

  • Step 1

    Download the project as a ZIP file from https://github.com/SAP/cloud-sample-webhooks and extract the files into a local folder.

  • Step 2

    Open the Command prompt and go to the project's local folder cloud-sample-webhooks-main.

  • Step 3

    Run the command mvn clean install to compile, test, and package the cloud-sample-webhooks-main project.

    You can now find your packaged webhooks.cloud.to.onpremise-1.0.0-SNAPSHOT.war file in the target folder.

    In the text area below, enter the command you used to compile, test, and package the cloud-sample-webhooks-main project.

  • Step 4

    Deploy the file on Java Web Tomcat 8 runtime and then start the application. For more information, see Deploying Applications.

  • Step 5

    The webhooks application is protected with OAuth. For more information, see Register an OAuth Client.

    You also need to select the Client Credentials authorization grant.

  • Step 6

    You need the access token to call the Alerting Channels REST API. For more information, see Using Platform APIs.

    Select Monitoring Service API and make sure that the Manage Alerting Channels scope is included.

    Which API name did you select for the platform API OAuth client?

  • Step 7

    Create a POST request with one of the following URIs:

    • Account level: https://api.{host}/alerting/v2/channels/accounts/{subaccountName}/types/webhook
    • Application level:
      https://api.{host}/alerting/v2/channels//accounts/{subaccountName}/apps/{appName}/types/webhook

    The application parameter in the URI is optional, and you do not specify it for alerts on account level.

    Use the following code in the body of the Alerting Channels REST call:

    JSON
    Copy
    {
                        "url": "application_URL/webhook",
                        "authentication": {
                            "authenticationType": "oauth2",
                            "client": "registered_client_ID",
                            "secret": "registered_client_secret",
                            "oAuthServerUrl": "token_endpoint_URL?grant_type=client_credentials"
                          }
    }
    
    • Replace application_URL with the webhook application URL. You can find it in the SAP BTP cockpit when you select the deployed webhook application.

    • Replace registered_client_ID and registered_client_secret with the client ID and secret created when registering the OAuth client for the webhook application.

      These are not the client ID and secret that you created for the platform API.

    • Replace token_endpoint_URL with the URL shown for the subaccount at Security > OAuth > Branding > Token Endpoint in the SAP BTP cockpit.

    Furthermore, use the access token as a bearer token in the Authorization for the REST API call.

    For more information, see Alerting Channels REST API.

  • Step 8

    Select the application in the SAP BTP cockpit, choose the Update button, and enter the verification token as a JVM argument (-DverificationToken=<verification_token>).

    JVM Argument View

    Finally, restart the application for your change to take effect.

    In the text area below, enter the text you inserted in the JVM Arguments field.

  • Step 9

    Use Java Web Tomcat 8 server and deploy the WAR file locally. See Deploy Locally with the Console Client.

  • Step 10
    1. Start the cloud connector.

      After you have configured the Cloud Connector as mentioned in Prerequisites, make sure that it connects to the internal system by using

      Check availability of internal host
      .

    2. Configure the access control.

      Go to the Cloud to On-Premise view and add the resource /webhooks.cloud.to.onpremise-1.0.0-SNAPSHOT/backend.

      Resource mapping

    In the text area below, enter the text you inserted in the URL Path field.

  • Step 11
    1. Log on to the SAP BTP cockpit.

    2. Select the subaccount.

    3. Go to Connectivity > Destinations.

    4. Create a new destination with the following values:

      Field Name Value
      Name on-premise-destination
      Type HTTP
      URL http://<virtual host>:<virtual port>/webhooks.cloud.to.onpremise-1.0.0-SNAPSHOT/backend
      Proxy Type OnPremise
      AuthenticationNoAuthentication

      For more information, see Configure the Destination in the Cloud.

      The virtual host and port are configured in the cloud connector under Cloud To On-Premise > Access Control > Mapping Virtual to Internal System.

    5. Check that the connection to the on-premise destination is successful.

    In the text area below, enter the name you used for the destination.

  • Step 12

    Trigger an alert by setting low threshold values (for example, Warning Threshold = 0.00001 and Critical Threshold = 0.0001 for the availability check of the application). You should receive the alert as an alert_<timestamp>.json file locally in the server’s workspace folder (usually in the …/webapps/webhooks.cloud.to.onpremise-1.0.0-SNAPSHOT folder).

Back to top