Start Now

Create Alert Configurations For YugabyteDB Anywhere Using APIs

Kapil Maheshwari

YugabyteDB Anywhere can monitor system health, and if a problem arises, it can automatically issue an alert notification. These alerts can be created from the YugabyteDB Anywhere UI or using APIs designed specifically for the DB Anywhere product.

Scripting the alert creation and management using APIs is extremely helpful if you need to create a new universe or migrate a platform.

Instructions to Create an Alert Configuration

So now, let’s walk through how to create an alert configuration using APIs for YugabyteDB Anywhere.

First, let’s review the high-level steps:

  1. Retrieve Customer UUID
  2. Validate the notification channel
  3. Validate the alert destinations
  4. Define the alert policies
  5. Test the alert policy

Step 1: Retrieve Customer UUID

Customer UUID (cUUID) is the unique UUID of the platform and can be retrieved using the following API request.

curl -H \ 
  "X-AUTH-YW-API-TOKEN: <<API Token>>" \
  http://<<IP_Address_Platform>>/api/customers

Successful Output:

[{ 
  "uuid": "3a69de7a-f74e-4124-adcd-de19484006da", 
  "code": "dev", 
  "name": "kapil", 
  "creationDate": "2022-08-04T07:56:23+0000", 
  "features": {}, 
  "universeUUIDs": [ 
    "7e848e2a-f7e1-47bc-8517-ec4a64b4e285" 
  ], 
  "customerId": 1 
}]%

Here, “3a69de7a-f74e-4124-adcd-de19484006da” is the Customer UUID (cUUID).

Step 2: Validate the Notification Channel

A notification channel designates how an alert is sent (ex: email, webhooks, chat, etc.) and who should receive the notification. In this case, we’ve already set up a default notification channel set and we will use the default destination to send the alert notification.

Following the API request will help to get the details about the default notification channel. Explore the syntax of the alert channel API here.

curl --request GET \
  --url \ http://<<IP_Address_Platform>>/api/v1/customers/3a69de7a-f74e-4124-adcd-de19484006da/alert_channels \
  --header 'Content-Type: application/json' \
  --header 'X-AUTH-YW-API-TOKEN: <<API Token>>'

Make a note of “uuid” (4d5f4e58-41fd-42e7-8741-77efb6577d4c) in the output. We will call it Notification Channel UUID for later reference.

Successful Output:

[{
  "uuid": "4d5f4e58-41fd-42e7-8741-77efb6577d4c",
  "name": "Default Channel",
  "params": {
    "channelType": "Email",
    "defaultRecipients": true,
    "defaultSmtpSettings": true
  },
  "customer_uuid": "3a69de7a-f74e-4124-adcd-de19484006da"
}]%

Step 3: Validate the Alert Destinations

A destination consists of one or more channels. It sends the related data to the designated destination whenever an alert is triggered. So now, let’s verify that the default destination is set for the platform using the  alert_destinations API.

curl --request GET \
  --url http://<<IP_Address_Platform>>/api/v1/customers/3a69de7a-f74e-4124-adcd-de19484006da/alert_destinations \
  --header 'Content-Type: application/json' \
  --header 'X-AUTH-YW-API-TOKEN: <<API Token>>'

Here, “176d882e-fd0d-4a6f-8f54-fbbfa8994f5d” is the alert destination UUID, and defaultDestination is set to true.

Successful Output:

[{
  "uuid": "176d882e-fd0d-4a6f-8f54-fbbfa8994f5d",
  "customerUUID": "3a69de7a-f74e-4124-adcd-de19484006da",
  "name": "Default Destination",
  "channels": [
    "4d5f4e58-41fd-42e7-8741-77efb6577d4c"
  ],
  "defaultDestination": true
}]%

Step 4: Define the alert policies

In this section, we will create an alert policy.

We will use the “alert_configuration” API to create an alert policy using the template “DB_COMPACTION_OVERLOAD” for all universes.

From the API description:
“targetType” can be a universe or platform.
“Target” defines the scope. If we set “targetType” to “UNIVERSE”, we have an option to specify a unique universe in this section.

curl --request POST \
  --url http://<<IP_Address_Platform>>/api/v1/customers/3a69de7a-f74e-4124-adcd-de19484006da/alert_configurations \
  --header 'Content-Type: application/json' \
  --header 'X-AUTH-YW-API-TOKEN: <<API Token>>' \
  --data '{
    "active": true,
    "defaultDestination": true,
    "description": "string 4",
    "name": "custom string 4",
    "targetType": "UNIVERSE",
    "target": {
      "all": true
    },
    "thresholds": {
      "SEVERE": {
        "condition": "GREATER_THAN",
  	"threshold": 0.0
      }
    },
    "template": "DB_COMPACTION_OVERLOAD",
    "thresholdUnit":"COUNT",
    "customerUUID":"3a69de7a-f74e-4124-adcd-de19484006da"
  }'

Note: If we want to create an alert for a specific universe, we have to change the “target” section to include a Universe UUID:

"target": {
  "all": false,
  "uuids": [
    "7e848e2a-f7e1-47bc-8517-ec4a64b4e285"
  ]
},

Sample output of Successful Alert policy creation:

{
  "uuid": "ec904a04-d49c-4b6f-a1a3-dcf5046404b4",
  "customerUUID": "3a69de7a-f74e-4124-adcd-de19484006da",
  "name": "custom string 4",
  "description": "string 4",
  "createTime": "2022-09-01 10:03:55",
  "targetType": "UNIVERSE",
  "target": {
    "all": true
  },
  "thresholds": {
    "SEVERE": {
      "condition": "GREATER_THAN",
      "threshold": 0.0
    }
  },
  "thresholdUnit": "COUNT",
  "template": "DB_COMPACTION_OVERLOAD",
  "durationSec": 0,
  "active": true,
  "defaultDestination": true
}

From the above output, we have “ec904a04-d49c-4b6f-a1a3-dcf5046404b4” as configuration UUID.

Step 5: Test the Alert Policies

Using the test_alert, we can test our newly-created policy.

Here, “ec904a04-d49c-4b6f-a1a3-dcf5046404b4” is the alert configuration UUID created in the last step.

curl --request POST \
  --url http://<<IP_Address_Platform>>/api/v1/customers/3a69de7a-f74e-4124-adcd-de19484006da/alert_configurations/ec904a04-d49c-4b6f-a1a3-dcf5046404b4/test_alert \
  --header 'Content-Type: application/json' \
  --header 'X-AUTH-YW-API-TOKEN: <<API Token>>' \
  --data '{
    "cUUID":"3a69de7a-f74e-4124-adcd-de19484006da",
    "configurationUUID":"ec904a04-d49c-4b6f-a1a3-dcf5046404b4"
  }'

Successful Output:

{
  "success":true,
  "message":"Result: Default Channel - Alert sent successfully"
}%

Conclusion:

In this blog, we have successfully created and tested an alert configuration using the APIs for YugabyteDB Anywhere.

Visit our Docs site to read more about alerts and YugabyteDB Anywhere APIs.

Related Posts

Kapil Maheshwari

Related Posts

Get started in any cloud, container or data center