Tool: create_rule
Create a new detection rule in Chronicle SIEM.
Creates a new YARA-L 2.0 detection rule in Chronicle that can generate alerts when the rule conditions are met by ingested events. Rules are the core mechanism for automated threat detection and response in Chronicle.
Workflow Integration: - Essential for implementing custom detection logic based on your organization's security requirements. - Use after analyzing events, entities, or threat intelligence to codify detection patterns. - Complements existing detection capabilities by addressing specific use cases or threat scenarios. - Enables automated detection of TTPs, IOCs, or behavioral patterns identified through investigations.
Use Cases: - Create rules to detect specific attack patterns discovered during threat hunting. - Implement custom detection logic for proprietary applications or unique network configurations. - Detect compliance violations or policy breaches specific to your organization. - Create behavioral detection rules based on user or entity activity patterns. - Implement detection for specific threat intelligence indicators relevant to your environment.
Rule Development Best Practices: - Start with a clear understanding of what you want to detect and the data sources available. - Use precise conditions to minimize false positives while maintaining detection efficacy. - Include appropriate metadata (description, author, severity, MITRE ATT&CK mappings). - Test rules thoroughly using test_rule before deploying to production. - Consider the rule's performance impact on Chronicle's processing capabilities.
Args: rule_text (str): Complete YARA-L 2.0 rule definition including rule metadata, events, and conditions. project_id (str): Google Cloud project ID (required). customer_id (str): Chronicle customer ID (required). region (str): Chronicle region (e.g., "us", "europe") (required).
Returns: str: Raw JSON response from the API, typically containing the created Rule object. Returns an error message if rule creation fails.
Example Usage: rule_text = ''' rule suspicious_powershell_download { meta: description = "Detects PowerShell downloading files" author = "Security Team" severity = "Medium" events: $process.metadata.event_type = "PROCESS_LAUNCH" $process.principal.process.command_line = /powershell.*downloadfile/i condition: $process } '''
create_rule(
rule_text=rule_text,
project_id="my-project",
customer_id="my-customer",
region="us"
)
Next Steps (using MCP-enabled tools): - Validate the rule syntax using validate_rule. - Use list_rule_errors to check for any runtime errors. - Test the rule using test_rule with historical data to validate its effectiveness. - Monitor the rule's performance and adjust thresholds or conditions as needed. - Review generated alerts using udm_search to assess rule quality. - Document the rule's purpose and expected behavior for operational teams.
The following sample demonstrate how to use curl to invoke the create_rule MCP tool.
| Curl Request |
|---|
curl --location 'https://chronicle.googleapis.com/mcp' \ --header 'content-type: application/json' \ --header 'accept: application/json, text/event-stream' \ --data '{ "method": "tools/call", "params": { "name": "create_rule", "arguments": { // provide these details according to the tool's MCP specification } }, "jsonrpc": "2.0", "id": 1 }' |
Input Schema
Request message for CreateRule.
CreateRuleRequest
| JSON representation |
|---|
{ "projectId": string, "customerId": string, "region": string, "rule": string } |
| Fields | |
|---|---|
projectId |
Project ID of the customer. |
customerId |
Customer ID of the customer. |
region |
Region of the customer. |
rule |
The rule to create. |
Output Schema
The Rule resource represents a user-created rule. NEXT TAG: 31
Rule
| JSON representation |
|---|
{ "name": string, "revisionId": string, "displayName": string, "text": string, "author": string, "severity": { object ( |
| Fields | |
|---|---|
name |
Identifier. Full resource name for the rule. Format: |
revisionId |
Output only. The revision ID of the rule. A new revision is created whenever the rule text is changed in any way. Format: |
displayName |
Output only. Display name of the rule. Populated in BASIC view and FULL view. |
text |
The YARA-L content of the rule. Populated in FULL view. |
author |
Output only. The author of the rule. Extracted from the meta section of text. Populated in BASIC view and FULL view. |
severity |
Output only. The severity of the rule as specified in the meta section of text. Populated in BASIC view and FULL view. |
metadata |
Output only. Additional metadata specified in the meta section of text. Populated in FULL view. An object containing a list of |
createTime |
Output only. The timestamp of when the rule was created. Populated in FULL view. Uses RFC 3339, where generated output will always be Z-normalized and use 0, 3, 6 or 9 fractional digits. Offsets other than "Z" are also accepted. Examples: |
revisionCreateTime |
Output only. The timestamp of when the rule revision was created. Populated in FULL, REVISION_METADATA_ONLY views. Uses RFC 3339, where generated output will always be Z-normalized and use 0, 3, 6 or 9 fractional digits. Offsets other than "Z" are also accepted. Examples: |
compilationState |
Output only. The current compilation state of the rule. Populated in FULL view. |
type |
Output only. User-facing type of the rule. Extracted from the events section of rule text. Populated in BASIC view and FULL view. |
referenceLists[] |
Output only. Resource names of the reference lists used in this rule. Populated in FULL view. |
allowedRunFrequencies[] |
Output only. The run frequencies that are allowed for the rule. Populated in BASIC view and FULL view. |
etag |
The etag for this rule. If this is provided on update, the request will succeed if and only if it matches the server-computed value, and will fail with an ABORTED error otherwise. Populated in BASIC view and FULL view. |
scope |
Resource name of the DataAccessScope bound to this rule. Populated in BASIC view and FULL view. If reference lists are used in the rule, validations will be performed against this scope to ensure that the reference lists are compatible with both the user's and the rule's scopes. The scope should be in the format: |
compilationDiagnostics[] |
Output only. A list of a rule's corresponding compilation diagnostic messages such as compilation errors and compilation warnings. Populated in FULL view. |
nearRealTimeLiveRuleEligible |
Output only. Indicate the rule can run in near real time live rule. If this is true, the rule uses the near real time live rule when the run frequency is set to LIVE. |
dataTables[] |
Output only. Resource names of the data tables used in this rule. |
inputsUsed |
Output only. The set of inputs used in the rule. For example, if the rule uses $e.principal.hostname, then the uses_udm field will be true. |
ruleOwner |
Output only. The rule owner (i.e., whether the rule is customer or Google-authored). |
tags[] |
Output only. Resource names of the tags used in this rule. Example: [ "projects/{project}/locations/{location}/instances/{instance}/ tags/google.mitre.TA000", "projects/{project}/locations/{location}/instances/{instance}/ "tags/google.CloudThreats", ] |
alertingEnabled |
Output only. Alerting status for the rule. |
liveModeEnabled |
Output only. Live Status for the rule. |
archived |
Output only. The archive state of the rule deployment. Cannot be set to true unless enabled is set to false. If set to true, alerting will automatically be set to false. If currently set to true, enabled, alerting, and run_frequency cannot be updated. |
runFrequency |
Output only. The chosen run frequencies for the rule. |
currentDayDetectionCount |
Output only. The number of matched events for the current day in UTC time. |
executionState |
Output only. The execution state of the rule. |
Severity
| JSON representation |
|---|
{ "displayName": string } |
| Fields | |
|---|---|
displayName |
The display name of the severity level. Extracted from the meta section of the rule text. |
MetadataEntry
| JSON representation |
|---|
{ "key": string, "value": string } |
| Fields | |
|---|---|
key |
|
value |
|
Timestamp
| JSON representation |
|---|
{ "seconds": string, "nanos": integer } |
| Fields | |
|---|---|
seconds |
Represents seconds of UTC time since Unix epoch 1970-01-01T00:00:00Z. Must be between -62135596800 and 253402300799 inclusive (which corresponds to 0001-01-01T00:00:00Z to 9999-12-31T23:59:59Z). |
nanos |
Non-negative fractions of a second at nanosecond resolution. This field is the nanosecond portion of the duration, not an alternative to seconds. Negative second values with fractions must still have non-negative nanos values that count forward in time. Must be between 0 and 999,999,999 inclusive. |
CompilationDiagnostic
| JSON representation |
|---|
{ "message": string, "position": { object ( |
| Fields | |
|---|---|
message |
Output only. The diagnostic message. |
position |
Output only. The approximate position in the rule text associated with the compilation diagnostic. Compilation Position may be empty. |
severity |
Output only. The severity of a rule's compilation diagnostic. |
uri |
Output only. Link to documentation that describes a diagnostic in more detail. |
CompilationPosition
| JSON representation |
|---|
{ "startLine": integer, "startColumn": integer, "endLine": integer, "endColumn": integer } |
| Fields | |
|---|---|
startLine |
Output only. Start line number, beginning at 1. |
startColumn |
Output only. Start column number, beginning at 1. |
endLine |
Output only. End line number, beginning at 1. |
endColumn |
Output only. End column number, beginning at 1. |
InputsUsed
| JSON representation |
|---|
{ "usesUdm": boolean, "usesEntity": boolean, "usesDetection": boolean } |
| Fields | |
|---|---|
usesUdm |
Optional. Whether the rule queries UDM events. |
usesEntity |
Optional. Whether the rule queries entity events. |
usesDetection |
Optional. Whether the rule queries detections. |
Tool Annotations
Destructive Hint: ❌ | Idempotent Hint: ❌ | Read Only Hint: ❌ | Open World Hint: ❌