# Fastmatch 로그 파서

## 개요

사용자를 사용할 것이며, `fastmatch` 파서는 로그 라인 내에서 필드의 위치를 지정하는 단순한 문자열 패턴을 사용합니다. 이름에서 알 수 있듯 매우 빠르며 텍스트 로그를 파싱하는 선호되는 방법으로 간주되어야 합니다. 필드의 순서를 알고 있는 대부분의 구조화된 텍스트 로그 사례를 처리할 수 있습니다. 사실 매우 빠르기 때문에 여러 패턴을 순서대로 지정하여 테스트할 수 있어 로그 라인의 구조에 몇 가지 변형이 있는 경우도 '해결'할 수 있습니다.

### fastmatch 사용 예

다음 예제 로그 라인은 Apache Common Log 형식을 사용합니다:

```
127.0.0.1 - frank [10/Oct/2000:13:55:36 -0700] "GET /apache_pb.gif HTTP/1.0" 200 2326
```

이 로그 유형에 대해 다음과 같이 로그 스키마를 정의할 수 있습니다 `fastmatch`:

{% tabs %}
{% tab title="콘솔 " %}
Panther 콘솔에서는 다음을 따릅니다 [커스텀 스키마를 수동으로 생성하는 방법 안내](https://docs.panther.com/ko/data-onboarding/custom-log-types/..#how-to-create-a-custom-schema-manually), **FastMatch** 파서.

<figure><img src="https://2400888838-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LgdiSWdyJcXPahGi9Rs-2910905616%2Fuploads%2Fgit-blob-154ae17854fc2eb08a2bd19c5349e4c463939557%2Fimage.png?alt=media" alt="In a &#x22;Schema&#x22; section, &#x22;FastMatch&#x22; is selected for a Parser field. There are various form fields shown, such as Match Patterns, Empty Values, and Skip Prefix."><figcaption></figcaption></figure>

일반 구성 **필드 및 지시자** 섹션(위 스크린샷에 표시된 **파서** 섹션 아래), 우리는 다음과 같이 필드를 정의합니다:

```yaml
필드:
  - 이름: remote_ip
    type: string
    지표:
      - ip
  - name: identity
    type: string
  - name: user
    type: string
  - 이름: timestamp
    type: timestamp
    isEventTime: true
    timeFormats:
     - '%d/%b/%Y:%H:%M:%S %z'
  - name: method
    type: string
  - 이름: request_uri
    type: string
  - 이름: protocol
    type: string
  - 이름: status
    유형: int
  - name: bytes_sent
    type: bigint
```

{% endtab %}

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

```yaml
파서:
  패스트매치:
    # 매칭할 패턴 배열을 정의합니다.
    # 이 예에서는 로그 형식이 모든 라인에서 동일하기 때문에 하나의 패턴만 사용합니다.
    # Apache Extended Log 형식을 포함하려면 추가 패턴을 제공할 수 있습니다.
    매치:
      - '%{remote_ip} %{identity} %{user} [%{timestamp}] "%{method} %{request_uri} %{protocol}" %{status} %{bytes_sent}'
    emptyValues: [ '-' ] # `-` 문자열 값을 널(null)로 간주하도록 지정
필드:
  - 이름: remote_ip
    type: string
    지표:
      - ip
  - name: identity
    type: string
  - name: user
    type: string
  - 이름: timestamp
    type: timestamp
    isEventTime: true
    timeFormats:
     - '%d/%b/%Y:%H:%M:%S %z'
  - name: method
    type: string
  - 이름: request_uri
    type: string
  - 이름: protocol
    type: string
  - 이름: status
    유형: int
  - name: bytes_sent
    type: bigint
```

{% endtab %}
{% endtabs %}

## fastmatch 패턴 이해하기

패턴은 `%{field_name}` 플레이스홀더를 사용하여 로그 라인에서 필드가 예상되는 위치를 설정합니다. 예를 들어, 다음 텍스트와 일치시키기 위해:

```
2020-10-10T14:32:05 [FOO_SERVICE@127.0.0.1] [DEBUG] "" Something when wrong
```

다음 패턴을 사용할 수 있습니다(명확성을 위해 작은따옴표로 둘러쌈):

```yaml
' % {timestamp} [%{service}@%{ip}] [%{log_level}] %{message}'
```

Panther 콘솔에서 스키마를 정의하는 경우 패턴을 **Match Patterns** 필드에 입력합니다:

<figure><img src="https://2400888838-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LgdiSWdyJcXPahGi9Rs-2910905616%2Fuploads%2Fgit-blob-59d206a2b4880541d062670cff1c067f18ea2968%2Fimage.png?alt=media" alt="A &#x22;Match Patterns&#x22; field is shown. Its description is, &#x22;Define patterns to match log entries and extract structured information from unstructured log lines.&#x22;"><figcaption></figcaption></figure>

### 구분자

두 연속 필드 사이의 텍스트는 그들 사이의 '구분자'를 정의합니다. 구분자는 비어 있을 수 없습니다.

위 예제의 패턴에서는 다음 사이의 `"@"` 을(를) 생략할 수 없습니다 `service` 와 `ip`.

필드 *이전의* 구분자는 구분자 텍스트를 포함할 수 없습니다. 위 예제에서:

* `timestamp` 공백을 포함할 수 없습니다 `" "`
* `service` 포함할 수 없습니다 `"@"`
* `ip` 포함할 수 없습니다 `"] ["`
* `log_level` 포함할 수 없습니다 `"] "`

### 익명 필드

이름 없는 필드 플레이스홀더(`%{}`)는 무시됩니다.

### 꼬리 캡처

패턴의 마지막 필드 뒤에 *텍스트 구분자가 전혀 없으면* 그것은 *모든 것* 끝까지 캡처합니다. 위 예제에서 `message` 캡처할 것입니다 `"Something when wrong"`

### 인용문 처리

경우에 따라 필드는 텍스트 내에서 인용될 수 있습니다:

```
2020-10-10T14:32:05 "Some quoted text with \"escaped quotes\" inside"
```

이러한 필드를 올바르게 언에스케이프하려면 필드 플레이스홀더를 인용부호로 감싸기만 하면 됩니다:

```
%{timestamp} "%{message}"
```

이 방법은 작은따옴표와 큰따옴표 모두에 적용됩니다.
