基于Python实现简单的微信通知和预警

发布时间:2026-02-05 11:36:33

不止短信!教你用,基于Python实现简单的微信通知和预警,使用Python,python脚本实现微信告警,下面小编来给大家介绍一下,一起来了解一下吧!

基于Python实现简单的微信通知和预警

文章目录

导入数据

导入日期时间

导入请求

CORP_ID=' '

SECRET=' '

班级微信Pub:

s=requests.session()

def __init__(self):

self.token=self.get_token()

def get_token(self):

URL=f ' https://qyapi。微信。QQ。com/CGI-bin/gettoken?'公司ID={公司ID }公司机密={机密} '

rep=self.s.get(url)

if rep.status_code!=200:

打印("请求失败。")

返回

返回JSON。loads(代表内容)[' access _ token ']

定义发送消息(自身,内容):

网址='https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=' self.token

header={

内容类型' : '应用程序/json '

}

表单数据={

touser': '@all ',

甲方' : '甲方1 |甲方2 ',

totag': ' TagID1 | TagID2 ',

msgtype': 'textcard ',

agentid': 1000002,

textcard': {

标题' : '服务异常告警,

描述' :内容,

url': 'URL ',

btntxt': '更多'

},

保险箱: 0

}

rep=self.s.post(url,data=json.dumps(form_data))。encode('utf-8 '),headers=header)

if rep.status_code!=200:

打印("请求失败。")

返回

返回json.loads(重复内容)

微信=微信朋友圈()

now=datetime.datetime.now()

时间现在=现在。strftime(' % Y % m % d % h :% m :% S ')

我们聊天。send _ msg(f ' div class= ' gray ' { time now }/div div class= ' normal '服务中央处理器超过80%/divdiv class= '突出显示 '请尽快排查!/div’)

下载所需要的模块点安装请求

只要你的企业微信没有关闭通知的权限,那你的手机立马就会弹出这个告警信息,后期只要设置可见人员即可

以上就是基于Python实现简单的微信通知和预警的介绍,希望大家喜欢!

热门精选

大家正在看