Skip to content

Create Monitor



POST /api/v1/checker/add

Overview

Create a monitor in the specified workspace, or create multiple monitors from a template.

Prerequisites and Usage Steps

Use site-level External API write permission. Obtain the workspace UUID from the workspace list. Exactly one of config or templateUUID. For standard configuration, config.jsonScript must be an object, and you must fill in the query conditions required by that type; when the top-level name is omitted, it is taken from jsonScript.title or jsonScript.name. Obtain the template UUID from the template list, filter by type=monitor; the rules come from meta.main.checkers. A multi-rule template must not be passed a top-level name; the name can be at most 256 characters.

HTTP 200 may also indicate partial success. Check the per-rule results in content.rules[].status, and verify the existing rules in the target workspace. When the scheduling or submission result is unknown, first verify by rule name and the returned UUIDs. If rules created from the original template still exist in the target workspace, replaying the same templateUUID directly returns HTTP 409 during the name check. After confirming the missing items, create them with a single-rule config or a template containing only the rules to be added. For combined rules, also verify the dependencies, use the actual UUIDs of the created rules, or include the dependencies that still need to be created in the same supplementary template.

In standard configuration, config.alertPolicyUUIDs is deduplicated and saved in order of first occurrence. For the template method, alert policies are processed in the order of first occurrence of each rule's alertPolicyNames. If a group or policy with the same name already exists in the target workspace, it is reused; if it is missing, it is created and submitted along with the corresponding rule. tagInfo[].name in the template can be used to create and associate tags in the target workspace. When dashboardName is specified, it is associated with the unique valid standard dashboard of the same name in the same workspace. If there is no match or multiple items with the same name exist, the precheck returns HTTP 400 ft.InvalidParameter.

Request Headers

Parameter Name Type Required Description
X-Df-SVersion string Signature version. The examples in this document use v20240417.
X-Df-Access-Key string Y Request AK information
Example: <external-access-key>
How to obtain or fill: Obtain the External API Access Key from the target site administrator.
X-Df-Signature string Y Signature information
Example: <computed-signature>
How to obtain or fill: Compute it using the actual method, request URL, and raw request body according to External API Signature Authentication.
X-Df-Timestamp string Y Signature timestamp
Example: 1785427200
How to obtain or fill: Generate the current Unix seconds string before sending, computing it with the actual time each time.
X-Df-Nonce string Y Request nonce
Example: b3b3564d4bb34c16be011e0cb85357c1
How to obtain or fill: Generate a new random string for each request, and use the same value to compute the signature.
Content-Type string Y Request body type, use application/json.

Body Request Parameters

Parameter Name Type Required Description
workspaceUUID string Y Target workspace UUID
Allowed empty string: False
Example: wksp_example
How to obtain or fill: Take content.data[].uuid from the workspace list.
config json Creation configuration, mutually exclusive with templateUUID.
Example: Refer to the jsonScript and monitor configuration in the request example of Create Monitor OpenAPI.
How to obtain or fill: Fill in config.jsonScript according to the monitor type. The top-level name is placed outside config. Omit this field when using a template.
templateUUID string Management console template UUID, mutually exclusive with config
Allowed empty string: False
Example: itgr_monitor_example
How to obtain or fill: Take content.data[].uuid of the type=monitor entry in the template list.
name string Resource name; when omitted, it is read from the configuration or template
Allowed empty string: False
Example: Production Service Availability
How to obtain or fill: Fill in the display name of the new monitor.

Request Example

import hashlib
import hmac
import json
import time
import uuid
from urllib.parse import urlencode
from urllib.request import Request, urlopen
from urllib.error import HTTPError, URLError

# Replace with the target site address and the External API AK/SK assigned by the administrator.
server = "https://external-api.guance.com"
access_key = "<external-access-key>"
secret_key = "<external-secret-key>"
method = 'POST'
path = '/api/v1/checker/add'
query = {}
data = {'workspaceUUID': 'wksp_example', 'templateUUID': 'itgr_monitor_example'}
full_path = path + ("?" + urlencode(query) if query else "")
body = "" if data is None else json.dumps(data, ensure_ascii=False, separators=(",", ":"))
timestamp = str(int(time.time()))
nonce = uuid.uuid4().hex
string_to_sign = " ".join([method, nonce, full_path, timestamp, body])
signature = hmac.new(secret_key.encode("utf-8"), string_to_sign.encode("utf-8"), hashlib.sha256).hexdigest()
headers = {
    "X-Df-Access-Key": access_key,
    "X-Df-Timestamp": timestamp,
    "X-Df-Nonce": nonce,
    "X-Df-Signature": signature,
    "X-Df-SVersion": "v20240417",
}
if data is not None:
    headers["Content-Type"] = "application/json"
