当前位置:网站首页>钉钉告警脚本
钉钉告警脚本
2022-07-29 05:20:00 【JACK-JIE】
# -*- coding: utf-8 -*-
import time
import hmac
import hashlib
import base64
import urllib.parse
import requests
import json
import sys
import os
from email.mime.text import MIMEText
from email.header import Header
class dd:
def __init__(self, secret, url,atmobiles, mes):
self.timestamp = str(round(time.time() * 1000))
self.secret = secret
self.secret_enc = self.secret.encode('utf-8')
self.string_to_sign = '{}\n{}'.format(self.timestamp, self.secret)
self.string_to_sign_enc = self.string_to_sign.encode('utf-8')
self.hmac_code = hmac.new(self.secret_enc, self.string_to_sign_enc, digestmod=hashlib.sha256).digest()
self.sign = urllib.parse.quote_plus(base64.b64encode(self.hmac_code))
self.url = url
self.atmobiles = atmobiles
self.mes = mes
def req(self):
#把第二步中获取到的 timestamp和sign拼接到URL中
url = f'{self.url}'f'×tamp={self.timestamp}'f'&sign={self.sign}'
h = {'content-type': 'application/json', 'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:22.0) Gecko/20100101 Firefox/22.0'}
#d里面的at参数是需要at的人参数,只有at的人存在这个参数里面才会@成功
d = json.dumps({"msgtype": "text", "text": {"content": self.mes}, "at": {"atMobiles": self.atmobiles, "isAtAll": "false"}})
req = requests.post(url, data=d, headers=h)
print(req.text)
if __name__ == '__main__':
secret = '*************************90c8a5df55ba4b91f6451a7d' # 这里填的就是上面获取的加签**
url = 'https://oapi.dingtalk.com/robot/send?access_token=**********************************d138a8d6da841edaf34200b9f9710'
atmobiles = ["138xxxx0751","157xxxx1995"]
mes = '哈喽啊,树哥!'
dd = dd(secret, url, atmobiles, mes)
dd.req()
边栏推荐
- 熊市慢慢,Bit.Store提供稳定Staking产品助你穿越牛熊
- QT setting background image method
- 从Starfish OS持续对SFO的通缩消耗,长远看SFO的价值
- 运动健康深入人心,MOVE PROTOCOL引领品质生活
- DeFi 2.0的LaaS协议,重振DeFi赛道发展的关键
- DAY6:利用 PHP 编写文件上传页面
- Plato farm is expected to further expand its ecosystem through elephant swap
- 改哭了,终于解决了Cannot read properties of undefined (reading ‘parseComponent‘)
- 完全去中心化的编程模式,不需要服务器,也不需要ip,就像一张漫无目的的网络、四处延伸
- Starfish OS:以现实为纽带,打造元宇宙新范式
猜你喜欢
运动健康深入人心,MOVE PROTOCOL引领品质生活
The Platonic metauniverse advocated by musk has long been verified by platofarm
Starfish OS: create a new paradigm of the meta universe with reality as the link
识变!应变!求变!
第五空间智能安全⼤赛真题----------PNG图⽚转换器
DAO赛道异军突起,M-DAO的优势在哪里?
Novice introduction: download from PHP environment to thinkphp6 framework by hand
“山东大学移动互联网开发技术教学网站建设”项目实训日志二
Fantom (FTM) 在 FOMC会议之前飙升 45%
Flink connector Oracle CDC 实时同步数据到MySQL(Oracle19c)
随机推荐
Laravel service container (Application of context binding)
Crypto巨头们ALL IN元宇宙,PlatoFarm或能突围
php写一个购买全网最低价的纸尿裤
全闪分布式,如何深度性能POC?
“山东大学移动互联网开发技术教学网站建设”项目实训日志七
第五空间智能安全⼤赛真题----------PNG图⽚转换器
Elastic box flex
微信内置浏览器禁止缓存的问题
DAY4:MySQL 数据库的建立及简单实用
Differences between href and SRC
Plato farm is expected to further expand its ecosystem through elephant swap
量化开发必掌握的30个知识点【什么是分笔逐笔数据】?
与张小姐的春夏秋冬(4)
DAY4:SQL Sever 简单使用
Laravel服务容器(继承与事件)
DAY14:Upload-labs 通关教程
IDEA使用JDBC连接MySQL数据库个人详细教程
超简单集成HMS ML Kit 人脸检测实现可爱贴纸
Laravel Swagger添加访问密码
Go|Gin 快速使用Swagger