# Zabbix 自定义邮件发送脚本(Python)
# Zabbix添加处理方法:管理——处理方法——create media type
zabbix会传给脚本三个参数:接收用户,邮件主题,邮件内容
脚本名称zabbix_sendmail.py
#!/usr/bin/python
#coding:utf-8
import smtplib
from email.mime.text import MIMEText
import sys
mail_host = 'smtp.163.com'
mail_user = 'username'
mail_pass = 'password'
mail_postfix = '163.com'
def send_mail(to_list,subject,content):
me = mail_user+"<"+mail_user+"@"+mail_postfix+">"
msg = MIMEText(content)
msg['Subject'] = subject
msg['From'] = me
msg['to'] = to_list
try:
s = smtplib.SMTP()
s.connect(mail_host)
s.login(mail_user,mail_pass)
s.sendmail(me,to_list,msg.as_string())
s.close()
return True
except Exception,e:
print str(e)
return False
if __name__ == "__main__":
send_mail(sys.argv[1], sys.argv[2], sys.argv[3])
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# 添加触发设置:系统配置——操作——create action
# zabbix_server添加脚本配置
mkdir -p /usr/local/zabbix/scripts
- 把脚本上传到该目录
修改zabbix_server.conf
配置:
AlertScriptsPath=/usr/local/zabbix/scripts
然后重启服务
# zabbix_server添加脚本配置:
mkdir -p /usr/local/zabbix/scripts
把脚本上传到该目录
修改zabbix_server.conf配置:
AlertScriptsPath=/usr/local/zabbix/scripts
然后重启服务