簡體   English   中英

在Logstash過濾器中解釋Keen.io JSON文件中的位置

[英]Interpret locations from Keen.io JSON file in logstash filter

我正在嘗試將帶有logstash的Keen.io的JSON文件解析為elasticsearch。 位置和時間戳存儲在這樣的參數中:

{
  "result":
  [
    {
      "keen":
      {
        "timestamp": "2014-12-02T12:23:51.000Z",
        "created_at": "2014-12-01T23:25:31.396Z",
        "id": "XXXX",
        "location":
        {
          "coordinates": [-95.8, 36.1]
        }
      }
    }
  ]
}

我的過濾器當前如下所示:

input {
  file {
    path => ["test.json"]
    start_position => beginning
    type => json
  }
}

filter {
  json {
    source => message
    remove_field => message
  }
}

output {
  stdout { codec => rubydebug }
}

如何解析“ timestamp”和“ location”字段,以便將它們用於Elasticsearch中的@timestamp和@ geoip.coordinates?

更新:我已經嘗試過這種變化,沒有運氣。 該文檔非常基礎-我是否誤解了如何引用JSON字段? 有沒有添加調試輸出以幫助的方法? 我嘗試過如何 使用Logstash 1.4 調試logstash文件插件 並向stdout打印字符串? 但都行不通。

filter {
  json {
    source => message
    remove_field => message
  }
  if ("[result][0][keen][created_at]") {
    date {
      add_field => [ "[timestamp]", "[result][0][keen][created_at]" ]
      remove_field => "[result][0][keen][created_at]"
    }
  }

更新2:

日期正在工作,仍然需要使位置工作。

filter {
  json {
    source => message
    remove_field => message
    add_tag => ["valid_json"]
  }
  if ("valid_json") {
    if ("[result][0][keen][created_at]") {
      date {
        match => [ "[result][0][keen][created_at]", "ISO8601" ]
      }
    }
  }
}

Keen.io的“ created_at”字段以ISO 8601格式存儲,因此可以通過日期過濾器輕松解析。 可以通過將Keen.io的現有坐標復制到logstash的geoip.coordinates數組中來設置緯度/經度坐標。

input {
  file {
    path => ["data.json"]
    start_position => beginning
    type => json
  }
}

filter {
  json {
    source => message
    remove_field => message
    add_tag => ["valid_json"]
  }
  if ("valid_json") {
    if ("[result][0][keen][created_at]") {
      date {
        # Set @timestamp to Keen.io's "created_at" field
        match => [ "[result][0][keen][created_at]", "ISO8601" ]
      }
    }
    if ("[result][0][keen][location][coordinates]") {
      mutate {
        # Copy existing co-orndiates into geoip.coordinates array
        add_field => [ "[geoip][coordinates]", "%{[result][0][keen][location][coordinates][0]}" ]
        add_field => [ "[geoip][coordinates]", "%{[result][0][keen][location][coordinates][1]}" ]
        remove_field => "[result][0][keen][location][coordinates]"
      }
    }
  }
}

output {
  stdout { codec => rubydebug }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM