> 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/data-onboarding/custom-log-types/script-parser.md).

# 스크립트 로그 파서

## 개요

`script` 의 가능한 값 중 하나입니다 [`파서` 키](/ko/data-onboarding/custom-log-types/reference.md#parserspec) 사용자 지정 로그 스키마에서. 이 파서는 Panther가 들어오는 각 로그 이벤트에 수행해야 하는 변환을 다음을 사용하여 지정할 수 있게 해줍니다 [Starlark 구성 언어](https://bazel.build/rules/language), 이는 Python과 문법적으로 많은 유사점을 공유합니다.  `script` Panther의 파서는 구조화된(JSON) 이벤트와 비구조화된 이벤트를 모두 처리할 수 있습니다.

다음을 사용하면 도움이 될 수 있습니다 `script` 파서를 사용할 수 있습니다:

* 비구조화된 로그를 파싱하지만, 다른 파서 옵션([`csv`](/ko/data-onboarding/custom-log-types/csv-parser.md), [`fastmatch`](/ko/data-onboarding/custom-log-types/fastmatch-parser.md), [`regex`](/ko/data-onboarding/custom-log-types/regex-parser.md))이 충분하지 않은 경우
* 데이터에 변환을 수행하지만, Panther에서 제공하는 [스키마 변환](/ko/data-onboarding/custom-log-types/transformations.md) 이 충분하지 않은 경우

## 이해하기 `script` 파서

### 정의하기 `함수`

다음을 사용할 때 `script` 파서를 정의하려면 Starlark `함수`. 함수는 다음을 입력받습니다: [문자열](https://github.com/google/starlark-go/blob/master/doc/spec.md#strings) 그리고 비어 있지 않은 [딕셔너리](https://github.com/google/starlark-go/blob/master/doc/spec.md#dictionaries). 반환된 딕셔너리는 출력 이벤트의 형식을 정의합니다.

### 사용 가능한 함수

해당 `script` 파서는 다음에 설명된 기본 요소를 사용할 수 있습니다 [Starlark 사양](https://github.com/google/starlark-go/blob/master/doc/spec.md). 또한 다음 함수를 사용할 수 있습니다:

<table><thead><tr><th width="177.61370849609375">함수 이름</th><th>설명</th></tr></thead><tbody><tr><td>json.decode</td><td>JSON 문자열을 딕셔너리로 디코딩합니다</td></tr><tr><td>json.encode</td><td>딕셔너리를 JSON 문자열로 인코딩합니다</td></tr><tr><td>base64.decode</td><td>base64로 인코딩된 문자열을 디코딩합니다</td></tr><tr><td>base64.encode</td><td>문자열에 base64 인코딩을 수행합니다</td></tr></tbody></table>

### 제한 사항

다음 제한 사항이 스크립트에 적용됩니다:

* 예외를 발생시키는 것은 허용되지 않습니다.
* import는 허용되지 않습니다.

### JSON 처리

비록 `script` 주로 텍스트 로그용으로 사용되지만, 다음 외부에서 변환을 수행하고 싶은 경우 JSON 로그에도 사용할 수 있습니다 [Panther에서 기본적으로 지원하는 것](/ko/data-onboarding/custom-log-types/transformations.md). 이러한 이유로,  `script` 파서에는 기본으로 다음이 포함되어 있습니다 `JSON` JSON을 문자열 형식에서 딕셔너리로 변환할 수 있는 모듈

예를 들어, 다음 구성은 다음과 같은 새 필드를 생성합니다 `is_panther_employee` 다음이 됩니다 `true` 행위자 이메일에 다음이 있으면 `panther.com` 도메인이면, 그리고 `false` 그 외의 경우.

```yaml
파서:
  스크립트:
    함수: |
      def parse(log):
        event = json.decode(log)
        if event['actor']['email'].endswith('@panther.com'):
          event['is_panther_employee'] = True
        else:
          event['is_panther_employee'] = False
        return event
```

이해를 돕기 위해 위의 `parse` 함수는 아래에 Python 구문 강조와 함께 표시됩니다:

```python
def parse(log):
  event = json.decode(log)
  if event['actor']['email'].endswith('@panther.com'):
    event['is_panther_employee'] = True
  else:
    event['is_panther_employee'] = False
  return event
```

## 다음을 사용하는 예시 `script`

Apache Common Log 형식을 사용하는 다음 로그 줄이 Panther로 전송된다고 가정해 보세요:

<pre><code><strong>127.0.0.1 - frank [10/Oct/2000:13:55:36 -0700] "GET /apache_pb.gif HTTP/1.0" 200 2326
</strong></code></pre>

이 로그 유형을 다음을 사용해 파싱하려면 `script`, 다음 함수를 정의합니다:

```python
def parse(log):
  fields = log.split(" ")
  return {
    'remote_ip': fields[0],
    'identity': fields[1],
    'user': fields[2],
    'timestamp': ' '.join(fields[3:5]).strip('[]'),
    'request_uri': ' '.join(fields[5:8]).strip('"'),
    "status": int(fields[8]),
    "bytes_sent": int(fields[9])
  }
```

그리고 다음 스키마 필드를 사용합니다:

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

위 로그가 이 파서로 정규화되면 다음과 같습니다:

```json
{
    "bytes_sent":2326,
    "identity": "-",
    "method":"GET",
    "protocol":"HTTP/1.0",
    "remote_ip":"127.0.0.1",
    "request_uri":"/apache_pb.gif",
    "status":200,
    "timestamp":"2000-10-10 20:55:36.000000000",
    "user":"frank"
}
```


---

# 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/data-onboarding/custom-log-types/script-parser.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.
