Skip to content

Create Security Detection Rule



POST /api/v1/security_rule/add

Overview

Creates a security rule that is initially disabled. Supports AI semantic security rules.

Before Calling and Usage Steps

Create a security detection rule in the current workspace. New rules are initially disabled. Before enabling an AI rule, verify the query capabilities, scheduling configuration, and alert policies. If a write request times out, first check the existing rules and scheduling status, and retry only after confirming the result.

Regular rules (siem, cspm, aba) specify their schedule through jsonScript.every or jsonScript.customCrontab. every uses a duration string with an s, m, or h unit, for example 5m. interval is required, in seconds, ranging from 1–2592000. checkerOpt.status is required for regular rules; set it to critical, high, medium, low, or info. Set checkerOpt.script to the detection script for the target rule type. If jsonScript.type is explicitly submitted, it must match the type of the regular rule.

The top-level type of an AI rule is ai_monitor. If jsonScript.type is submitted, set it to aiMonitor. For AI rules, every is required (1–59 minutes, 1–24 hours, or 1d, for example 1h), as are interval (a positive integer number of seconds) and checkerOpt.userPrompt (non-empty, up to 20000 characters).

Request Headers

Parameter Type Required Description
DF-API-KEY string Y OpenAPI Key of the target workspace. Obtain it from API Key Management in the workspace.

Body Request Parameters

Parameter Type Required Description
name string Y Security detection rule name.
Allow null: False
Allow empty string: False
Maximum length: 128
Example: 登录检测
How to obtain or enter: Enter the display name of the security detection rule in the target workspace.
type string Y Rule type. Required for creation. When editing, if provided, it must match the original type.
Allow null: False
Allowed values: ['siem', 'cspm', 'aba', 'ai_monitor']
Example: ai_monitor
How to obtain or enter: Select the rule type that matches the detection method from the allowed values. When modifying, enter the existing type.
desc string Rule description. If omitted during editing, the original value is retained.
Allow null: False
Maximum length: 4096
Example: 检测异常登录
How to obtain or enter: Enter the rule's purpose or monitoring scope.
jsonScript json Y Required object. Populate scheduling and checkerOpt according to the AI or regular rule type; see the usage instructions above.
Allow null: False
Example: {"every":"1h","interval":3600,"checkerOpt":{"userPrompt":"检查异常登录"}}
How to obtain or enter: Enter the complete configuration according to the detection type. The example is an AI rule. When editing, first read the rule details.
alertPolicyUUIDs array Associated alert policy UUIDs. If omitted during editing, they are retained; an empty array clears them.
Allow null: False
Example: ["altpl_example"]
How to obtain or enter: Obtain the UUIDs of valid alert policies in the current workspace from the alert policy list.
alertPolicyUUIDs[*] string Allow null: False
Allow empty string: False
Example: altpl_example
How to obtain or enter: Enter the UUID of a single valid alert policy.
tags array Tag names. If omitted during editing, they are retained; an empty array clears them.
Allow null: False
Example: ["env:production"]
How to obtain or enter: Enter the names of the tags to associate.
tags[*] string Allow null: False
Allow empty string: False
Example: env:production
How to obtain or enter: Enter the name of one tag to associate.

Request Example

AI rule

curl --request POST 'https://openapi.guance.com/api/v1/security_rule/add' \
  -H 'DF-API-KEY: <DF-API-KEY>' \
  -H 'Content-Type: application/json' \
  --data-raw '{"name": "登录检测", "type": "ai_monitor", "jsonScript": {"every": "1h", "interval": 3600, "checkerOpt": {"userPrompt": "检查异常登录"}}}'

Regular rule

The following uses SIEM as an example. When creating CSPM or ABA rules, select the corresponding top-level type and use the actual detection script for that type. return [] is an example that produces no detection events.

curl --request POST 'https://openapi.guance.com/api/v1/security_rule/add' \
  -H 'DF-API-KEY: <DF-API-KEY>' \
  -H 'Content-Type: application/json' \
  --data-raw '{"name":"常规安全规则示例","type":"siem","jsonScript":{"every":"5m","interval":300,"checkerOpt":{"status":"high","script":"return []"}}}'

Response

HTTP 200, application/json.

Field Type Description
content.uuid string Security rule UUID.
content.name string Rule name.
content.type string Rule type.
content.status integer Rule status, 0 enabled, 2 disabled.
content.updateAt integer Update time, in Unix seconds. May be -1 if not updated.
content.declaration object Public declaration of the current workspace.
{
    "code": 200,
    "content": {
        "uuid": "srul_example",
        "name": "登录检测",
        "type": "ai_monitor",
        "status": 2,
        "updateAt": -1,
        "declaration": {}
    },
    "errorCode": "",
    "message": "",
    "success": true,
    "traceId": "TRACE-EXAMPLE"
}

Error Responses

For authentication, rate limiting, and common request errors, see common error definitions.

HTTP Status errorCode Trigger Condition Message or Response Description Resolution
406 ft.ParameterValidationFailed / ft.InvalidParameter Missing field, or type or configuration does not meet requirements Invalid parameter Check the fields and values against the request parameter table.
406 ft.MissingCheckFreqFixedCrontab A regular rule does not specify every or customCrontab Missing schedule Specify a run interval or Cron expression.
406 ft.InvalidInterval The interval of a regular rule is outside the allowed range Invalid query time range Use an integer between 1 and 2592000 seconds.
406 ft.InvalidSecurityCheckerOptStatus The checkerOpt.status of a regular rule is missing or outside the allowed range Invalid severity level Use the severity levels listed on this page.
403 ft.Forbidden The API Key lacks API permissions, or it does not have permission to operate the current AI rule Access forbidden Confirm the Key's workspace, permissions, and target rule.
400 ft.UnsupportFreeWorkspaceSecurityCfg The current workspace version does not support security configuration Version not supported Confirm the target workspace version.
403 ft.ForbiddenFreeEditionLimit The site has enabled a creation quota and the limit has been reached Quota exceeded Check the number of existing rules and the site quota.
400 ft.InvalidAlertPolicyUUID The alert policy is invalid or does not belong to the current workspace Invalid alert policy Obtain a valid alert policy UUID again.
400 ft.FiledCreateTrigger Failed to create the schedule Failed to create trigger configuration Check the schedule and current rule status before retrying.

Feedback

Is this page helpful?