Receive Alerts in Your On-Premise System Using Java Web Tomcat 9
Configure a connection with an on-premise system to receive alert notifications locally. For example, extend your on-premise application in the corporate network to show alerts for critical or warning metrics of an SAP BTP application in the Neo environment or to take self-healing actions. Furthermore, use the Alerting Channels REST API to configure the channel for receiving such alert notifications.
Overview
You will learn
- How to connect with an on-premise system so that your alerts will be processed locally
Prerequisites
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 9) 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
jrefolder 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.
Steps
Intro
This tutorial describes the configuration with a Java Web Tomcat 9 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.
Download the project as a ZIP file from https://github.com/SAP/cloud-sample-webhooks and extract the files into a local folder.
Open the Command prompt and go to the project's local folder cloud-sample-webhooks-main.
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.
Deploy the file on Java Web Tomcat 9 runtime and then start the application. For more information, see Deploying Applications.
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.
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.
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:
{
"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_URLwith the webhook application URL. You can find it in the SAP BTP cockpit when you select the deployed webhook application.Replace
registered_client_IDandregistered_client_secretwith 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_URLwith 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.
Select the application in the SAP BTP cockpit, choose the Update button, and enter the verification token as a JVM argument (-DverificationToken=<verification_token>).

Finally, restart the application for your change to take effect.
Use Java Web Tomcat 9 server and deploy the WAR file locally. See Deploy Locally with the Console Client.
- 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 .
- 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`.

Log on to the SAP BTP cockpit.
Select the subaccount.
Go to Connectivity > Destinations.
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` |
|Authentication|`NoAuthentication` |
For more information, see [Configure the Destination in the Cloud](https://help.sap.com/viewer/b865ed651e414196b39f8922db2122c7/Cloud/en-US/e76f9e75bb571014a7218bcd30a8771b.html#loioe76f9e75bb571014a7218bcd30a8771b__configure_destination_cloud).
> The virtual host and port are configured in the cloud connector under **Cloud To On-Premise** > **Access Control** > **Mapping Virtual to Internal System**.
- Check that the connection to the on-premise destination is successful.
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).
Resources
Discussion
Share feedback on this tutorial or join the conversation in SAP Community.