zabbix郵件報警指令碼

2021-09-29 20:52:34 字數 3353 閱讀 9486

指令碼一

sendemail.sh

#!/bin/bash

logfile=

"/tmp/email.log"

:>

"$logfile"

exec 1>

"$logfile"

exec 2>

&1smtp_server=

'smtp.163.com'

#改為自己163郵箱位址

username=

'***@163.com'

#改為自己163郵箱的授權碼

password=

'***'

#改為自己163郵箱位址

from_email_address=

'***@163.com'

to_email_address=

"$1"

message_subject_utf8=

"$2"

message_body_utf8=

"$3"

# 轉換郵件標題為gb2312,解決郵件標題含有中文,收到郵件顯示亂碼的問題。

message_subject_gb2312=

`iconv -t gb2312 -f utf-8 <<

eof$message_subject_utf8

eof`

[$? -eq 0 ]

&& message_subject=

"$message_subject_gb2312"

|| message_subject=

"$message_subject_utf8"

# 轉換郵件內容為gb2312,解決收到郵件內容亂碼

message_body_gb2312=

`iconv -t gb2312 -f utf-8 <<

eof$message_body_utf8

eof`

[$? -eq 0 ]

&& message_body=

"$message_body_gb2312"

|| message_body=

"$message_body_utf8"

# 傳送郵件

sendemail=

'/usr/local/bin/sendemail'

set -x

$sendemail -s "$smtp_server" -xu "$username" -xp "$password" -f "$from_email_address" -t "$to_email_address" -u "$message_subject" -m "$message_body" -o message-content-type=text -o message-charset=gb2312

指令碼二

sendmail_zabbix.py

#!/usr/bin/python

# -*- coding: utf-8 -*-

import smtplib

import sys

from email.mime.text import mimetext

from email.header import header

def send_mail(to_email, subject, message):

sender =

'***@163.com'

receiver = to_email

subject =

'python email test'

smtpserver =

'smtp.163.com'

username =

'***@163.com'

password =

'***'

msg = mimetext(message, 'plain', 'utf-8'

) msg[

'subject'

]= subject

msg[

'from'

]= sender

msg[

'to'

]= receiver

smtp = smtplib.smtp(

) smtp.connect(smtpserver)

smtp.login(username, password)

smtp.sendmail(sender, to_email, msg.as_string(

)) smtp.quit(

)if __name__ ==

'__main__'

: send_mail(sys.ar**[1], sys.ar**[2], sys.ar**[3]

)

指令碼三

sendmail_zabbix_ssl.py(加密的)

#!/usr/bin/python

# _*_ coding:utf-8 _*_

import smtplib, sys

from email.mime.text import mimetext

from email.utils import formataddr

def send_mail(to_email, subject, message):

# 郵箱位址和郵箱密碼

my_sender =

'***@163.com'

my_pass =

'***'

my_user = to_email

# 傳送郵件的資訊主體,發件人,收件人,內容

msg = mimetext(message, 'plain', 'utf-8'

) msg[

'from'

]= formataddr(

["zabbix", my_sender]

) msg[

'to'

]= formataddr(

["ops", my_user]

) msg[

'subject'

]= subject

# 傳送郵件

server = smtplib.smtp_ssl(

"smtp.163.com", 465)

server.login(my_sender, my_pass)

server.sendmail(my_sender, [my_user, ], msg.as_string(

)) server.quit(

)if __name__ ==

'__main__'

: send_mail(sys.ar**[1], sys.ar**[2], sys.ar**[3]

)

zabbix郵件報警指令碼

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

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...