#!/usr/bin/python
# -- coding:utf-8 --
""" 1、
2、"""import requests
import json
import sys
class wechat():
def __init__(self,corpid,corpsecret):
self.url = ""
self.corpid = corpid
self.corpsecret = corpsecret
#獲取access_token
def get_token(self):
token = "gettoken?corpid=&corpsecret=".format(url=self.url,corpid=self.corpid,corpsecret=self.corpsecret)
json_data = json.loads(requests.get(token).content.decode())
access_token = json_data["access_token"]
return access_token
#獲取傳送訊息
def send_message(self,user,agentid,subject,content):
send_url = "message/send?access_token=".format(url=self.url,access_token=self.get_token())
data = ,
"safe":0
}#傳送報警訊息
requests.post(send_url,json.dumps(data))
if __name__ == '__main__':
#abbix傳過來的第乙個引數
user = sys.ar**[1]
#zabbix傳過來的第二個引數
subject = str(sys.ar**[2])
#zabbix傳過來的第三個引數
content = str(sys.ar**[3])
wechat = wechat("ww3f7e13339beb9a1d","fwn9iyf9x8veetli7xgjrz40g3vot-na18lvce93edi")
#呼叫例項化的類的傳送資訊功能,其中agentid等於自建應用的agentid
wechat.send_message(user,1000002,subject,content)
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import smtplib
from email.mime.text import mimetext
class memcache_monitor():
def __init__(self):
pass
def send_mail(self,to_list, subject, content):
# 郵件位址的smtp位址
mail_host = 'smtp.exmail.qq.com'
# 用來發郵件的郵箱
mail_user = '******'
# 郵箱的密碼
mail_pass = '***xx'
# smtp位址的主**位址
mail_postfix = 'exmail.qq.com'
sender = "<@".format(name=mail_user, postfix=mail_postfix)
msg = mimetext(content, 'plain', 'utf-8')
# 必須使用'utf-8'引數,解決在部分郵件客戶端中文會顯示為亂碼
msg['subject'] = subject
msg['from'] = sender
msg['to'] = to_list
try:
smtpobj = smtplib.smtp()
smtpobj.connect(mail_host)
smtpobj.login(mail_user, mail_pass)
smtpobj.sendmail(sender, to_list, msg.as_string())
smtpobj.close()
print("傳送成功")
return true
except exception as e:
return false
zabbix郵件報警指令碼
zabbix郵件報警指令碼 對於目前的運營商來說,25埠基本上被禁用了,只能使用ssl tls加密協議來發收郵件,對於zabbix來說郵件報警還是比較常用的,下面為報警指令碼,親測時可以正常收到郵件的,可以先進行測試是否能正常收到郵件在正式配置到zabbix上。以163郵件為例 1 2 3 4 5 ...
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微信報警指令碼
bin bash script name weixin.sh send message from weixin for zabbix monitor cuiss v1 2016 01 01 cropid x secret x gurl purl function body n printf t sa...