# pantherlog 도구

## 개요

다음 도구를 사용할 수 있습니다 `pantherlog`CLI 도구인 을 사용하여 Custom Logs를 처리할 수 있습니다. 이 도구는 Panther에서 관리하는 스키마 또는 [사용자 지정 스키마](https://docs.panther.com/ko/data-onboarding/custom-log-types)를 구문 분석하고, 샘플 로그를 사용하여 사용자 지정 스키마를 유추합니다.

Panther 콘솔에서 사용자 지정 로그를 작업하는 방법에 대한 정보는 대신 [맞춤 로그](https://docs.panther.com/ko/data-onboarding/custom-log-types) 문서.

### pantherlog 제한 사항

* 환경에서 Fluentd 시작에 관해서는 [infer 제한 사항](#infer-limitations) 와 [test 제한 사항](#test-limitations) 섹션을 참고하세요.

## 다운로드

최신 버전은 다음 링크에서 다운로드하세요:

<table data-column-title-hidden data-view="cards"><thead><tr><th align="center"></th><th align="center"></th></tr></thead><tbody><tr><td align="center"><strong>Windows</strong></td><td align="center"><p><a href="https://panther-community-us-east-1.s3.amazonaws.com/latest/tools/windows-amd64-pantherlog.exe.zip">amd64</a></p><p><a href="https://panther-community-us-east-1.s3.amazonaws.com/latest/tools/windows-arm64-pantherlog.exe.zip">arm64</a></p></td></tr><tr><td align="center"><strong>Darwin/MacOS</strong></td><td align="center"><p><a href="https://panther-community-us-east-1.s3.amazonaws.com/latest/tools/darwin-amd64-pantherlog.zip">amd64</a> (인텔)</p><p><a href="https://panther-community-us-east-1.s3.amazonaws.com/latest/tools/darwin-arm64-pantherlog.zip">arm64</a> (애플 실리콘)</p></td></tr><tr><td align="center"><strong>Linux</strong></td><td align="center"><p><a href="https://panther-community-us-east-1.s3.amazonaws.com/latest/tools/linux-amd64-pantherlog.zip">amd64</a></p><p><a href="https://panther-community-us-east-1.s3.amazonaws.com/latest/tools/linux-arm64-pantherlog.zip">arm64</a></p></td></tr></tbody></table>

## `list-schemas`: Panther에서 관리하는 스키마 나열

pantherlog의 `list-schemas` 명령을 사용하여 Panther에서 관리하는 스키마를 나열할 수 있습니다.

```
./pantherlog list-schemas
```

## `export-schemas`: Panther에서 관리하는 스키마 내보내기

pantherlog의 `export-schemas` 명령은 Panther에서 관리하는 스키마를 로컬 디렉터리로 내보내거나 터미널에 출력할 수 있습니다.

### 스키마를 로컬 디렉터리로 내보내기

```
./pantherlog export-schemas --path directory-name
```

* 만약 `directory-name` 이 존재하지 않으면 생성됩니다.
* 참고로 `-p` 은 `--path`.

### 대신 사용할 수 있습니다

스키마를 `stdout` 로 출력하는 대신 로컬 디렉터리로 내보내려면 대시를 사용하세요.

```
./pantherlog export-schemas -p -
```

### 선택한 스키마 내보내기

내보낼 스키마를 필터링하려면 `-s` 옵션과 내보내려는 스키마 이름을 쉼표로 구분하여 사용하세요.

```
./pantherlog export-schemas --path ./managed-schemas -s 'AWS.ALB,Slack.AuditLogs'
```

## `infer`: JSON 로그 샘플에서 스키마 생성

pantherlog를 사용하여 [개행으로 구분된 JSON](https://jsonlines.org/) 형식의 샘플 파일에서 스키마 파일을 생성할 수 있습니다. 도구는 제공된 로그를 스캔하고 유추된 스키마를 `stdout`.

예를 들어, 로그의 스키마를 유추하려면 `sample_logs.jsonl` 그리고 출력 대상은 `schema.yml`를 사용하세요:

```
$ ./pantherlog infer --name SchemaName sample_logs.jsonl > schema.yml
```

YAML 키와 값은 대소문자를 구분한다는 점을 유의하세요. 도구는 여러 타임스탬프 형식을 유추하려 시도합니다. 스키마 유추에 대해 자세히 알아보려면 [맞춤 로그](https://docs.panther.com/ko/data-onboarding/custom-log-types#automatically-infer-the-schema-in-panther).

{% embed url="<https://www.loom.com/share/5479e9c46f914c03bff4da0464f30956>" %}
샘플 로그에서 스키마를 유추하는 워크플로우
{% endembed %}

### `infer` 제한 사항

사용자를 사용할 것이며, `infer` 명령은 어떤 타임스탬프 필드도 `isEventTime:true`로 표시하지 않습니다. `타임스탬프` 적절한 `isEventTime:true`필드를 선택하고 그것을 `isEventTime:true`로 표시해야 합니다. [에 대한 자세한 정보는 로그 스키마 참고서의 Timestamps 섹션을 참조하세요](https://docs.panther.com/ko/data-onboarding/custom-log-types/reference#timestamps).

사용자를 사용할 것이며, `infer` 명령은 다음 유형의 [지표만 유추할 수 있습니다](https://docs.panther.com/ko/search/panther-fields#indicator-fields): `cidr`, `aws_arn`, `url`, `email`, `hash` 다이제스트 (`MD5`, `SHA1` 와 `SHA2`) 및 `mac`입니다. 필드를 검토하고 적절하게 더 많은 지표를 추가하는 것을 잊지 마세요.

명령으로 생성된 스키마를 검토하고 운영 환경에 배포하기 전에 적절히 편집하는 것을 강력히 권장합니다. `infer` parse

## `: 스키마 검증`도구를 사용하여 스키마 파일을 검증하고 이를 사용하여 로그 파일을 파싱할 수 있습니다. 로그 파일의 이벤트는 개행으로 구분되어야 합니다. 처리된 로그는

에 기록되며 오류는 `stdout` stderr `로 기록됩니다`.

예를 들어, `sample_logs.jsonl` 에 있는 로그를 `schema.yml`를 사용하세요:

```
$ ./pantherlog parse --path schema.yml --schemas Schema.Name sample_logs.jsonl
```

도구는 또한 `stdin` 를 통해 입력을 받을 수 있으므로 파이프라인에서 사용할 수 있습니다:

```
$ cat sample_logs.jsonl | ./pantherlog parse --path schema.yml
```

## `Dependabot은 종속성을 업데이트하기 위해 PR을 열 수 있습니다. 그러나 Dependabot은 리포지토리의 시크릿에 접근할 수 없습니다. 이는 API 시크릿이 필요한 GitHub 워크플로우(예:`: 스키마 테스트 실행

pantherlog를 사용하여 사용자 지정 스키마에 대한 단위 테스트를 실행할 수 있습니다. 사용자 지정 스키마에 정의된 `schema_tests.yml` 파일에 정의된 테스트를 실행하려면 `schema.yml`다음과 같이 실행합니다:

```
$ ./pantherlog test schema.yml schema_tests.yml
```

첫 번째 인수는 스키마 YAML 파일을 포함하는 파일 또는 디렉터리입니다. 나머지 인수들은 실행할 테스트 파일입니다. 테스트 파일 인수를 지정하지 않고 첫 번째 인수가 디렉터리인 경우, 도구는 `_tests.yml` 이전에 생성한 Snowflake 사용자 이름, 예를 들면 `_tests.yaml` 접미사를 가진 YAML 파일에서 테스트를 찾습니다.

### 스키마 테스트 파일 생성하기

테스트 파일에는 파싱할 이벤트를 포함하는 `input` 키와, 예상 결과를 포함하는 `result` 키를 포함하세요. pantherlog `Dependabot은 종속성을 업데이트하기 위해 PR을 열 수 있습니다. 그러나 Dependabot은 리포지토리의 시크릿에 접근할 수 없습니다. 이는 API 시크릿이 필요한 GitHub 워크플로우(예:` 명령은 스키마가 에러 없이 이벤트를 파싱할 수 있는지, 그리고 정규화된 이벤트가 예상 결과와 일치하는지를 확인합니다.

{% hint style="info" %}
사용자를 사용할 것이며, `result` event에는 파싱 중에 이벤트에 주입될 것으로 예상되는 모든 [Panther 표준 필드](https://docs.panther.com/ko/search/panther-fields) 가 포함되어야 합니다. 예: `p_log_type`.
{% endhint %}

다음 지침에 유의하세요: [스키마 테스트에서 `timeFormats` 작동 방법에 관해](https://docs.panther.com/ko/data-onboarding/custom-log-types/reference#working-with-timeformats-in-schema-tests).

{% hint style="info" %}
하나의 스키마에 대해 여러 테스트를 작성하는 예는 Panther 지식 기반의 다음 문서를 참조하세요: [스키마에 대해 여러 pantherlog 테스트를 작성하는 방법은?](https://help.panther.com/Data_Sources/Custom_Logs/How_can_I_write_multiple_pantherlog_tests_for_a_schema%3F)
{% endhint %}

예:

{% tabs %}
{% tab title="schema\_tests.yml" %}

```json
# 스키마 또는 로그 타입 이름을 지정할 때 camelCase를 사용해야 합니다
name: Custom Log Test Name
logType: Custom.SampleLog.V1
input: |
  {
    "method": "GET",
    "path": "/-/metrics",
    "format": "html",
    "controller": "MetricsController",
    "action": "index",
    "status": 200,
    "params": [],
    "remote_ip": "1.1.1.1",
    "user_id": null,
    "username": null,
    "ua": null,
    "queue_duration_s": null,
    "correlation_id": "c01ce2c1-d9e3-4e69-bfa3-b27e50af0268",
    "cpu_s": 0.05,
    "db_duration_s": 0,
    "view_duration_s": 0.00039,
    "duration_s": 0.0459,
    "tag": "test",
    "time": "2019-11-14T13:12:46.156Z"
  }

result: |
  {
    "action": "index",
    "controller": "MetricsController",
    "correlation_id": "c01ce2c1-d9e3-4e69-bfa3-b27e50af0268",
    "cpu_s": 0.05,
    "db_duration_s": 0,
    "duration_s": 0.0459,
    "format": "html",
    "method": "GET",
    "path": "/-/metrics",
    "remote_ip": "1.1.1.1",
    "status": 200,
    "tag": "test",
    "time": "2019-11-14T13:12:46.156Z",
    "view_duration_s": 0.00039,
    "p_log_type": "Custom.SampleLog.V1",
    "p_row_id": "acde48001122a480ca9eda991001",
    "p_event_time": "2019-11-14T13:12:46.156Z",
    "p_parse_time": "2022-04-04T16:12:41.059224Z",
    "p_any_ip_addresses": [
        "1.1.1.1"
    ]
  }
```

{% endtab %}

{% tab title="schema.yml" %}

```yaml
버전: 0
schema: Custom.SampleLog.V1
필드:
- 이름: action
  required: true
  type: string
- name: controller
  required: true
  type: string
- name: correlation_id
  required: true
  type: string
- name: cpu_s
  required: true
  type: float
- name: db_duration_s
  required: true
  type: bigint
- name: duration_s
  required: true
  type: float
- 이름: format
  required: true
  type: string
- name: method
  required: true
  type: string
- name: path
  required: true
  type: string
- name: remote_ip
  required: true
  type: string
  지표:
   - ip
- 이름: status
  required: true
  type: bigint
- name: tag
  required: false
  type: string
- 이름: time
  required: true
  type: timestamp
  timeFormats: 
   - rfc3339
  isEventTime: true
- name: view_duration_s
  required: true
  type: float
```

{% endtab %}
{% endtabs %}

### `Dependabot은 종속성을 업데이트하기 위해 PR을 열 수 있습니다. 그러나 Dependabot은 리포지토리의 시크릿에 접근할 수 없습니다. 이는 API 시크릿이 필요한 GitHub 워크플로우(예:` 제한 사항

* 사용자를 사용할 것이며, `Dependabot은 종속성을 업데이트하기 위해 PR을 열 수 있습니다. 그러나 Dependabot은 리포지토리의 시크릿에 접근할 수 없습니다. 이는 API 시크릿이 필요한 GitHub 워크플로우(예:` 명령은 JSON 이벤트만 지원합니다.

## PAT를 통한 스키마 업로드

Panther Analysis Tool (PAT)을 통해 스키마를 업로드하는 방법에 대한 정보는 [Custom Logs: Panther Analysis Tool로 로그 스키마 업로드하기](https://docs.panther.com/ko/data-onboarding/custom-log-types#uploading-log-schemas-with-the-panther-analysis-tool).
