> For the complete documentation index, see [llms.txt](https://docs.panther.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.panther.com/ko/pantherflow/statements.md).

# PantherFlow 문

## 개요

{% hint style="info" %}
PantherFlow는 Panther 버전 1.110부터 오픈 베타로 제공되며, 모든 고객이 이용할 수 있습니다. 버그 보고 및 기능 요청은 Panther 지원 팀에 공유해 주세요.
{% endhint %}

PantherFlow 쿼리는 하나 이상의 문으로 구성됩니다. 문에는 두 가지 유형이 있습니다: [테이블식 표현 문](#tabular-expression-statements) 및 [`let` 문](#let-statements).

동일한 쿼리의 여러 문은 세미콜론(`;`). 마지막 문에는 세미콜론이 필요하지 않습니다.

## 테이블식 표현 문

"파이프된 쿼리"라고 들으면 보통 떠오르는 것이 테이블식 표현 문입니다. 이는 데이터 소스와 일반적으로 하나 이상의 연산자로 구성되며, 파이프 문자(`|`). 각 연산자는 데이터를 받아 작업을 수행한 다음 변환된 데이터를 다음 연산자에 전달합니다.

{% hint style="info" %}
다음의 [Search](/ko/search/search-tool.md#using-pantherflow-in-search), 쿼리는 아래에 표시된 것처럼 데이터베이스 및 테이블 이름으로 시작하거나 `union` 연산자로 시작할 수 있습니다. 둘 중 어느 것도 제공되지 않으면 Search는 다음의 값을 사용합니다 [데이터베이스 및 테이블 드롭다운 필드](/ko/search/search-tool.md#using-database-table-and-date-range-filters).
{% endhint %}

```kusto
panther_logs.public.aws_cloudtrail
| where accountId != '1234567'
| summarize Count=agg.count() by eventName
| extend tooHigh = Count > 100
| where tooHigh
| sort Count
| limit 10
```

### 데이터 소스

모든 PantherFlow 쿼리는 데이터 소스를 지정해야 합니다. 다음 항목 중 어느 것이든 데이터 소스로 사용할 수 있습니다:

* 테이블식 표현 문
* [테이블 변수](#table-variables)
* [`datatable`](/ko/pantherflow/operators/datatable.md)
* [`union`](/ko/pantherflow/operators/union.md)
* [`range`](/ko/pantherflow/operators/range.md)

## `let` 문

A `let` 문은 후속 문에서 사용할 수 있는 변수에 값을 할당합니다. `let` 문은 두 가지 유형의 변수를 정의할 수 있습니다:

* **테이블 변수**: 테이블식 표현을 나타내며, 나중에 테이블처럼 사용할 수 있습니다
* **스칼라 변수**: 스칼라 값 또는 스칼라 값으로 평가되는 표현식을 나타냅니다

변수는 다음 안에서 정의되어야 합니다 `let` 문에서 참조되기 전에. 모든 `let` 문은 세미콜론(`;`)으로 끝나야 합니다.

### 테이블 변수

테이블 변수는 다음을 사용하여 변수에 테이블식 표현 문을 할당할 때 생성됩니다 `let`. 그런 다음 이를 테이블식 표현 문처럼 참조할 수 있습니다(즉, 가능한 [데이터 소스](#data-sources)).

테이블 변수에 할당된 테이블식 표현 문은 이후 문에서 변수가 참조되거나 "호출"될 때까지 실행되지 않습니다.

테이블 변수로 쿼리에 이름을 붙이는 것은 다음과 같은 경우 유용할 수 있습니다:

* 같은 쿼리를 두 번 이상 작성하고 싶지 않을 때
* 다른 사람들이 쿼리가 무엇을 하는지 더 쉽게 이해할 수 있게 하고 싶을 때

**예시**

다음 예제는 테이블 변수 `elbOK`. 아래에서 `elbOK` 는 `let` 문에 정의된 그대로 정확히 실행됩니다:

```kusto
let elbOK = panther_logs.public.aws_alb
| where elbStatusCode == 200;

elbOK
```

여기서는 추가 연산자가 `elbOK` 테이블식 표현 문 내에서 적용됩니다:

```kusto
let elbOK = panther_logs.public.aws_alb
| where elbStatusCode == 200;

elbOK 
| where p_event_time > time.ago(1h)
```

테이블 변수는 데이터셋을 참조하는 모든 곳에서 사용할 수 있으며, 다음과 함께 사용할 수 있습니다 [`union` 연산자](/ko/pantherflow/operators/union.md):

```kusto
let ec2Events = panther_logs.public.aws_cloudtrail
| where p_event_time > time.ago(1h)
| where eventSource == "ec2.amazonaws.com";

let s3Events = panther_logs.public.aws_cloudtrail
| where p_event_time > time.ago(1h)
| where eventSource == "s3.amazonaws.com";

union ec2Events, s3Events
| summarize count=agg.count() by eventName, eventSource
| sort count desc
```

### 스칼라 변수

스칼라 변수는 비테이블식 표현식을 변수에 할당할 때 생성됩니다. 그런 다음 스칼라 변수는 이후 쿼리 전반에서 참조할 수 있습니다.

스칼라 변수를 선언하는 것은 다음과 같은 경우 유용할 수 있습니다:

* 특히 같은 값을 여러 번 사용할 때 쿼리를 더 읽기 쉽고 유지 관리하기 쉽게 만들기
* 그렇지 않으면 오해될 수 있는 값에 이름을 붙이기

다음 사항에 유의하세요 [아래의 스칼라 변수 제한 사항](#scalar-variable-limitations).

#### **예시**

다음 예제는 스칼라 변수 `threshold`를 선언한 다음, 이를 [`where`](/ko/pantherflow/operators/where.md) 절에서 참조합니다:

```kusto
let threshold = 100;

panther_logs.public.aws_cloudtrail
| where p_event_time > time.ago(1d)
| summarize count=agg.count() by eventName
| where count > threshold
```

스칼라 변수의 값은 하나의 [함수](/ko/pantherflow/functions.md)을 사용할 수 있으며, 스칼라 변수는 함수의 매개변수로 사용할 수 있습니다:

```kusto
let domain = "example.com";
let searchSuffix = strings.cat("@", domain);

panther_logs.public.aws_cloudtrail
| where strings.ends_with(userIdentity.principalId, searchSuffix)
| summarize count=agg.count() by eventName
```

스칼라 변수와 함께 산술 표현식도 사용할 수 있습니다:

```kusto
let hourInSeconds = 60 * 60;
let dayInSeconds = hourInSeconds * 24;
let weekInSeconds = dayInSeconds * 7;

panther_logs.public.aws_cloudtrail
| extend ageInSeconds = time.diff("s", p_event_time, time.now())
| extend ageCategory = case(
    ageInSeconds < hourInSeconds, "1시간 미만",
    ageInSeconds < dayInSeconds, "1일 미만",
    ageInSeconds < weekInSeconds, "1주 미만",
    "1주 이상"
)
| summarize count=agg.count() by ageCategory
```

강력한 쿼리를 위해 스칼라 변수와 테이블 변수를 함께 사용할 수 있습니다:

```kusto
// Scalar variables
let minSeverity = 3;
let timeRange = 7d;
let criticalServices = ["ec2.amazonaws.com", "iam.amazonaws.com", "s3.amazonaws.com"];

// Table variable
let baseQuery = panther_logs.public.aws_cloudtrail
| where p_event_time > time.ago(timeRange)
| where eventSource in criticalServices;

// Table variable
let failedActions = baseQuery
| where errorCode != ""
| extend severity = case(
    errorCode == "AccessDenied", 4,
    errorCode == "UnauthorizedOperation", 3,
    strings.starts_with(errorCode, "Client"), 2,
    1
);

// Tabular expression statement
failedActions
| where severity >= minSeverity
| summarize count=agg.count() by eventSource, errorCode, severity
| sort severity desc, count desc
```

### 변수 이름 규칙

변수 이름은 다음 규칙을 따라야 합니다:

* 첫 번째 문자는 문자, 밑줄(`_`), 또는 달러 기호(`$`).
* )여야 합니다. 첫 번째 문자 이후의 문자는 문자, 숫자 또는 밑줄이어야 합니다.
* 기존 테이블 이름은 변수 이름으로 사용할 수 없습니다.
  * 예를 들어, 이미 다음이라는 이름의 테이블이 존재한다면 `aws_cloudtrail`다음을 `aws_cloudtrail` 변수 이름으로 사용할 수 없습니다.
* 한 번 사용된 변수 이름은 동일한 PantherFlow 검색에서 다시 사용할 수 없습니다. 즉, 변수는 다시 정의할 수 없습니다.

**예시**

<table><thead><tr><th width="158.21954345703125">올바른 변수 이름</th><th width="360.1328125">잘못된 변수 이름</th></tr></thead><tbody><tr><td><code>myVar123</code></td><td><code>123myVar</code> (숫자로 시작함)</td></tr><tr><td><code>my_var</code></td><td><code>my-var</code> (잘못된 문자)</td></tr><tr><td><code>_my_var</code></td><td><code>my.var</code> (잘못된 문자)</td></tr><tr><td><code>$my_var</code></td><td><code>my_var$</code> (<code>$</code> 첫 번째 문자로만 허용됨)</td></tr></tbody></table>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.panther.com/ko/pantherflow/statements.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
