Python Simplemonitor不会在发出警报时发送电子邮件;可能的配置错误

问题描述 投票:0回答:1

我正在设置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
[email protected]
[email protected]

以及定义what我正在监视的monitors.ini文件:

[test-check]
type=http
url=http://www.test.com:8080/hello
tolerance=1

我正在使用simplemonitor --config monitor.ini &>> monitor.log &运行它。

鉴于我只是开始使用它,所以我不确定这是由于代码错误还是由于设置错误而导致的。

编辑:我觉得很傻。该错误是由于monitor.ini文件中的错字所致。我会在host变量中拼写smtp服务器的名称。现在,它发送了一封电子邮件。对于任何麻烦,我深表歉意。

python email url configuration monitor
1个回答
0
投票

正如我在原始问题的编辑中所说,这是由于int文件中输入了smtp服务器名称的错字,位于host中。对于造成的任何麻烦,我深表歉意。

© www.soinside.com 2019 - 2024. All rights reserved.