百度智能云

All Product Document

          Cloud Monitor

          Alarm callback

          Function overview

          Alarm callbacks enable BCM alarm notifications to be sent to a specified URL. You can process various alarm messages freely and flexibly. BCM supports pushing messages to a publicly accessible URL via POST requests using the HTTP/HTTPS protocol, allowing further processing of alarm information pushed through the callback API. To receive alarm notifications through office tools like WeCom, DingTalk, Infoflow, Zhiyinlou, Feishu, or Knock, please refer to the webhook usage instructions.

          Instructions for use of alarm callback

          • Alarm callback API: You need to provide a publicly accessible URL address capable of receiving POST requests through the HTTP/HTTPS protocol as the callback address.
          • Alarm callback triggering: If an alarm callback address is provided, the triggering logic is the same as for alarms sent via SMS, email, and phone calls. When an alarm strategy is triggered or resolved, alarm messages will be sent via the callback API.
          • Binding the alarm callback API: You can add a callback API when creating an alarm strategy. Each alarm strategy can only be bound to one alarm callback URL.
          • Response content: After sending alarm information to the bound URL, we need to receive a response content (httpCode = 200) indicating successful receipt; otherwise, we will resend the alarm information three times at most, with a timeout duration of 5 s (retry mechanism)

          Operation steps

          Below is example of cloud product monitor, there are three entries for alarm callback function:

          • Entry I: Entry for uniformly creating alarm strategy
          1. In the left navigation bar, click Alarm Management, then Alarm Strategy, and under the cloud product monitor strategy list, click Add Strategy.

          image.png

          1. On the Create Strategy page, activate the alarm callback and input a publicly accessible URL.

          image.png

          • Entry II: Entry for creating an alarm strategy for a single instance under a cloud service
          1. Go to Cloud Product Monitor, then click on Instance Monitor in the left-hand menu to open the Instance List page. To access Baidu Cloud Compute (BCC) monitoring data, click on Baidu Cloud Compute Monitor to navigate to the Baidu Cloud Compute List page. From there, choose and click the relevant instance to proceed to the Alarm Strategy page.

          image.png

          1. In the instance Alarm Strategy page, click Add Strategy

          image.png

          1. On the Create Strategy page, activate the alarm callback and input a publicly accessible URL.

          image.png

          • Entry III: Entry for creating an alarm notification template
          1. In the left-hand menu, select Alarm Management and then Alarm Template. Click on Add Template under the Alarm Action List page.

          image.png

          1. In the Add Notification Template page, input a publicly accessible URL into the API callback field.

          image.png

          Notes Alarm notification templates support adding multiple callback addresses (5 at most).

          Instructions for use of webhook

          • WeCom
          1. Log in to WeCom, open the designated WeCom group that will receive alarm notifications.
          2. After adding a group bot, copy the webhook address and paste it into Alarm Callback as instructed in the steps above.
          3. Once successfully configured, any triggered alarm notification will be sent to the WeCom group.
          • DingTalk
          1. Log in to DingTalk, open the DingTalk group designated to receive alarm notifications, and add a group bot.
          2. Complete the form, select the Custom Keywords option in the Security Settings section, and it is recommended to set Alarm as the keyword.

          Note: Check the custom keywords box, enter up to 10 keywords, and ensure each message contains at least one keyword for successful delivery. For instance, if Alarm is set as a custom keyword, messages sent by the bot must include the word Alarm to guarantee successful delivery.

          1. After adding a DingTalk bot, copy the webhook address and input it into Alarm Callback by following the stated steps.
          2. Once configured successfully, any triggered alarm notification will be delivered to the DingTalk group.
          • Infoflow
          1. Log in to Infoflow, open the Infoflow group designated to receive alarm notifications.
          2. After adding an Infoflow bot, copy the webhook address and paste it into Alarm Callback following the provided steps.
          3. Once successfully configured, any triggered alarm notification will be sent to the Infoflow group.
          • Zhiyinlou
          1. Log in to Zhiyinlou, open the Zhiyinlou group that will receive alarm notifications.
          2. Complete the form, select the Custom Keywords option in the Security Settings section, and it is recommended to set Alarm as the keyword.

          Note: Check the custom keywords box, enter up to 10 keywords, and ensure each message contains at least one keyword for successful delivery. For instance, if Alarm is set as a custom keyword, messages sent by the bot must include the word Alarm to guarantee successful delivery.

          1. After adding an Infoflow bot, copy the webhook address and paste it into Alarm Callback following the provided steps.
          2. Once successfully configured, any triggered alarm notification will be sent to the Infoflow group.
          • Feishu
          1. Log in to Feishu, open the Feishu group that will receive alarm notifications.
          2. After adding an Infoflow bot, copy the webhook address and paste it into Alarm Callback following the provided steps.
          3. Once successfully configured, any triggered alarm notification will be sent to the Infoflow group.
          • Knock
          1. Log in to Knock, open the Knock group that will receive alarm notifications.
          2. After adding an Infoflow bot, copy the webhook address and paste it into Alarm Callback following the provided steps.
          3. Once successfully configured, any triggered alarm notification will be sent to the Infoflow group.

          POST method parameter description

          Metric alarm POST method parameter description

          Parameters Description
          alertId Alarm ID
          userId Account ID
          alarmName Alarm strategy name
          scope Cloud product name
          policyType Strategy type (Either metric alarm or event alarm, where Metric represents metric alarms and Event represents event alarms)
          alertStartTimestamp Alarm timestamp
          region Region where the alarm object is located
          monitoringObject Alarm object
          alarmLevel Alarm level status. Based on actual conditions, return one of the four statuses: critical, notification, important, or warning.
          formula Alarm conditions
          currentValue Current value of the metric when an alarm occurs or is restored
          taskTimestamp Alarm callback sending time
          signature Signature
          alarmStatus Alarm status: One of four statuses - alarm - abnormal, alarm - repeated notification, alarm - insufficient data, or alarm - closed (return to normal)

          Event alarm POST method parameter description

          Parameters Description
          alarmName Alarm strategy name
          scope Cloud product name
          alertStartTimestamp Alarm timestamp
          alertContent Event Details
          taskTimestamp Alarm callback sending time
          signature Signature

          The signature value is verified by ensuring it matches the MD5 hash of the concatenated string comprising the alertId and taskTimestamp parameters.

          URL callback example

          Below is an example of URL callback usage, where BCM initiates a POST-style URL callback request:

          POST http://127.0.0.1:8201/callback
           Request Body (“Content-Type”: “application/json”):
          {
           “alarmStatus”: “alarm - abnormal”,
              "alertId":"19925050-3f77-4839-bae7-6a5f721aae0c",
              "userId":"your_user_id",
              "alarmName":"test_bcc_alarm",
              "scope":"BCE_BCC",
              "policyType":"Metric",
              "alertStartTimestamp":1698982559,
           “region”: “Beijing”,
           “monitoringObject”: “i-6nfua8xc/bcc-test-bj/-(Public)/192.168.16.12(Private)”,
           “alarmLevel”: “Important”,
           “Formula”: “CPU average usage >1% within 1 minute”,
           “currentValue”: “CPU usage=0.50%”,
              "taskTimestamp":1698982642,
              "signature":"88e647b853e480046632a5eb9fef70f5"
          }

          In callback.java, receive POST parameters and validate messages:

          // Parse 3 parameters - alertId, taskTimestamp, and signature from the received POST requests. The message can be verified using the MD5 hash value generated by concatenating the three parameter strings alertId and taskTimestamp.
           If the verification is successful, it indicates that the message is sent by Baidu AI Cloud; otherwise, it is regarded as an illegal request and will not be processed. The taskTimestamp can be used for expiration validation. If the time interval between the Timestamp and the user’s current time exceeds a certain period (e.g., 10 minutes), the user may discard the request.
          if (md5(alertId + taskTimestamp) == signature) {
              ..........
          }
          Previous
          Alarm Template
          Next
          Alarm Notification Template