Skip to content

Modify Security Detection Rule



POST /api/v1/security_rule/{rule_uuid}/modify

Overview

Modify an existing security rule that you have permission to operate on, while retaining its original type and enabled/disabled status.

Before Calling and Usage Steps

Obtain the rule UUID from content.data[].uuid in the Security Detection Rule List. Modification requires permission on the rule object. If type is omitted, the current value is retained; if submitted, it must match the existing type. If desc, tags, or alertPolicyUUIDs is omitted, the current value is retained; passing an empty array for the latter two clears them. If a write request times out, first verify the existing rule and scheduling status, and retry only after confirming the result.

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

AI rules have a top-level type of ai_monitor. If jsonScript.type is submitted, set it to aiMonitor. AI rules must specify every (1–59 minutes, 1–24 hours, or 1d, for example 1h), interval (a positive integer in seconds), and checkerOpt.userPrompt (non-empty, up to 20,000 characters).

Path Parameters

Parameter Type Required Description
rule_uuid string Y Security Detection Rule UUID.
Allows null: False
Allows empty string: False
Example: srul_example
How to obtain or enter: Obtain from content.data[].uuid in the Security Detection Rule List.

Request Headers

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

Body Request Parameters

Parameter Type Required Description
name string Y Security Detection Rule name.
Allows null: False
Allows 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 Rule type. Required for creation; when editing, if provided, it must match the original type.
Allows null: False
Optional 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 optional values. When modifying, enter it according to the existing type.
desc string Rule description. When editing, omit it to retain the original value.
Allows null: False
Maximum length: 4096
Example: 检测异常登录
How to obtain or enter: Enter the rule purpose or monitoring scope.
jsonScript json Y Required object. Fill in the schedule and checkerOpt according to the AI or regular rule type; see the usage instructions above.
Allows 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 for an AI rule; when editing, read the Rule Details first.
alertPolicyUUIDs array Associated Alert Policy UUIDs. When editing, omit to retain; an empty array clears them.
Allows null: False
Example: ["altpl_example"]
How to obtain or enter: Obtain valid policy UUIDs in the current workspace from the Alert Policy List.
alertPolicyUUIDs[*] string Allows null: False
Allows empty string: False
Example: altpl_example
How to obtain or enter: Enter the UUID of a single valid alert policy.
tags array Tag names. When editing, omit to retain; an empty array clears them.
Allows null: False
Example: ["env:production"]
How to obtain or enter: Enter the tag names to associate.
tags[*] string Allows null: False
Allows empty string: False
Example: env:production
How to obtain or enter: Enter a tag name to associate.

Request Example

AI Rule

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

Regular Rule

The following uses an existing SIEM rule for demonstration. First confirm the rule type from the details, retain the existing type, and enter the detection script according to the modification objective. return [] is an example that produces no detection events.

curl --request POST 'https://openapi.truewatch.com/api/v1/security_rule/srul_example/modify' \
  -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 for the current workspace.
{
    "code": 200,
    "content": {
        "uuid": "srul_example",
        "name": "登录检测",
        "type": "ai_monitor",
        "status": 2,
        "updateAt": 1795737600,
        "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 Handling Method
406 ft.ParameterValidationFailed / ft.InvalidParameter Field missing, or type or configuration does not meet requirements Invalid parameter Check the fields and values according to the request parameter table.
406 ft.MissingCheckFreqFixedCrontab Regular rule does not specify every or customCrontab Missing run schedule Specify a run period or Cron expression.
406 ft.InvalidInterval The interval of the regular rule is out of the allowed range Invalid query time range Use an integer from 1 to 2592000 seconds.
406 ft.InvalidSecurityCheckerOptStatus The checkerOpt.status of the 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 permission, or has no operation permission for the current AI rule Forbidden Confirm the Key's workspace, permissions, and target rule.
400 ft.UnsupportFreeWorkspaceSecurityCfg The current workspace version does not support security configuration Unsupported version Confirm the target workspace version.
404 ft.ObjectNotExists The rule does not exist, has been deleted, or does not belong to the current workspace Rule does not exist Obtain the UUID again from the rule list in the current workspace.
403 ft.ForbiddenCspmOperation / ft.ForbiddenSiemOperation / ft.ForbiddenAbaOperation The caller does not have operation permission for the corresponding category of security rules Rule operation denied Check the permissions for the corresponding rule category.
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.OuterFuncFailed AI schedule update, enable/disable, or cleanup is unconfirmed External function call failed Check the current rule and scheduling state by traceId, then decide whether to retry.