request = Request(server + full_path, data=None if data is None else body.encode("utf-8"), headers=headers, method=method)
try:
    with urlopen(request, timeout=30) as result:
        payload = json.loads(result.read().decode("utf-8"))
except HTTPError as error:
    print("HTTP", error.code, error.read().decode("utf-8"))  # Handle by errorCode, content, and traceId; do not output AK/SK.
    raise SystemExit(1)
except (URLError, TimeoutError):
    print('Request result unknown. First verify the current state of the target and whether it has already been written, then decide whether to sign again and retry; do not automatically repeat write requests.')
    raise SystemExit(1)
print(json.dumps(payload, ensure_ascii=False, indent=2))

Response

HTTP 200, application/json.

Field Type Description
content.workspaceUUID string Target workspace UUID.
content.templateUUID string Returned when a template is used.
content.status string succeeded or partial_success.
content.createdCount integer Number of rules created.
content.failedCount integer Number of rules that explicitly failed.
content.rules[] object Per-rule results, including index, name, and status. Created rules are created and return ruleUUID; explicit failures are failed and return errorCode and message; unconfirmed results are unknown; not yet executed is not_attempted.
{
  "code": 200,
  "content": {
    "workspaceUUID": "wksp_example",
    "templateUUID": "itgr_monitor_example",
    "createdCount": 1,
    "failedCount": 0,
    "rules": [
      {
        "index": 0,
        "name": "Business Availability",
        "status": "created",
        "ruleUUID": "rul_example"
      }
    ],
    "status": "succeeded"
  },
  "errorCode": "",
  "message": "",
  "success": true,
  "traceId": "TRACE-EXAMPLE"
}

Error Response

For authentication, rate limiting, and common request errors, see Common Error Definitions.

HTTP Status errorCode Trigger Condition Message or Response Description Handling
400 ft.RequestJsonFormatError The request body is not valid JSON The response may include content.reason/line/column Fix the JSON syntax.
400 ft.JsonFormatError The top level of the request body is not a JSON object JSON format error Submit a JSON object.
400 ft.InvalidParameter Required parameters are missing or unsupported fields are included Invalid parameter Verify the parameter positions and field descriptions.
403 ft.WorkspaceIsLocked / ft.Forbidden The workspace is locked or the current credential has no write permission Access forbidden Confirm the workspace status and the write permission of the site credential.
404 ft.WKSPNotExistOrReleased The target workspace does not exist or has been released Workspace unavailable Select a valid workspace from the site workspace list.
400 ft.InvalidParameter The template category does not match, or the template meta is missing or malformed Invalid parameter; the field is templateUUID Reselect a valid template according to the API requirements.
404 ft.NotFoundTemplateUUID The template does not exist or is not active Template not found Query a valid monitor template again.
409 ft.CheckerRepeatNames / ft.ObjectParmeterExists Duplicate monitor name or concurrent write lock conflict May include content.conflicts Verify the name and the created rules before proceeding.
409 ft.ForGroupNameRepeat When creating a monitor group from a template, the creation of a group with the same name is in progress On partial success, the error is reported for that entry through content.rules[].errorCode in the HTTP 200 response Confirm whether the group with the same name has been created, and create the pending rules according to the per-rule results.
406 ft.ParameterCheckFailed / ft.AuthorizationVerificationFailed The query configuration is invalid or authorization in the target workspace failed Unable to create rules Verify the rule query parameters and the corresponding authorization.
502 ft.FiledCreateTrigger No rule succeeded and scheduling explicitly rejected creation Failed to create trigger configuration Check the returned rule results and traceId.
500 ft.InternalServerError The scheduling, submission, or cleanup result is unknown content.status=unknown, stage=create_rule/commit/cleanup Rules already submitted are retained. First verify rules[] and the target workspace status, then create the missing items as described in the prerequisites.

Feedback

Is this page helpful?