zabbix郵件報警指令碼

2021-09-20 22:26:25 字數 3272 閱讀 4880

zabbix郵件報警指令碼

對於目前的運營商來說,25埠基本上被禁用了,只能使用ssl/tls加密協議來發收郵件,對於zabbix來說郵件報警還是比較常用的,下面為報警指令碼,親測時可以正常收到郵件的,可以先進行測試是否能正常收到郵件在正式配置到zabbix上。以163郵件為例:

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

[root@localhost ~]# cat zabbix_mail.py

#!/usr/bin/python

# coding=utf-8

#zabiix 郵件報警指令碼

#測試方法:python zabbix_mail.py ******[email protected] test test

#能正常傳送郵件說明成功

importsmtplib

importsys

from email.mime.textimportmimetext

class send_mail():

mail_host="smtp.163.com"

mail_user="*********[email protected]"

#注:此地方的密碼為pop3/smtp/imap客戶端授權的授權碼,不是郵箱的登入密碼

mail_pass="*********x"

mail_postfix="163.com"

def __init__(self,sub,content):

self.me="zabbix-alter"+"<"+self.mail_user+"@"+self.mail_postfix+">"

self.msg = mimetext(content,_subtype='html',_charset='utf-8')

self.msg['from'] = self.me

self.msg['subject'] = sub

def sendmessage(self,user):

self.msg['to'] =";".join(user)

try:

s = smtplib.smtp_ssl(host=self.mail_host,port=465)

s.login(self.mail_user,self.mail_pass)

s.sendmail(self.me, user, self.msg.as_string())

#傳送郵件

s.close()

except exception, e:

print str(e)

if__name__ =='__main__':

mailto_list=

s = send_mail(sys.ar**[2],sys.ar**[3])

s.sendmessage(mailto_list)

zabbix郵件報警指令碼

指令碼一 sendemail.sh bin bash logfile tmp email.log logfile exec 1 logfile exec 2 1smtp server smtp.163.com 改為自己163郵箱位址 username 163.com 改為自己163郵箱的授權碼 pa...

zabbix郵件報警指令碼 簡單版

配置zabbix主配置檔案 新增報警媒介 usr bin env python coding utf8 script name sendmail.py import smtplib import sys smtp server smtp.sina.com smtp伺服器,我用的是sina的,所以是s...

zabbix郵件報警

常完美的選擇 使用簡單並且功能強大.這個被設計用在php bash perl和web站點使用。以上是sendemail的簡單介紹,千萬不要和sendmail搞混掉了。1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 root server wget root server ta...