

# 알림 로그용 테이블 생성 및 쿼리
<a name="querying-network-firewall-logs-sample-alert-logs-table"></a>

1. 다음 샘플 DDL 문을 알림 로그의 구조에 맞게 수정하세요. 최신 버전 로그의 열을 포함하도록 문을 업데이트해야 할 수 있습니다. 자세한 내용은 *AWS Network Firewall 개발자 안내서*의 [방화벽 로그의 내용](https://docs.aws.amazon.com/network-firewall/latest/developerguide/firewall-logging.html#firewall-logging-contents)을 참조하세요.

   ```
   CREATE EXTERNAL TABLE network_firewall_alert_logs (
     firewall_name string,
     availability_zone string,
     event_timestamp string,
     event struct<
       timestamp:string,
       flow_id:bigint,
       event_type:string,
       src_ip:string,
       src_port:int,
       dest_ip:string,
       dest_port:int,
       proto:string,
       app_proto:string,
       sni:string,
       tls_inspected:boolean,
       tls_error:struct<
         error_message:string>,
       revocation_check:struct<
         leaf_cert_fpr:string,
         status:string,
         action:string>,
       alert:struct<
         alert_id:string,
         alert_type:string,
         action:string,
         signature_id:int,
         rev:int,
         signature:string,
         category:string,
         severity:int,
         rule_name:string,
         alert_name:string,
         alert_severity:string,
         alert_description:string,
         file_name:string,
         file_hash:string,
         packet_capture:string,
         reference_links:array<string>
       >, 
       src_country:string, 
       dest_country:string, 
       src_hostname:string, 
       dest_hostname:string, 
       user_agent:string, 
       url:string
      >
   )
    ROW FORMAT SERDE 'org.openx.data.jsonserde.JsonSerDe'
    LOCATION 's3://amzn-s3-demo-bucket/{{path_to_alert_logs_folder}}/';
   ```

1. `LOCATION` 절을 수정하여 Amazon S3의 로그 폴더를 지정합니다.

1. Athena 쿼리 편집기에서 사용자의 `CREATE TABLE` 쿼리를 실행합니다. 쿼리가 완료된 후 Athena는 `network_firewall_alert_logs` 테이블을 등록하여 쿼리 준비를 나타내는 데이터를 만듭니다.

## 예제 쿼리
<a name="querying-network-firewall-logs-alert-log-sample-query"></a>

이 섹션의 샘플 알림 로그 쿼리는 TLS 검사가 수행된 이벤트 중 심각도 수준이 2 이상인 알림이 있는 이벤트를 필터링합니다.

쿼리는 별칭을 사용하여 해당 열이 속한 `struct`를 보여주는 출력 열 제목을 생성합니다. 예를 들어 `event.alert.category` 필드의 열 제목은 `event_alert_category`이며 그냥 `category`가 아닙니다. 열 이름을 추가로 사용자 지정하려면 원하는 대로 별칭을 수정할 수 있습니다. 예를 들어 밑줄이나 기타 구분 기호를 사용하여 `struct` 이름과 필드 이름을 구분할 수 있습니다.

테이블 정의와 쿼리 결과에 표시할 필드를 기반으로 열 이름과 `struct` 참조를 수정해야 합니다.

```
SELECT 
  firewall_name,
  availability_zone,
  event_timestamp,
  event.timestamp AS event_timestamp,
  event.flow_id AS event_flow_id,
  event.event_type AS event_type,
  event.src_ip AS event_src_ip,
  event.src_port AS event_src_port,
  event.dest_ip AS event_dest_ip,
  event.dest_port AS event_dest_port,
  event.proto AS event_protol,
  event.app_proto AS event_app_proto,
  event.sni AS event_sni,
  event.tls_inspected AS event_tls_inspected,
  event.tls_error.error_message AS event_tls_error_message,
  event.revocation_check.leaf_cert_fpr AS event_revocation_leaf_cert,
  event.revocation_check.status AS event_revocation_check_status,
  event.revocation_check.action AS event_revocation_check_action,
  event.alert.alert_id AS event_alert_alert_id,
  event.alert.alert_type AS event_alert_alert_type,
  event.alert.action AS event_alert_action,
  event.alert.signature_id AS event_alert_signature_id,
  event.alert.rev AS event_alert_rev,
  event.alert.signature AS event_alert_signature,
  event.alert.category AS event_alert_category,
  event.alert.severity AS event_alert_severity,
  event.alert.rule_name AS event_alert_rule_name,
  event.alert.alert_name AS event_alert_alert_name,
  event.alert.alert_severity AS event_alert_alert_severity,
  event.alert.alert_description AS event_alert_alert_description,
  event.alert.file_name AS event_alert_file_name,
  event.alert.file_hash AS event_alert_file_hash,
  event.alert.packet_capture AS event_alert_packet_capture,
  event.alert.reference_links AS event_alert_reference_links,
  event.src_country AS event_src_country,
  event.dest_country AS event_dest_country,
  event.src_hostname AS event_src_hostname,
  event.dest_hostname AS event_dest_hostname,
  event.user_agent AS event_user_agent,
  event.url AS event_url
FROM 
  network_firewall_alert_logs 
WHERE 
  event.alert.severity >= 2
  AND event.tls_inspected = true 
LIMIT 10;
```