当前位置:网站首页>钉钉告警脚本
钉钉告警脚本
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()
边栏推荐
- dcat 批量操作弹窗及参数传递
- 运动健康深入人心,MOVE PROTOCOL引领品质生活
- 使用Qss设置窗体样式
- Flink connector Oracle CDC 实时同步数据到MySQL(Oracle19c)
- “山东大学移动互联网开发技术教学网站建设”项目实训日志五
- 剑指核心-TaoCloud全闪SDS助力构建高性能云服务
- Fvuln-自动化web漏洞检测工具
- Bare metal cloud FASS high performance elastic block storage solution
- Countdown of the uniapp component (such as the countdown to reading the agreement and the countdown to completing learning)
- Changed crying, and finally solved cannot read properties of undefined (reading 'parsecomponent')
猜你喜欢
随机推荐
Novice introduction: download from PHP environment to thinkphp6 framework by hand
Use QSS to style the form
Common prompt pop-up box of uniapp
完全去中心化的编程模式,不需要服务器,也不需要ip,就像一张漫无目的的网络、四处延伸
Move protocol global health declaration, carry out the health campaign to the end
Sliding switch of tab of uniapp component
What is nmap and how to use it
裸金属云FASS高性能弹性块存储解决方案
Masscan tutorial
中海油集团,桌面云&网盘存储系统应用案例
赓续新征程,共驭智存储
The bear market is slow, and bit.store provides stable stacking products to help you get through the bull and bear market
“山东大学移动互联网开发技术教学网站建设”项目实训日志六
深度学习的趣味app简单优化(适合新手)
一文读懂Move2Earn项目——MOVE
量化开发必掌握的30个知识点【什么是Level-2数据】
D3.JS 纵向关系图(加箭头,连接线文字描述)
QT layout management -- Part stretch principle and sizepolicy
iSCSI vs iSER vs NVMe-TCP vs NVMe-RDMA
超简单集成HMS ML Kit 人脸检测实现可爱贴纸