在自己服务器上写个python脚本 然后推送到企业微信上 就能每天查看服务器状态了
agentid / corpsecret / corpid 这几个参数值都可以在上面图片中找到
useridlist 是可以发给多个用户的 可以在应用 服务》》可见范围中的名字 将鼠标放上就可以看到账号名
推送消息的模板有 纯文本 有图片加文本等具体看一下文档
cpuU diskU memU 是传过来的值 (例如 :pusht.py $cpuU $diskU $memU)
import datetime import json import sys import requests def send_message_QiYeVX(useridlist=['ChenHao']): # 默认发送给自己 now_time = datetime.datetime.now() time1 = datetime.datetime.now().strftime('%Y-%m-%d %H:%M') var = sys.argv cpuU=var[1] diskU=var[2] memU=var[3]+"%" # print(var[1]) useridstr = "|".join(useridlist) agentid = 'xxx' corpid = 'xxx' corpsecret = 'xxx' response = requests.get(f"https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid={corpid}&corpsecret={corpsecret}") data = json.loads(response.text) access_token = data['access_token'] json_dict = { "touser": useridstr, "msgtype": "textcard", "agentid": agentid, "textcard": { "title": "服务器状态", "description": "<div class=\"gray\">"+time1+"</div>" "<div class=\"normal\">cpu使用:"+cpuU+"</div><div class=\"normal\">内存使用:"+memU+"</div>" "<div class=\"highlight\">硬盘使用:"+diskU+"</div>", "url": "https://ikownthat.com", "btntxt": "更多" }, "safe": 0, "enable_id_trans": 0, "enable_duplicate_check": 0, "duplicate_check_interval": 1800 } json_str = json.dumps(json_dict) response_send = requests.post(f"https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={access_token}", data=json_str) return json.loads(response_send.text)['errmsg'] == 'ok' send_message_QiYeVX()
推送到手机上的效果(我只推了这三个参数)