Creating and subscribing to APIM Publisher alerts via Jaggery API calls in WSO2-APIM-Analytics-2.6.0

Umesha Guruge
4 min readMar 14, 2021

--

If you are familiar with the WSO2 APIM and APIM Analytics products, you know that they offer a range of API related alerts for their customers. These alerts can be configured via the Publisher portal or the Store portal. And this is normally done by logging into the Publisher or the Store web applications.

But today I’m gonna tell you how we can do this by just using Jaggery APIs, instead of logging into the web applications. This tip will come in handy if you need to automate the alert creation and subscription. 😃

Before moving further let me tell you where you can find more information regarding WSO2-APIM Analytics alerts and basics regarding the Jaggery APIs. You can visit the following official WSO2 documentation and get a better understanding.

Now let’s get back to our alert creation process. In this blog, I will tell you how to configure the Publisher alerts using the Jaggery APIs. So there are three types of publisher portal alerts namely,

  • Abnormal Response Time alert
  • Abnormal Backend Time alert
  • Health Availability alert

While we can directly subscribe to mail addresses for any API’s health monitoring alert, we need to configure the response and backend threshold time per API for abnormal response time alert and abnormal backend time alert.

Following are the API calls we used to create and subscribe to the publisher alerts.

First, we have to log in to the API Publisher web application using the below call.

curl -X POST -c cookies http://localhost:9763/publisher/site/blocks/user/login/ajax/login.jag -d 'action=login&username=admin&password=admin'

Please make sure to change the username and password values accordingly before executing the curl command.

Upon success, we will receive the response as below.

{"error" : false}

Once logged in successfully, run the following command to create/configure the abnormal response time alert for a particular API.

Make sure to change the following values accordingly.

  • apiCreator
  • apiName
  • apiVersion
  • threshold ( abnormal response time threshold value)
Curl -X POST -b cookies http://localhost:9763/publisher/site/blocks/configure-alert/ajax/configure-alert.jag -d 'action=configureAlert&apiCreator=admin&apiName=testapi&apiVersion=v1&alertType=AbnormalResponseTime&threshold=12' -k -v

Upon success, we will receive the response as below.

{"error" : false, "list" : {"records" : []}}

Use the following command to create/configure the backend time alert for a particular API.

Make sure to change the following values accordingly.

  • apiCreator
  • apiName
  • apiVersion
  • threshold ( abnormal backend time threshold value)
Curl -X POST -b cookies http://localhost:9763/publisher/site/blocks/configure-alert/ajax/configure-alert.jag -d 'action=configureAlert&apiCreator=admin&apiName=testapi&apiVersion=v1&alertType=AbnormalBackendTime&threshold=456'-k -v

Upon success, we will receive the response as below.

{"error" : false, "list" : {"records" : []}}

Now that we have created both alerts. The next step would be adding email addresses to the receive email alert notifications for all three alert types abnormal response time alert, abnormal backend time alert and health availability alert (As I have mentioned above we can directly subscribe to the health availability alert as it is already created and receive the health status for all the APIs).

Now let’s subscribe to them by running the below command. Please make sure to add the email list accordingly. Please note that the ‘%40’ is for URL encoded @ sign in test123@gmail.com (test123%40gmail.com). And we can add several mail addresses separated by the %2C. In the given sample we have added two mail addresses.

Curl -X POST -b cookies http://localhost:9763/publisher/site/blocks/manage-alerts/ajax/manage-alerts.jag -d 'action=saveAlertTypes&checkedList=1%2C2%2C7&emailList=test123%40gmail.com%2Cerenjaeger%gmail.com&checkedValues=AbnormalResponseTime%2CAbnormalBackendTime%2CApiHealthMonitor' -k -v

Observe that we have all three alert names under the checkedValues parameter in the above curl command, which means we are subscribing email users for all three alerts.

And now that we are done with creating and subscribing to publisher portal alerts. If we need we can check and verify whether this is implemented as expected by logging into the publisher web application because the changes we have done via the API calls will be reflected in the publisher portal. (https://<host-name>:9443/publisher)

Let’ check and verify our changes in the publisher portal:

Abnormal Response Time alert configuration
Abnormal Backend Time alert configuration
Subscribing to all three publisher portal alerts

After verifying these changes in the UI we can simulate an alert generation use-case by using our APIs and test whether the email alerts are received as expected.

[1]. https://docs.wso2.com/display/AM260/Publisher+APIs

[2]. https://docs.wso2.com/display/AM260/Store+APIs

Until Next time

--

--