2025년 9월 7일 일요일

Logstash 필터 date - 4th

DB 데이터 연동.
[2025-09-07T11:06:48,019][INFO ][logstash.agent           ] Pipelines running {:count=>1, :running_pipelines=>[:main], :non_running_pipelines=>[]}
[2025-09-07T11:07:00,219][INFO ][logstash.inputs.jdbc     ][main][d56fa9ad43d4dc4ae19f64f322de33854c6e9d33b5fc7c06354603bf613db2ee] (0.001000s)
select a.cid, a.timestamp, b.sig_name, inet_ntoa(c.ip_src), inet_ntoa(c.ip_dst), unhex(d.data_payload)
from event a, signature b, iphdr c, data d
where a.signature = b.sig_id
and a.sid = c.sid and a.cid = c.cid
and a.sid = d.sid and a.cid = d.cid
and a.cid > 0

{
      "inet_ntoa(c.ip_src)" => "192.168.31.230",
                 "sig_name" => "sql-injection-and",
                 "@version" => "1",
                "timestamp" => 2018-01-08T04:54:52.000Z,
    "unhex(d.data_payload)" => #<Sequel::SQL::Blob:0xad0 bytes=190 start="GET /s?ie=" end="t: */*\r\n\r\n">,
                      "cid" => 4,
               "@timestamp" => 2025-09-07T02:07:00.232Z,
      "inet_ntoa(c.ip_dst)" => "119.63.197.151"
}

로그스태시가 데이터를 가져온 시간인 @timestamp와 데이터의 원본 시간인 timestamp의 포맷이 똑같은 ISO8601이다. 그래서 엘라스틱은 둘 다 시간 필드로 인식함. 굳이 date 필터 작업을 안 해도 된다는 얘기. 

%{+yyyy.MM.dd} 등의 구문을 사용해서 시간 정보 활용을 시도하면 @timestamp에 접근하기 때문에 헷갈리기 싫으면 그냥 date 필터 작업을 해주는 게 낫다.
filter {
 date {
  match => ["timestamp", "ISO8601"]
 }
}

그런데 안 됨(..)
{
      "inet_ntoa(c.ip_src)" => "192.168.31.230",
                 "sig_name" => "sql-injection-and",
                 "@version" => "1",
                "timestamp" => 2018-01-08T04:54:47.000Z,
    "unhex(d.data_payload)" => #<Sequel::SQL::Blob:0xbb4 bytes=351 start="GET /s?ie=" end="t: */*\r\n\r\n">,
                      "cid" => 1,
                     "tags" => [
        [0] "_dateparsefailure"
    ],
               "@timestamp" => 2025-09-07T02:10:00.041Z,
      "inet_ntoa(c.ip_dst)" => "119.63.197.139"
}

date 필터가 ISO8601 포맷을 해석하지 못하는 모양. date 필터를 걸기 전에 먼저 문자열로 바꿔줘야 한다.
filter {
 mutate {
  convert => {"timestamp" => "string"}
 }

 date {
  match => ["timestamp", "ISO8601"]
 }
}
{
      "inet_ntoa(c.ip_src)" => "192.168.31.230",
                 "sig_name" => "sql-injection-and",
                 "@version" => "1",
                "timestamp" => "2018-01-08T04:55:12.000Z",
    "unhex(d.data_payload)" => #<Sequel::SQL::Blob:0xcbe bytes=264 start="GET /s?ie=" end="t: */*\r\n\r\n">,
                      "cid" => 5,
               "@timestamp" => 2018-01-08T04:55:12.000Z,
      "inet_ntoa(c.ip_dst)" => "119.63.197.151"
}

댓글 없음:

댓글 쓰기

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