使用規則 API 管理統一定價規則
Rules API 提供程式輔助端點,可管理自訂和精選規則。本文說明如何使用 Rules API,以程式輔助方式管理自訂和精選規則。
您可以使用 Rules API 執行下列工作:
搜尋及列出規則:執行結構化搜尋、排序結果,以及擷取擴展規則資源。
查看精選規則詳細資料:擷取 Google 撰寫規則的唯讀中繼資料、套用的標記和原始文字邏輯。
批次修改規則設定:同步更新多項規則的即時狀態、警報狀態、封存狀態和標記指派。
使用清單規則搜尋規則
rules.list 方法支援擴充規則資源和結構化搜尋。
如要查詢這些詳細資源,請使用下列任一檢視畫面:
CONFIG_ONLYTRENDS
這兩種檢視畫面都會提供擴充資訊,包括:
規則部署資訊 (啟用即時規則、啟用快訊、封存狀態、執行狀態)
相關規則標記
在「
CONFIG_ONLY」檢視畫面中存取精選規則資源CONFIG_ONLY檢視畫面中,每頁最多可顯示 5,000 個結果強大的結構化搜尋功能。
使用 rules.list 要求的 order_by,依規則資源欄位排序搜尋結果。支援的規則欄位如下:
alerting_enabledarchivedauthorcreate_timedisplay_nameexecution_statelive_mode_enabledrevision_create_timerule_idrule_ownerseveritytypeupdate_time
要求範例:
HTTP
GET https://chronicle.googleapis.com/v1alpha/projects/<ID>/locations/us/instances/<ID>/rules?filter=archived%3Dfalse&pageSize=100&pageToken=&view=TRENDS
回應範例:
JSON
{
"rules": [
{
"name": "projects/11344677023/locations/eu/instances/e902a911-16e3-4c39-978d-e25234232492/rules/ru_fd3fe28c-2d7b-4f7e-9fca-4fdd6029d228",
"revisionId": "v_1719339990_701951000",
"displayName": "SomaMaglevProberRule",
"author": "test@google.com",
"metadata": {
"description": "enabled live rule used for maglev rules latency prober"
},
"createTime": "2024-06-25T18:26:30.701951Z",
"revisionCreateTime": "2024-06-25T18:26:30.701951Z",
"type": "SINGLE_EVENT",
"etag": "CNaX7LMGEJjY284C",
"nearRealTimeLiveRuleEligible": true,
"ruleOwner": "CUSTOMER",
"alertingEnabled": true,
"liveModeEnabled": true,
"runFrequency": "LIVE",
"currentDayDetectionCount": 10000,
"executionState": "DEFAULT"
},
{
"name": "projects/11344677023/locations/eu/instances/e902a911-16e3-4c39-978d-e25234232492/rules/ru_fbf56bf1-ea5f-4b5b-bbe9-e91e13f3b3b3",
"revisionId": "v_1696452642_197471000",
"displayName": "LoadTestingRule",
"author": "loadtesting@google.com",
"createTime": "2023-10-04T20:50:42.197471Z",
"revisionCreateTime": "2023-10-04T20:50:42.197471Z",
"type": "SINGLE_EVENT",
"etag": "CKKg96gGEJjWlF4=",
"nearRealTimeLiveRuleEligible": true,
"ruleOwner": "CUSTOMER",
"alertingEnabled": true,
"liveModeEnabled": true,
"runFrequency": "LIVE",
"executionState": "DEFAULT"
}
]
}
使用 getRule 和 listRules 查看精選規則詳細資料
rules.getRule 和 rule.listRules 支援擷取精選規則的詳細資料。
rule.listRules 回覆可以透過 rule_owner: "GOOGLE" 篩選器,只顯示精選規則。如要進一步瞭解如何使用 rule_owner 篩選器,請參閱規則搜尋語法一節。
以下是讀取精選規則的 listRules 要求範例:
HTTP
GET https://chronicle.googleapis.com/v1alpha/projects/<ID>/locations/us/instances/<ID>/rules?filter=rule_owner%3A%22GOOGLE%22pageSize=1&view=TRENDS
回應範例:
JSON
{
"rules": [
{
"name": "projects/<ID>/locations/us/instances/<ID>/rules/ur_e34bf150-6cfb-494c-ad9d-ec8f7216a03c",
"revisionId": "v_1755272664_971453000",
"displayName": "Example Curated Rule",
"severity": {
"displayName": "Info"
},
"metadata": {
"technique": "T1136.003",
"rule_name": "Example Curated Rule",
"description": "Example Curated Rule Description",
"tactic": "TA0003"
},
"createTime": "2024-10-02T18:10:43.647897Z",
"revisionCreateTime": "2025-08-15T15:44:24.971453Z",
"type": "SINGLE_EVENT",
"etag": "CNir/cQGEMjknM8D",
"nearRealTimeLiveRuleEligible": true,
"ruleOwner": "GOOGLE",
"tags": [
"google.mitre.tactic.ta0003",
"google.mitre.technique.t1136.003"
],
"executionState": "DEFAULT"
}
]
}
rule.getRule 方法支援使用資源名稱擷取精選規則。
以下是擷取精選規則的 getRule 要求範例:
HTTP
GET https://chronicle.googleapis.com/v1alpha/projects/<ID>/locations/us/instances/<ID>/rules/ur_e34bf150-6cfb-494c-ad9d-ec8f7216a03c?view=BASIC
回應範例:
JSON
{
"rules": [
{
"name": "projects/<ID>/locations/us/instances/<ID>/rules/ur_e34bf150-6cfb-494c-ad9d-ec8f7216a03c",
"revisionId": "v_1755272664_971453000",
"displayName": "Example Curated Rule",
"severity": {
"displayName": "Info"
},
"metadata": {
"technique": "T1136.003",
"rule_name": "Example Curated Rule",
"description": "Example curated rule description",
"tactic": "TA0003"
},
"createTime": "2024-10-02T18:10:43.647897Z",
"revisionCreateTime": "2025-08-15T15:44:24.971453Z",
"text": "Example curated rule text",
"type": "SINGLE_EVENT",
"etag": "CNir/cQGEMjknM8D",
"nearRealTimeLiveRuleEligible": true,
"ruleOwner": "GOOGLE",
"tags": [
"google.mitre.tactic.ta0003",
"google.mitre.technique.t1136.003"
],
"executionState": "DEFAULT"
}
]
}
使用 modifyRules 批次修改規則設定
rules.modifyRules 方法支援對自訂規則和精選規則進行下列批次更新:
更新即時規則狀態
更新快訊狀態
更新套用的代碼
更新封存狀態 (僅限自訂規則)
系統會以同步方式獨立執行批次更新。這個程序並非不可分割,即使發生個別失敗情形,仍會繼續執行。failed_requests 欄位會詳細說明部分失敗情形,這個對應項的鍵代表失敗要求的索引,值則提供失敗原因。成功更新的項目會記錄在 rule_updates 欄位中,每個要求的結果會放在原始批次中對應的索引。
modifyRules 要求範例:
HTTP
POST https://chronicle.googleapis.com/v1alpha/projects/<ID>/locations/us/instances/<ID>/rules:modifyRules
JSON
{
"parent": "projects/<ID>/locations/us/instances/<ID>",
"requests": [
{
"update_mask": "liveModeEnabled",
"rule": {
"name": "projects/11344677023/locations/eu/instances/e902a911-16e3-4c39-978d-e25234232492/rules/ru_aaaaaaaaaaaaaaaaaaaaaaa",
"liveModeEnabled": true
}
},
{
"update_mask": "alertingEnabled",
"rule": {
"name": "projects/11344677023/locations/eu/instances/e902a911-16e3-4c39-978d-e25234232492/rules/ur_zzzzzzzzzzzzzzzzzzzzz",
"alertingEnabled": false
}
},
{
"update_mask": "tags",
"rule": {
"name": "projects/11344677023/locations/eu/instances/e902a911-16e3-4c39-978d-e25234232492/rules/ru_bbbbbbbbbbbbbbbbbbbbbbb",
"tags": [
"projects/11344677023/locations/eu/instances/e902a911-16e3-4c39-978d-e25234232492/google.mitre.tactic.TA0043",
"projects/11344677023/locations/eu/instances/e902a911-16e3-4c39-978d-e25234232492/google.mitre.technique.T1595"
]
}
},
{
"update_mask": "archived",
"rule": {
"name": "projects/11344677023/locations/eu/instances/e902a911-16e3-4c39-978d-e25234232492/rules/ru_cccccccccccccccccccccc",
"archived": true
}
}
]
}
回應範例:
JSON
{
"failed_requests": {
"0": {
"code": 5,
"message": "rule is already enabled"
},
"3": {
"code": 5,
"message": "rule is already archived"
}
},
"rule_updates": [
{},
{ "alerting_state_updated": true },
{ "tagsUpdated": true },
{}
]
}
更新精選規則的指南
修改精選規則的即時或快訊狀態時,請注意下列事項:
獨立控制:您可以獨立管理規則的狀態,不必受父項規則集政策影響。如果規則的狀態與上層政策不同,自訂設定會持續生效,直到上層政策下次更新為止。
資格規定:只有在執行個體有權使用上層規則套件時,才能更新這些狀態。
更新代碼的規範
您可以透過下列方法將代碼與規則建立關聯:
在規則文字的
tactic、technique或mitre_ttp中繼欄位中,加入 MITRE T 程式碼 (戰術或技術)。在規則文字的
tags中繼欄位中,指定完整的標記資源名稱。使用
ModifyRuleAPI 要求指定完整的代碼資源名稱。
ModifyRules API 支援 MITRE tactic 和 technique 標記。API 更新中提供的任何標記都會覆寫現有標記,但直接從規則文字推斷出的標記除外。
Google 代管的 MITRE tactic 標記使用 google.mitre.tactic 命名空間前置字元。
TA0001 策略代碼的完整資源名稱範例:
projects/11344677023/locations/eu/instances/e902a911-16e3-4c39-978d-e25234232492/google.mitre.tactic.TA0001
還有其他問題嗎?向社群成員和 Google SecOps 專業人員尋求答案。