作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在创建一个logstash grok过滤器,以将事件从备份服务器中拉出,并且我希望能够测试某个字段的模式,如果它与该模式匹配,则进一步处理该字段并提取其他信息。
为此,我将if
语句嵌入grok
语句本身。这导致在Error: Expected one of #, =>
之后,测试失败并显示if
失败。
这是过滤器语句:
filter {
grok {
patterns_dir => "./patterns"
# NetWorker logfiles have some unusual fields that include undocumented engineering codes and what not
# time is in 12h format (ugh) so custom patterns need to be used.
match => [ "message", "%{NUMBER:engcode1} %{DATESTAMP_12H:timestamp} %{NUMBER:engcode2} %{NUMBER:engcode3} %{NUMBER:engcode4} %{NUMBER:ppid} %{NUMBER:pid} %{NUMBER:engcode5} %{WORD:processhost} %{WORD:processname} %{GREEDYDATA:daemon_message}" ]
# attempt to find completed savesets and pull that info from the daemon_message field
if [daemon_message] =~ /done\ saving\ to\ pool/ {
grok {
match => [ "daemon_message", "%{WORD:savehost}\:%{WORD:saveset} done saving to pool \'%{WORD:pool}\' \(%{WORD:volume}\) %{WORD:saveset_size}" ]
}
}
}
date {
# This is requred to set the time from the logline to the timestamp and not have it create it's own.
# Note the use of the trailing 'a' to denote AM or PM.
match => ["timestamp", "MM/dd/yyyy HH:mm:ss a"]
}
}
$ /opt/logstash/bin/logstash -f ./networker_daemonlog.conf --configtest
Error: Expected one of #, => at line 12, column 12 (byte 929) after # Basic dumb simple networker daemon log grok filter for the NetWorker daemon.log
# no smarts to this and not really pulling any useful info from the files (yet)
filter {
grok {
... lines deleted ...
# attempt to find completed savesets and pull that info from the daemon_message field
if
grok
语句中使用条件处理,但是我更喜欢对其他
match
行使用这种条件处理,因为这样会保留daemon_message字段以供其他用途,同时提取取出我想要的数据。
if
语句可以使configtest通过,而过滤器可以解析日志。
最佳答案
条件过滤器位于过滤器之外,因此类似:
if [field] == "value" {
grok {
...
}
]
grok {
match => [ "message", "%{NUMBER:engcode1} %{DATESTAMP_12H:timestamp} %{NUMBER:engcode2} %{NUMBER:engcode3} %{NUMBER:engcode4} %{NUMBER:ppid} %{NUMBER:pid} %{NUMBER:engcode5} %{WORD:processhost} %{WORD:processname} %{GREEDYDATA:daemon_message}" ]
}
if [daemon_message] =~ /done\ saving\ to\ pool/ {
grok {
match => [ "daemon_message", "%{WORD:savehost}\:%{WORD:saveset} done saving to pool \'%{WORD:pool}\' \(%{WORD:volume}\) %{WORD:saveset_size}" ]
}
}
grok {
match => [ "message", "%{NUMBER:engcode1} %{DATESTAMP_12H:timestamp} %{NUMBER:engcode2} %{NUMBER:engcode3} %{NUMBER:engcode4} %{NUMBER:ppid} %{NUMBER:pid} %{NUMBER:engcode5} %{WORD:processhost} %{WORD:processname} %{GREEDYDATA:daemon_message}" ]
}
grok {
match => [ "daemon_message", "%{WORD:savehost}\:%{WORD:saveset} done saving to pool \'%{WORD:pool}\' \(%{WORD:volume}\) %{WORD:saveset_size}" ]
}
关于logtash if grok语句中的语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29046055/
我正在创建一个logstash grok过滤器,以将事件从备份服务器中拉出,并且我希望能够测试某个字段的模式,如果它与该模式匹配,则进一步处理该字段并提取其他信息。 为此,我将if语句嵌入grok语句
我是一名优秀的程序员,十分优秀!