如何在SMTP中设置logstash 1.4.2电子邮件插件而不进行身份验证

时间:2016-02-10 11:20:23

标签: email logstash

我在CentOS 6中设置了使用elasticsearch运行的logstash 1.4,2。我想在日志中发生典型错误时发送电子邮件的简单方法,我从不同的日志文件中选择日志。在logstash docs online中,我发现了最新版本的示例,即2.0。我不希望gmail示例在我的情况下不起作用。 还有一件事我需要启用电子邮件插件还是直接将其添加到logstash conf文件中?

感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

您好我曾在最近更新到2.0的logstash-1.4.2上工作,并且我已经实现了电子邮件插件。我将与本地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 /输出/ email.rb 如果不存在,则可以通过运行此命令来安装它。         ./bin/plugin install contrib

如果你有插件设置,现在你可以测试脚本。 ./bin/logstash -f my-logstash.conf

它会显示很少的警告并读取日志文件,如果错误将在电子邮件中发送。 每当这个文件发生变化时,它都会被读取。

如果您需要任何细节来测试此样本,请与我们联系。