我正在尝试配置 logstash 以在 elasticsearch/kibana 中发送电子邮件警报和日志输出。
我已通过 rsyslog 成功同步日志,但运行时出现以下错误
/opt/logstash-1.4.1/bin/logstash 代理 -f /opt/logstash-1.4.1/logstash.conf --configtest
错误:在过滤器 { if [program] == "nginx-access" { 之后,第 23 行,第 12 列(字节 387)处预期为 #、{、,、] 之一
grok { match => [ "消息","%{IPORHOST:remote_addr} - %{USERNAME:remote_user} [%{HTTPDATE:time_local}] %{QS:request} %{INT:status} %{INT:body_bytes_sent} %{QS:http_referer} %{QS:http_user_agent}” ] } } }
输出 { stdout { } elasticsearch { embedded => false host => "
这是我的 logstash 配置文件
input {
syslog {
type => syslog
port => 5544
}
}
filter {
if [program] == "nginx-access" {
grok {
match => [ "message" , "%{IPORHOST:remote_addr} - %{USERNAME:remote_user} \[% {HTTPDATE:time_local}\] %{QS:request} %{INT:status} %{INT:body_bytes_sent} %{QS:http_referer} %{QS:http_user_agent}” ]
}
}
}
output {
stdout { }
elasticsearch {
embedded => false
host => "localhost"
cluster => "cluster01"
}
email {
from => "[email protected]"
match => [
"Error 504 Gateway Timeout", "status,504",
"Error 404 Not Found", "status,404"
]
subject => "%{matchName}"
to => "[email protected]"
via => "smtp"
body => "Here is the event line that occured: %{@message}"
htmlbody => "<h2>%{matchName}</h2><br/><br/><h3>Full Event</h3><br/><br/><div align='center'>%{@message}</div>"
}
}
我检查了错误中引用的第 23 行,它看起来很好......我尝试取出过滤器,一切正常......无需更改该行。
请帮忙
编辑
我现在将配置改为这样
input {
syslog {
type => syslog
port => 5544
}
}
filter {
grok {
type => "syslog"
match => ["syslog_program","nginx-access"]
match => [ "message","%{IPORHOST:remote_addr} - %{USERNAME:remote_user} \[%{HTTPDATE:time_local}\] %{QS:request} %{INT:status} %{INT:body_bytes_sent} %{QS:http_referer} %{QS:http_user_agent}" ]
add_field => [ "nginx_response", "%{NUMBER:response}" ]
}
}
output {
stdout {}
elasticsearch {
embedded => false
host => "localhost"
cluster => "cluster01"
}
email {
match => [ "status", "status,304"]
to => "[email protected]"
from => "[email protected]"
options => [ "smtpIporHost", "",
"port", "",
"userName", "",
"password", "",
"starttls", "",
"authenticationType", ""
]
via => "smtp" # or pop or sendmail
subject => "Found %{IP:client} Alert on %{@source_host}"
body => "Here is the event line %{@message}"
htmlbody => "<h2>%{matchName}</h2><br/><br/><h3>Full Event</h3><br/><br/><div align='center'>%{@message}</div>"
}
}
这似乎有效,据我所知,它现在可以识别 logstash 中的东西,并且那里有一个电子邮件插件命令,但匹配失败.....有什么想法吗?
谢谢
答案1
你不需要[program]
先解析吗?我认为“输入”字段根本不会进行任何形式的过滤,所以你可能需要先%SYSLOGBASE
http://logstash.net/docs/1.4.1/filters/grok
你或许可以尝试一下:
if [message] =~ /nginx-access/ {
哪个关键字会与您的message
领域相匹配。这至少会告诉您是否是这里发生了什么事。