# CSV 로그 파서

## 개요

다음을 사용하여 `csv` 로그 파서로, CSV 파일은 각 행을 간단한 JSON 객체로 변환하고 키를 값에 매핑하여 파싱됩니다. 이를 위해 각 열에 이름을 지정해야 합니다.

## 헤더가 없는 CSV 로그

헤더 행이 없는 CSV 로그를 파싱하려면, Panther는 각 열에 어떤 이름을 할당할지 알아야 합니다.

로그가 year, month, day, time, action, ip\_address, message의 7개 열을 가진 CSV라고 가정해 보겠습니다. 이 파일의 예시 행은 다음과 같을 수 있습니다:

```
# 20200901의 액세스 로그
2020,09,01,10:35:23, SEND ,192.168.1.3,"PING"
2020,09,01,10:35:25, RECV ,192.168.1.3,"PONG"
2020,09,01,10:35:25, RESTART ,-,"시스템 재시작"
```

다음 *LogSchema* 를 사용하여 로그 유형을 정의합니다:

{% tabs %}
{% tab title="콘솔 " %}
Panther 콘솔에서는 다음을 따라 [커스텀 스키마를 수동으로 만드는 방법 지침](/ko/data-onboarding/custom-log-types.md#how-to-create-a-custom-schema-manually)을 선택하여 **CSV** parser.

<figure><img src="/files/3dcce33ec60397fb97a4c7aa36908f3bed256e3d" alt="Under a &#x22;Parser&#x22; header is a form with various fields, including &#x22;Has Header,&#x22; &#x22;Delimiter,&#x22; &#x22;Columns,&#x22; &#x22;Empty Values,&#x22; and more."><figcaption></figcaption></figure>

다음 **CSV Log Parser** 섹션(위 스크린샷에 표시된 **를 클릭합니다. 스키마에** 섹션 아래)에서 다음 필드를 정의합니다:

```yaml
fields:
- name: timestamp
  type: timestamp
  timeFormats: 
   - rfc3339
  isEventTime: true
  required: true
- 이름: 동작
  type: string
  required: true
- 이름: ip_address
  type: string
  indicators: [ip]
- name: message
  type: string
```

{% endtab %}

{% tab title="전체 YAML 표현" %}

```yaml
parser:
  csv:
    # CSV 파일은 다양한 형태로 제공되며, 각 행을 분리할 구분 문자를 선택할 수 있습니다
    delimiter: ","
    # 값 주변의 공백을 제거합니다
    trimSpace: true
    # 'columns' 배열의 이름은 각 행의 열에 매핑됩니다.
    # 열을 건너뛰고 싶다면, 같은 인덱스의 이름을 빈 문자열("")로 설정할 수 있습니다
    columns:
    - year
    - month
    - day
    - time
    - action
    - ip_address
    - message
    # 접두사로 시작하는 줄은 건너뜁니다(예: 주석)
    skipPrefix: "# "
    # CSV 파일은 때때로 누락되었거나 N/A 데이터에 대한 자리표시자 값을 사용합니다.
    # 'emptyValues'로 이러한 값을 정의할 수 있으며, 그러면 무시됩니다.
    emptyValues: ["-"]
    # 'expandFields' 지시문은 생성된 필드를 키/값 쌍에 주입하는 템플릿 문자열을 렌더링합니다
    expandFields:
      # 타임스탬프가 여러 열에 나뉘어 있으므로, RFC3339 형식으로 다시 조립해야 합니다
      # 다음은 CSV 값의 필드를 대체하여 'timestamp' 필드를 추가합니다
      timestamp: '%{year}-%{month}-%{day}T%{time}Z'
fields:
- name: timestamp
  type: timestamp
  timeFormats: 
   - rfc3339
  isEventTime: true
  required: true
- 이름: 동작
  type: string
  required: true
- 이름: ip_address
  type: string
  indicators: [ip]
- name: message
  type: string
```

{% endtab %}
{% endtabs %}

## 헤더가 있는 CSV 로그

헤더 행으로 시작하는 CSV 파일을 파싱하려면, 두 가지 옵션이 있습니다:

* 헤더에 정의된 이름을 JSON 필드의 이름으로 사용합니다
* 헤더를 무시하고 열 이름을 명시적으로 정의합니다 [헤더가 없는 CSV 파일에서와 같은 방식으로](#csv-logs-without-header)

{% hint style="warning" %}
CSV 파일에 헤더가 있고 열을 명시적으로 정의하지 않는 경우(대신 헤더에 의해 정의되도록 하는 경우), 이 스키마를 다른 스키마와 같은 로그 소스(또는 단일 S3 prefix)에 함께 사용하지 마십시오. 그렇게 하면 로그가 잘못 분류될 수 있습니다.
{% endhint %}

헤더의 이름을 사용하려면 파서 설정은 다음과 같아야 합니다:

```yaml
parser:
  csv:
    delimiter: "," 
    # 'hasHeader'를 true로 설정하고 'columns' 필드를 지정하지 않으면,
    # Panther는 헤더의 값에서 열 이름을 설정합니다.
    hasHeader: true
    # 열 이름을 변경하고 싶다면 'expandFields' 지시문을 사용할 수 있습니다
    expandFields:
      # 헤더에 열 이름으로 '$cost'가 있고 이를 'cost_us_dollars'로 '정규화'하고 싶다고 가정해 보겠습니다
      "cost_us_dollars": '%{$cost}'
```

헤더를 무시하고 열에 사용할 이름 집합을 정의하려면 다음을 사용합니다:

```yaml
parser:
  csv:
    delimiter: "," 
    # 'hasHeader'를 true로 설정하면서 동시에 'columns' 필드를 지정하면, 
    # Panther는 헤더를 무시하고 'columns' 배열의 이름을 사용합니다
    hasHeader: true
    columns:
    - foo
    - bar
    - baz
```


---

# Agent Instructions: 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:

```
GET https://docs.panther.com/ko/data-onboarding/custom-log-types/csv-parser.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
