【发布时间】:2016-05-20 17:16:14
【问题描述】:
我在 CentOS 6 中设置了运行 elasticsearch 的 logstash 1.4,2。我想要一种简单的方法来在日志中发生典型错误时发送电子邮件,我从不同的日志文件中挑选日志。在 logstash 在线文档中,我找到了仅最新版本 2.0 的示例。而且我不想要在我的情况下不起作用的 gmail 示例。 我还需要启用电子邮件插件还是直接将其添加到logstash conf文件中?
感谢您的帮助。
【问题讨论】:
我在 CentOS 6 中设置了运行 elasticsearch 的 logstash 1.4,2。我想要一种简单的方法来在日志中发生典型错误时发送电子邮件,我从不同的日志文件中挑选日志。在 logstash 在线文档中,我找到了仅最新版本 2.0 的示例。而且我不想要在我的情况下不起作用的 gmail 示例。 我还需要启用电子邮件插件还是直接将其添加到logstash conf文件中?
感谢您的帮助。
【问题讨论】:
您好,我之前在 logstash-1.4.2 上工作过,最近更新到 2.0,并且我已经实现了电子邮件插件。我将与本地 smtp 的电子邮件设置分享一个示例 conf 文件。
input {
file {
type => 'file'
path => '/home/tech/apache-tomcat-7.0.54/logs/em.log'
start_position => beginning
}
}
filter {
if [type] == "file" {
grok {
# The grok filter will use the below pattern and on successful match use
# any captured values as new fields in the event.
match => { 'message' => '([\w\.]*(ERROR|Exception))' }
}
}
}
#here is the output will be displayed in Kibana and on ERROR it will send notification
output {
elasticsearch { host => localhost }
if "ERROR" in [message] {
email {
options => [ "smtpIporHost", "YOUR-SMTP-IP",
"port", "25"
]
from => "<myemail@example.com>"
subject => "Logstash alert on Error "
to => "recipeint@example.com"
via => "smtp"
body => "Here is the event line that occured: %{message} %{@timestamp} %{host}"
htmlbody => "<h2 align='center'>%{host}</h2><br/><h3>Details</h3><br/><div align='center' style='color:red'>%{message}</div><div align='center'>%{@timestamp}</div><div align='center'>%{@version}</div>"
}
}
stdout { codec => rubydebug }
}
首先您需要检查电子邮件插件是否已安装 logstash-1.4.2/lib/logstash/outputs/email.rb 如果它不存在,您可以通过运行此命令来安装它。 ./bin/plugin 安装贡献
如果你有插件设置,现在你可以测试脚本。 ./bin/logstash -f my-logstash.conf
它会向您显示一些警告并阅读日志文件,如果有错误将通过电子邮件发送。 每当此文件发生更改时,它将读取。
如果您需要任何详细信息来测试此样本,请告诉我。
【讨论】: