Zabbix Custom Email sending script (Python)

Source: Internet
Author: User

1. How to add Zabbix: Manage -- Solution -- create media type

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/122H0C46-0.png "border =" 0 "alt =" "/>

Zabbix sends three parameters to the script: recipient, subject, and content.

Zabbix_sendmail.py

 
 
  1. #!/usr/bin/python 
  2. #coding:utf-8 
  3.  
  4.  
  5. import smtplib 
  6. from email.mime.text import MIMEText 
  7. import sys 
  8.  
  9. mail_host = 'smtp.163.com' 
  10. mail_user = 'username' 
  11. mail_pass = 'password' 
  12. mail_postfix = '163.com' 
  13.  
  14. def send_mail(to_list,subject,content): 
  15.     me = mail_user+"<"+mail_user+"@"+mail_postfix+">" 
  16.     msg = MIMEText(content) 
  17.     msg['Subject'] = subject 
  18.     msg['From'] = me 
  19.     msg['to'] = to_list 
  20.      
  21.     try: 
  22.         s = smtplib.SMTP() 
  23.         s.connect(mail_host) 
  24.         s.login(mail_user,mail_pass) 
  25.         s.sendmail(me,to_list,msg.as_string()) 
  26.         s.close() 
  27.         return True 
  28.     except Exception,e: 
  29.         print str(e) 
  30.         return False 
  31.      
  32. if __name__ == "__main__": 
  33.     send_mail(sys.argv[1], sys.argv[2], sys.argv[3]) 

2. Add trigger settings: System Configuration-operation-create action

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/122H062Y-1.png "border =" 0 "alt =" "/>

 

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/122H0C53-2.png "border =" 0 "alt =" "/>

 

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/122H04193-3.png "border =" 0 "alt =" "/>

3. Add the script configuration to zabbix_server:

Mkdir-p/usr/local/zabbix/scripts

Upload the script to this directory.

Modify zabbix_server.conf:

AlertScriptsPath =/usr/local/zabbix/scripts

Then restart the service.

The configuration is complete. It's easy !~

 

 

This article is from the "O & M notes" blog, please be sure to keep this source http://lihuipeng.blog.51cto.com/3064864/1066915

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.