zabbix 发送不了邮件

  1. 网上找到一个脚本sendmail.py

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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/python
# -*- coding:utf-8 -*-
   
import  smtplib
import  sys
from  email.mime.text  import  MIMEText
import  time
#reload(sys)
#sys.setdefaultencoding('utf8')
current_time = time.strftime( '%Y-%m-%d%H:%M' ,time.localtime(time.time()))
   
mail_host  = 'smtp.163.com'
mail_user  = 'xxx@163.com'
mail_pwd  =  'xxxxxx'
   
def  send_email( content,mailto, get_sub ):
     #msg = MIMEText( content.encode('utf8'),_subtype = 'html', _charset = 'utf8')
     msg  =  MIMEText(content,_subtype = 'plain' ,_charset = 'utf8' )
     msg[ 'From' =  mail_user
     msg[ 'Subject' = get_sub
     msg[ 'To' =  "," .join( mailto )
     
     try :
         =  smtplib.SMTP(mail_host,  25 )       
         s.login(mail_user, mail_pwd )
         s.sendmail(mail_user, mailto,msg.as_string())
         s.close()
     except  Exception as e:
         print  'Exception: ' , e
   
title = sys.argv[ 2 ]
cont = """
---------------------------------
摘要:  %s
---------------------------------
时间:  %s
---------------------------------
   
""" % (sys.argv[ 3 ],current_time)
   
   
to_list  =  [
          '%s' % (sys.argv[ 1 ]),
         ]
   
'''withopen('/tmp/sendmail_qs.log','ab') as f:
         f.write('%s  Receive address:  %s Title: %s \n'%(current_time,sys.argv[1],title))
'''
send_email( cont, to_list,title)

sendmail.py脚本权限 755或者777,owner zabbix

测试 ./sendmail.py $to $subject $messages

2.添加脚本

wKioL1Ul8qvxFZIIAAJXoLqsIC0290.jpg

3.设置触发条件

wKiom1Ul8BnB2THeAAHVqpHxdUg997.jpg

4.设置故障恢复后的报警时间,一般是间隔5分钟,你可以修改为60s

wKiom1Ul8E-RzsInAAJzPClP9yw457.jpg



本文转自 liqius 51CTO博客,原文链接:http://blog.51cto.com/szgb17/1630366,如需转载请自行联系原作者

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值