9

我正在创建一个需要为某些特定日志发送邮件的应用程序。这是我的规则文件:

es_host: localhost
es_port: 9200
name: Log Level Test
type: frequency
index: testindexv4
num_events: 1
timeframe:
   hours: 4
filter:
 - term:
     log_level.keyword: "ERROR"
 - query:
     query_string:
       query: "log_level.keyword: ERROR"
alert:
- "email"
email:
- "<mailId>@gmail.com"

这是 config.yaml

rules_folder: myrules
run_every:
  seconds: 2
buffer_time:
  seconds: 10
es_host: localhost
es_port: 9200
writeback_index: elastalert_status
alert_time_limit:
  days: 2

这是 smpt_auth.yaml

alert:
 - email
email:
 - "<mailId>@gmail.com"
smtp_host: "smtp.gmail.com" 
smtp_port: 587 
smtp_ssl: true
from_addr: "<mailId>@gmail.com"
smtp_auth_file: 'D:\ELK_Info\ElastAlert\elastalert-master\smtp_auth_user.yaml'

这是 smtp_auth_user.yaml

user: "<mailId>@gmail.com"
password: "<password>"

当我运行这个命令时:

python -m elastalert.elastalert --verbose --rule myrules\myrule.yaml

我收到一个错误:

ERROR:root: Error while running alert email: Error connecting to SMTP host: [Errno 10061] No connection could be made because the target machine actively refused it.

请问有什么办法解决这个问题吗?

4

3 回答 3

3

请尝试检查以下链接:

https://stackoverflow.com/a/36532619/5062759

据我了解,完全不建议使用 Gmail 发送电子邮件。它是有限制的,所以如果你是为生产服务(尤其是日志)做的,你会很快达到上限。我相信亚马逊的 SES 系统会为开发人员提供积分,因此您可以对其进行修改,或者如果您真的喜欢 Google,您可以使用:https ://cloud.google.com/appengine/docs/standard/go/mail/ 。

于 2018-09-22T08:40:36.650 回答
2

默认情况下,sendemail 命令尝试使用 localhost 作为 SMTP 服务器,并忽略用于计划搜索警报的设置。如果您没有安装 SMTP 服务器或转发器(在 Windows 上很可能),sendemail则在尝试连接到 localhost 时将失败。

要解决此问题,请在 sendemail 中指定服务器,如下所示:

my search terms | sendemail to=foo@bar.com sendresults=true server=mail.bar.com

于 2018-09-25T16:07:58.793 回答
0

您可以尝试将 smtp_auth.yaml 中的 smtp_host 设置为本地 smtp 主机(电子邮件服务器)。您的管理员可以帮助您解决一个问题。

于 2018-09-27T05:57:36.537 回答