代码之家  ›  专栏  ›  技术社区  ›  RCross

Logstash在字段中定义字段

  •  1
  • RCross  · 技术社区  · 7 年前

    grok有没有办法从已经定义的字段中保存字段?

    grok {
      match => [ "message", "\[%{TIMESTAMP_ISO8601:timestamp}\]\s+\[%{DATA:homebridge_app}\]\s+%{GREEDYDATA:log_message}" ]
    }
    

    这会导致“log_消息”中填充以下内容:

    Current temperature for Entryway Thermostat is: 20.5 C
    Current humidity for Entryway Thermostat is: 60%
    Current temperature for Entryway Thermostat is: 21 C
    Current temperature for Entryway Thermostat is: 21.5 C
    Current humidity for Entryway Thermostat is: 61%
    

    等等这里可能还有其他数据,但以上是我感兴趣的几行。

    我希望能够使用Kibana在图表上绘制湿度和温度与时间的关系,但我仍然希望log_消息包含如上所述的完整字符串。有没有办法保存log_消息字段中的整数,而不将该字段一分为二?

    1 回复  |  直到 7 年前
        1
  •  2
  •   baudsp Alain Collins    7 年前

    您可以在 log_message 字段:

    grok { 
        match => { "log_message" => [ 
            "%{NUMBER:humidity}%$", 
            "%{NUMBER:temperature} C$" 
        ] } }
    }
    

    看见 the grok plugin documentation :

    如果需要针对单个字段匹配多个模式,则 值可以是一组模式

    filter {
       grok {     
          match => { "message" => [ "Duration: %{NUMBER:duration}", "Speed: %{NUMBER:speed}" ] } 
       }
    }