Zabbix 郵件報警設置

自定義腳本,腳本使用python 寫的代碼如下

#!/usr/bin/env python
#-*- coding:utf-8 -*-
import smtplib
import sys
to_addr=sys.argv[1]
subject_header=sys.argv[2]
body=sys.argv[3]
def Sendmail(to_addr='[email protected]',subject_header='Test',body='This is just for test'):
        subject_header = 'Subject:' + subject_header + '\r'
        mail_server = 'smtp.163.com'
        mail_server_port = 25
        from_addr = '[email protected]'
        from_header = 'From:%s\r' %from_addr
        smtp = smtplib.SMTP()
        smtp.connect(mail_server,mail_server_port)
        smtp.login('mencomonitor','yourpassord')
        to_header = 'To:%s\r' % to_addr
        email_message = '%s\n%s\n%s\n\r\n%s' %(from_header,to_header,subject_header,body)
        smtp.sendmail(from_addr, to_addr, email_message)
        smtp.quit()
if __name__ == '__main__':
        Sendmail(to_addr = to_addr,subject_header = subject_header, body = body)


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章