I. Overview and ENVIRONMENTAL requirements
1. Overview
Zabbix monitoring also plays an important role, following the use of Python scripts to send alert mail configuration methods. Previously used SendEmail mail alarm but found that the subject of the message will be garbled when the Chinese language.
2, environmental installation requirements
Zabbix software version: zabbix3.2.6
Operating system: CentOS release 6.8 (Final)
Second, script creation and testing
1, check the configuration zabbix_server.conf, find the Alertscriptspath, look at the path location, such as being commented, open the note, the send.py file saved to the directory.
Grep-n ' ^[a-z] '/usr/local/etc/zabbix_server.conf
38:logfile=/tmp/zabbix_server.log
87:dbname=zabbix
103:dbuser=zabbix
111:dbpassword=zabbix
126:dbport=3306
239:startvmwarecollectors=10
247:vmwarefrequency=60
255:vmwareperffrequency=60
265:vmwarecachesize=80m
273:vmwaretimeout=10
281:snmptrapperfile=/tmp/zabbix_traps.tmp
289:startsnmptrapper=0
407:timeout=4
448:alertscriptspath=/usr/local/share/zabbix/alertscripts
492:logslowqueries=3000
2, if there is modification configuration, you need to restart the Zabbix-server service.
/etc/init.d/zabbix_server restart
3. Enter the Zabbix e-mail script directory
Cd/usr/local/share/zabbix/alertscripts
4. Create Scripts and configurations
Vim zabbix-mail.py
#!/usr/bin/python
#coding: Utf-8
Import Smtplib
From Email.mime.text import Mimetext
Import Sys
Mail_host = ' smtp.qq.com '
Mail_user = ' 10880347 '
Mail_pass = ' ********** '
Mail_postfix = ' qq.com '
def send_mail (to_list,subject,content):
me = "zabbix3.2 Monitoring alarm Platform" + "<" +mail_user+ "@" +mail_postfix+ ">"
msg = mimetext (content, ' plain ', ' utf-8 ')
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])
5. Add executable permissions
chmod +x zabbix-mail.py
Chown-r Zabbix.zabbix zabbix-mail.py
6. Test Mail
Python zabbix-mail.py [email protected] test test
650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M01/99/40/wKioL1lGZ7uSICFcAAAVLUTL1r8546.png "title=" QQ picture 20170618184713.png "alt=" Wkiol1lgz7usicfcaaavlutl1r8546.png "/>
Third, Zabbix server alarm Media type
1. Web interface settings
http://172.16.8.200/zabbix/
Add three parameters
{ALERT. SENDTO} recipient Address
{ALERT. SUBJECT} topics
{ALERT. MESSAGE} Detailed content
650) this.width=650; "src=" Https://s1.51cto.com/wyfs02/M02/99/41/wKiom1lGZ96RG_FHAAEA-7nYDCg460.jpg "title=" QQ picture 20170618185459.jpg "alt=" Wkiom1lgz96rg_fhaaea-7nydcg460.jpg "/>
2. Create an alarm user
650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M01/99/41/wKioL1lGaEDAp0ttAAENcIy-O80467.jpg "title=" QQ picture 20170618190350.jpg "alt=" Wkiol1lgaedap0ttaaenciy-o80467.jpg "/>
3. Configure the Alarm media
650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M02/99/41/wKiom1lGaFCD0OfEAAD2ipf7Xg4525.jpg "title=" QQ picture 20170618190502.jpg "alt=" Wkiom1lgafcd0ofeaad2ipf7xg4525.jpg "/>
4. Configure permissions
Now test the environment so configure Super Admin permissions, if the production environment recommends using user rights
650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M02/99/41/wKiom1lGaGiB3gnCAAD2ipf7Xg4378.jpg "title=" QQ picture 20170618190502.jpg "alt=" Wkiom1lgagib3gncaad2ipf7xg4378.jpg "/>
Iv. Configuring Alarm Actions
1. Create a new trigger action
650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M00/99/41/wKiom1lGaIfA5K5uAAF8NH2-wJQ257.jpg "title=" QQ picture 20170618192110.jpg "alt=" Wkiom1lgaifa5k5uaaf8nh2-wjq257.jpg "/>
2. Configure the action
650) this.width=650; "src=" Https://s1.51cto.com/wyfs02/M02/99/41/wKioL1lGaQCy0BKwAAEX6Ke2LTQ752.jpg "title=" QQ picture 20170618191627.jpg "alt=" Wkiol1lgaqcy0bkwaaex6ke2ltq752.jpg "/>
3. Configuration operation
Fault {TRIGGER. STATUS}, server: {HOSTNAME1} occurred: {Trigger.name} failed!
Alarm host: {HOSTNAME1}
Alarm time: {EVENT. DATE} {EVENT. TIME}
Alarm level: {TRIGGER. SEVERITY}
Warning message: {trigger.name}
Alarm item: {TRIGGER. KEY1}
Problem Details: {item.name}:{item. VALUE}
Current status: {TRIGGER. Status}:{item. VALUE1}
Event Id:{event.id}
650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M01/99/41/wKioL1lGaRLR3XIWAAGY4LVWgOA474.jpg "title=" QQ picture 20170618192339.jpg "alt=" Wkiol1lgarlr3xiwaagy4lvwgoa474.jpg "/>
4. Configure Recovery operations
Restore {TRIGGER. STATUS}, server: {HOSTNAME1}: {trigger.name} restored!
Alarm host: {HOSTNAME1}
Alarm time: {EVENT. DATE} {EVENT. TIME}
Alarm level: {TRIGGER. SEVERITY}
Warning message: {trigger.name}
Alarm item: {TRIGGER. KEY1}
Problem Details: {item.name}:{item. VALUE}
Current status: {TRIGGER. Status}:{item. VALUE1}
Event Id:{event.id}
650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M00/99/41/wKiom1lGaSOhK0w1AAFRMtpO6hc436.jpg "title=" QQ picture 20170618192803.jpg "alt=" Wkiom1lgasohk0w1aafrmtpo6hc436.jpg "/>
5. Email Alarm test Results
650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M00/99/41/wKioL1lGaTOTvnvOAAD-28x7sbE044.png "title=" QQ picture 20170618192935.png "alt=" Wkiol1lgatotvnvoaad-28x7sbe044.png "/>
650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M01/99/41/wKioL1lGaUOwfn6TAABMZG7Q1Qk716.png "title=" QQ picture 20170618193015.png "alt=" Wkiol1lgauowfn6taabmzg7q1qk716.png "/>
This article is from the "Think" blog, make sure to keep this source http://10880347.blog.51cto.com/346720/1939532
Zabbix3.2 Mail Alert Python script