This topic describes how to view OceanBase Cloud Platform (OCP) alerts on your alert platform.
Background
You must call APIs to query OCP alerts on your alert platform. For more information, see Query the alert event list.
Scenario 1: View real-time alerts
The following sample code shows how to view real-time OCP alerts. You can call the corresponding API on a regular basis to query the alert event list and learn of the alert objects in real time.
Sample code
curl 'http://OCP-IP:8080/api/v2/alarm/alarms?isSubscribedByMe=false&status=Active&page=1&size=10' \
--user username:password \
--compressed \
--insecure
The data.page.totalPages field indicates the total pages of real-time alerts. You can view the alerts on a specific page. For example, you can set the page field to 2 and view the alerts on Page 2:
curl 'http://OCP-IP:8080/api/v2/alarm/alarms?isSubscribedByMe=false&status=Active&page=2&size=10' \
--user username:password \
--compressed \
--insecure
Key fields
| Field | Description |
|---|---|
| alarmType | The name of the alert rule. |
| activeAt | The time when the alert was triggered, in Greenwich Mean Time (GMT). You need to convert it to the local time before use. |
| updatedAt | The time when the alert was updated, in GMT. You need to convert it to the local time before use. |
| target | The alert object, such as a tenant of a cluster. |
| description | The description of the alert. |
| summary | The summary of the alert. |
| level | The alert level. |
| labels | Other information, such as the cluster (obregion or ob_cluster in previous versions), tenant (tenant_name), or host IP address (svr_ip). A labels field suffixed with _1, _2, or _3 is in non-standard format. We recommend that you use this format only when necessary. This field is not used in later versions of OCP. For more information about supported labels, see Examples of alert channel configuration. |
Scenario 2: Connect to your alert platform
Based on the sample code in Scenario 1, you can call the corresponding API on a regular basis to query the alert event list and update the status of the alert object (target).
The following information is updated:
The last alert time. You can calculate the duration of an alert based on the time when the alert was triggered.
The alert status. If the alert of a target is not returned for each batch, the alert is set to the cleared state. When you query multiple pages, alerts on these pages are returned in a batch.
The number of alerts of each alert level in the Alerting state in real time.
Scenario 3: Verify alert availability
To prevent hidden dangers due to alert unavailability, you can trigger an alert on a regular basis based on the following sample code to verify the alert trace availability.
Sample code
You can trigger a log alert. For example, you can write the following ERROR log to the runtime log of an OBServer:
echo '[2035-01-02 15:04:05.666666] ERROR [CLOG] update_free_quota (ob_log_file_pool.cpp:413) [1994][2072][Y0-0000000000000000] [lt=19] [dc=0] test ob error for ocp alarm, just ignore. ret=-999999' >> /home/admin/oceanbase/log/observer.log.wfRun the following command to call the API and verify the log alert:
Set the keyword in the request to the log content.
If the alert is displayed on your alert platform, the alert trace is working.