我收到了这个日志信息。 I've got this log message, which I ship to the elasticsearch:
Jul 23 09:24:16 mmr mmr-core[5147]: Aweg3AOMTs_1563866656876839.mt GetProvider_v4
我把它发到了elasticsearch上
我想用logstash过滤器来解析它,然后把Aweg3AOMTs_1563866656876839.mt的id字段改成Aweg3AOMTs_1563866656876839.mt,但我不想涉及字母或其他字符,而只在id中加入数字。
我已经做了这么多。
%{SYSLOGTIMESTAMP:logtimestamp} %{HOSTNAME:hostname} %{DATA:type} %{USERNAME:id} %{GREEDYDATA:rest}
"logtimestamp": "Jul 23 09:24:16",
"hostname": "mmr",
"id": "Aweg3AOMTs_1563866656876839.mt",
"type": "mmr-core[5147]:"
我怎么才能跳过id字段中的字母和字符?
谢谢大家的帮助!
据我所知,你想要的只是其中的 1563866656876839
在你 id
领域?你可以把 Aweg3AOMTs_1563866656876839.mt
字符串分为三个字段。id_prefix
, id
和 id_suffix
然后 去掉 你不需要的部分。
模式尝试在 Grok调试器:
%{SYSLOGTIMESTAMP:logtimestamp}\s%{HOSTNAME:hostname}\s%{DATA:type}\s%{USERNAME:id_prefix}_%{NUMBER:id}\.%{GREEDYDATA:id_suffix}\s%{GREEDYDATA:rest}
Logstash配置。
# logstash.conf
…
filter {
grok {
match => {
"message" => "%{SYSLOGTIMESTAMP:logtimestamp}\s%{HOSTNAME:hostname}\s%{DATA:type}\s%{USERNAME:id_prefix}_%{NUMBER:id}\.%{GREEDYDATA:id_suffix}\s%{GREEDYDATA:rest}"
}
}
mutate {
remove_field => ["id_prefix", "id_suffix"]
}
}
…