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: 
munishsuri
Participant
What is a consumption based model ? - With the consumption-based model, your organization purchases an entitlement to all current and future SAP BTP services that are eligible for this model. Throughout the duration of your contract, you have complete flexibility to turn services on and off and to switch between services as your business requires.

As customers receive monthly invoices, sometimes the over usage is being overlooked and it is reflected in the monthly bill.

Extending on the previous blog- Monitoring CPEA Cloud Credits for Business Technology Platform and Triggering Email Notifications

We are going to utilize the Usage Data Management Service of SAP BTP and analyst the monthly usage (Current month's usage) - as the previous months are covered by the invoices, so we are trying to trigger the alerts as close as to real time. The API used in this case is /monthlyUsage .

Use Case: Getting notified on the overuse of different services on the basis of the monthly thresholds defined by the consumer.

 

To achieve the above solution, we are going to deploy a Go lang based application to SAP BTP Cloud Foundry Runtime which is written in go lang, the application will be responsible to scrape the usage data from usage and data management service , the application will be matching the usage data and the threshold being defined by the user, if the usage being over utilized then an alert notification will be triggered which is intern going to send the email to the admin (configured in the alert notification service).

Link to the repository

 


 

Let's see at the components to be required to run this application.

Alert Notification - an instance of Alert notification  has to be created.post that you would be required to create a service key with the following parameters,
{
"type":"BASIC"
}

BASIC auth is being used for Alert notifications.


 

Now Copy the Values of Service Key , we will be needing it to configure the application afterwards.


 

Now navigate to the alert notification service instance and create an alert.

For that -> we will create a subscription first , provide the name and click on create


 

Once the subscription is there, we will bind it to the condition. for that click on create condition.


 

Create the condition , provide the condition name and enter the details of the condition.

We are using event type ,  and provide a condition name, note the condition name, this will be required to configure the application.


 

Now let's create an action to trigger an email.


 

provide the name of the action


Enter additional properties, with the email of the individual .


 

for template, use the following template
<!DOCTYPE html>
<html>
<body>
<h1>SAP Alert Notification service Email With HTML Payload Template Test</h1>
<p>Where: {resource.resourceName}</p>
<p>What: {subject}</p>
<p>Priority: {severity}</p>
<p>Details: {body}</p>
<p>Disclaimer: {ans-disclaimer}</p>
</body>
</html>

 

Once it is done, you will be receiving the Email from alert notification service to confirm the action.


 

Once this is done, you can edit the subscription and assign the action.


Now we will be requiring the credentials for Usage and Data management Service, hence create an instance for Usage and Data Management Service. Post creation of the service instance, create a service key and copy the credentials, this will be required to configure the application.


 

Now we have all the information we need to run the application.

We are going to operate the application in 2 modes :

For that we are going to configure the manifest.yaml file, which is the main deployment file.


Alert : <Alert_config>
Time : <Time_In_Minutes>
Event: <Event_type>
Services: <Services_Threshold>
Uas: <UAS_Services>
SubaccountMode: <true or false>




  1. Global Account Mode - in this scenario, you can define the service and plan threshold on the basis of global account.

  2. Sub Account Mode - in this scenario, you can define the thresholds and services on the basis of sub account.


Let's look at the configuration and it's difference.

 

Alert Variable - this information you will get from the service key mentioned above.
{
"Url":"<url_of_service>",
"Client_Id":"<client_id>",
"Client_Secret":"<client_secret>",

}

UAS Variable - this information you will get from the service key mentioned above.
{
"Url":"<target_url>",
"Client_Id":"<client_id>",
"Client_Secret":"<client_secret>",
"Token_Url":"<url>"

}

Time variable - this is the time, you want your application to check the APIs for usage data - it is configured in minutes e.g. - 10, this means your application will be running every 10 minutes to check the data.

Event variable - this is the event name that you configured above in the alert notification service - cpeaover

SubaccountMode: this is very important and will make the application run in that mode, if you set it true, this means you will be want your application to check for sub account, else for global account.

Services: this is where you define the services and their threshold values,

For SubaccountMode false the format looks like
{
"<Service_ID>":[{
"Metric":"<measureId>",
"PlanId":"<plan>",
"ThreholdValue":"<threshold>"
}]
}

example value

{
"CloudIntegration":[
{"Metric":"connections","ThreholdValue":100,"PlanId":"standard"},
{"Metric":"tenants","ThreholdValue":5,"PlanId":"standard"}
],
"sap-workzone":[
{"Metric":"swz_users","ThreholdValue":10,"PlanId":"standard"},
{"Metric":"swz_connections","ThreholdValue":10,"PlanId":"standard"}
]
}

 

For SubaccountMode false the format looks like

 
{
"<Service_ID>":[{
"Metric":"<measureId>",
"PlanId":"<plan>",
"ThreholdValue":"<threshold>",
"SubaccountId":"<subaccountId>"
}]
}

example values:

{
"CloudIntegration":[
{"Metric":"connections","ThreholdValue":100,"PlanId":"standard", "SubaccountId": "s1"},
{"Metric":"tenants","ThreholdValue":5,"PlanId":"standard","SubaccountId": "s2"}
],
"sap-workzone":[
{"Metric":"swz_users","ThreholdValue":10,"PlanId":"standard","SubaccountId": "s2"},
{"Metric":"swz_connections","ThreholdValue":10,"PlanId":"standard","SubaccountId": "s1"}
]
}

 

The values of Plan and Metrics can be taken from Usage analytics services,

sample attached


 

Once the varibales are configured properly,

The only thing you need to do is to deploy the application to the desired sub account and space and viola if you exceed the usage you are being notified.

 

8 Comments