【发布时间】:2020-04-10 19:48:49
【问题描述】:
我正在设置 simplemonitor,找到 here,以检查我的 web 服务的 url。如果任何检查失败,则应发送电子邮件警报。
到目前为止,我已经确认显示器工作正常。但是,当我关闭服务以检查电子邮件警报时,发送电子邮件时出错:
2020-04-10 20:03:00 WARNING (simplemonitor) monitor failed but within tolerance: test-check
2020-04-10 20:03:10 ERROR (simplemonitor) monitor failed: test-check (Requests exception while opening URL: HTTPConnectionPool(host='www.test.com', port=8080): Max retries exceeded with url: /hello (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fef7c8762e8>: Failed to establish a new connection: [Errno 111] Connection refused',)))
2020-04-10 20:03:10 ERROR (simplemonitor.alerter-email) couldn't send mail
Traceback (most recent call last):
File "/anaconda/envs/test/envs/alertenv/lib/python3.5/site-packages/simplemonitor/Alerters/mail.py", line 127, in send_alert
server = smtplib.SMTP(self.mail_host, self.mail_port)
File "/anaconda/envs/test/envs/alertenv/lib/python3.5/smtplib.py", line 251, in __init__
(code, msg) = self.connect(host, port)
File "/anaconda/envs/test/envs/alertenv/lib/python3.5/smtplib.py", line 336, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "/anaconda/envs/test/envs/alertenv/lib/python3.5/smtplib.py", line 307, in _get_socket
self.source_address)
File "/anaconda/envs/test/envs/alertenv/lib/python3.5/socket.py", line 712, in create_connection
raise err
File "/home/user/anaconda3/envs/test/lib/python3.5/socket.py", line 703, in create_connection
sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused
这里是设置规则的monitor.ini文件:
[monitor]
monitors=/home/user/monitor/monitors.ini
interval=10
[reporting]
loggers=logfile
alerters=email
[logfile]
type=logfile
filename=monitor.log
only_failures=1
[email]
type=email
host=host.domain.com
from=simplemonitor@company.com
to=user@company.com
还有定义我正在监控的什么的monitors.ini文件:
[test-check]
type=http
url=http://www.test.com:8080/hello
tolerance=1
我正在使用simplemonitor --config monitor.ini &>> monitor.log & 运行它。
鉴于我才开始使用它,我不确定这是由于代码中的错误,还是由于设置错误造成的。
编辑:我觉得很傻。该错误是由于 monitor.ini 文件中的拼写错误造成的。我在主机变量中拼错了 smtp 服务器的名称。它现在发送了一封电子邮件。对于任何打扰,我深表歉意。
【问题讨论】:
标签: python email url configuration monitor