2021년 4월 19일 월요일

Filebeat: mapper_parsing_exception

시계열 분석 기반이 마련됐으면 분석다운 분석을 위해 나머지 데이터도 성격별로 분리를 해보자.


host는 버리고, 세 개 필드로 분리.
processors:
  - drop_fields:
      fields: ["log", "input", "ecs", "host", "agent"]
  - dissect:
      tokenizer: "%{timestamp} %{+timestamp->} %{+timestamp} %{+timestamp} %{} %{process->} %{msg}"
      target_prefix: ""
  - timestamp:
      field: timestamp
      layouts:
        - '2006 Jan 2 15:04:05'
  - drop_fields:
      fields: ["timestamp", "message"]
{
  "@timestamp": "2010-01-09T17:31:21.000Z",
  "@metadata": {
    "beat": "filebeat",
    "type": "_doc",
    "version": "7.12.0"
  },
  "process": "sshd[1854]:",
  "msg": "Accepted password for root from 192.168.56.1 port 1939 ssh2"
}

잘 된다. 하지만 프로세스 필드는 프로세스명과 PID라는 두 가지 성격의 정보가 섞여 있다. 그대로 놔두면 망할테니 쪼개자.
processors:
  - drop_fields:
      fields: ["log", "input", "ecs", "host", "agent"]
  - dissect:
      tokenizer: "%{timestamp} %{+timestamp->} %{+timestamp} %{+timestamp} %{} %{process->} %{msg}"
      target_prefix: ""
  - if:
      contains.process: "[" 
    then:   
      - dissect:
          field: process
          target_prefix: ""
          overwrite_keys: true
          tokenizer: "%{process}[%{pid}]:"
    else:
      - dissect:
          field: process
          target_prefix: ""
          overwrite_keys: true
          tokenizer: "%{process}:"
  - timestamp:
      field: timestamp
      layouts:
        - '2006 Jan 2 15:04:05'
  - drop_fields:
      fields: ["timestamp", "message"]
{
  "@timestamp": "2010-01-09T17:31:21.000Z",
  "@metadata": {
    "beat": "filebeat",
    "type": "_doc",
    "version": "7.12.0"
  },
  "msg": "Accepted password for root from 192.168.56.1 port 1939 ssh2",
  "pid": "1854",
  "process": "sshd"
}

이제 엘라스틱에 저장. 그런데 데이터가 안 들어온다. filebeat 로그를 열어보니 process 필드를 만들 수 없다고?


원인은 ECS

엘라스틱은 세상 모든 데이터에서 성격은 같지만 이름이 다른, 그래서 상관분석(?)이 어려운 정보를 같은 이름의 필드로 통일하는 공통 스키마(Elastic Common Schema)를 beat에 반영한다.

공통 스키마에 이미 존재하는 process 필드와 충돌했다는 얘기. 이게 의도는 좋은데 문제는 beat를 이용하면 수천 개의 사용하지 않는 필드까지 포함된 스키마가 만들어져서 골치다. 필드 충돌 문제도 신경써야 하고, UI도 구려지고(..) 

필드 이름 바꾸면 잘 들어온다.
processors:
  - drop_fields:
      fields: ["log", "input", "ecs", "host", "agent"]
  - dissect:
      tokenizer: "%{timestamp} %{+timestamp->} %{+timestamp} %{+timestamp} %{} %{procs->} %{msg}"
      target_prefix: ""
  - if:
      contains.procs: "[" 
    then:   
      - dissect:
          field: procs
          target_prefix: ""
          overwrite_keys: true
          tokenizer: "%{procs}[%{pid}]:"
    else:
      - dissect:
          field: procs
          target_prefix: ""
          overwrite_keys: true
          tokenizer: "%{procs}:"
  - timestamp:
      field: timestamp
      layouts:
        - '2006 Jan 2 15:04:05'
  - drop_fields:
      fields: ["timestamp", "message"]

댓글 없음:

댓글 쓰기

크리에이티브 커먼즈 라이선스