以下是使用Python连接163邮箱的Zabbix 4.4.10配置步骤:

  1. 安装Python邮件库

使用以下命令安装Python邮件库:

pip install secure-smtplib
  1. 配置Zabbix SMTP设置

在Zabbix管理界面,转到“Administration”>“Media types”>“Email”>“SMTP设置”,输入以下信息:

SMTP服务器:smtp.163.com SMTP端口:465 SMTP身份验证:启用 SMTP安全连接:SSL / TLS SMTP用户名:您的163邮箱地址 SMTP密码:您的163邮箱密码

  1. 创建Zabbix脚本

在Zabbix服务器上创建一个Python脚本,例如“sendmail.py”,并复制以下代码:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.mime.application import MIMEApplication

def send_email(username, password, recipient, subject, body, attachment=None):
    msg = MIMEMultipart()
    msg['From'] = username
    msg['To'] = recipient
    msg['Subject'] = subject
    msg.attach(MIMEText(body, 'plain'))

    if attachment != None:
        with open(attachment, "rb") as f:
            attach = MIMEApplication(f.read(), _subtype="pdf")
            attach.add_header('Content-Disposition', 'attachment', filename=str(attachment))
            msg.attach(attach)

    smtp_server = "smtp.163.com"
    smtp_port = 465
    smtp_username = username
    smtp_password = password

    smtp = smtplib.SMTP_SSL(smtp_server, smtp_port)
    smtp.login(smtp_username, smtp_password)
    smtp.sendmail(username, recipient, msg.as_string())
    smtp.quit()

if __name__ == "__main__":
    send_email("your163email@163.com", "your163emailpassword", "recipient@example.com", "Test email", "This is a test email", "test.pdf")

请注意,您需要将您的163电子邮件地址和密码替换为“smtp_username”和“smtp_password”。

  1. 测试Zabbix脚本

在Zabbix服务器上打开终端,切换到脚本所在的目录并运行以下命令:

python sendmail.py

如果一切正常,您应该会收到一封带有附件的测试电子邮件。

  1. 配置Zabbix通知

在Zabbix管理界面中,转到“Configuration”>“Actions”>“报警操作”,单击“新建操作”,输入操作名称和条件,并在“操作”选项卡中选择“发送电子邮件”作为操作类型。在“发送电子邮件”选项卡中,输入收件人电子邮件地址,主题和正文,并将“Send to”设置为“Custom script”。在“Custom script”字段中,输入以下命令:

/usr/bin/python /path/to/sendmail.py {ALERT.SENDTO} {ALERT.SUBJECT} {ALERT.MESSAGE} {ALERT.ATTACHMENT}

确保将“/ path / to / sendmail.py”替换为脚本的实际路径。

  1. 保存并测试Zabbix通知

单击“添加操作”以保存操作,然后创建一个测试触发器以测试通知是否正常工作。

至此,您已成功配置了Zabbix 4.4.10以使用Python连接163邮箱。

zabbix 4410 用Python连接163邮箱配置

原文地址: https://www.cveoy.top/t/topic/brhn 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录