当前位置:网站首页>钉钉告警脚本
钉钉告警脚本
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()边栏推荐
- 打印出1-100之间的所有质数
- 获取水仙花数
- 与张小姐的春夏秋冬(3)
- Laravel service container (Application of context binding)
- Display effect of uniapp page title
- 麦当娜“Hellbent”购买130万美元的nft无聊猿,现在被认为太贵了
- 量化开发必掌握的30个知识点【什么是Level-2数据】
- Changed crying, and finally solved cannot read properties of undefined (reading 'parsecomponent')
- WIN10 编译ffmpeg(包含ffplay)
- Gluster集群管理小分析
猜你喜欢

Sports health is deeply rooted in the hearts of the people, and move protocol leads quality life

微信内置浏览器禁止缓存的问题

量化开发必掌握的30个知识点【什么是Level-2数据】

Thinkphp6管道模式Pipeline使用

Some opportunities for young people in rural brand building

“山东大学移动互联网开发技术教学网站建设”项目实训日志一

新手入门:手把手从PHP环境到ThinkPHP6框架下载

Xsan is highly available - xdfs and San are integrated with new vitality

“山东大学移动互联网开发技术教学网站建设”项目实训日志五

使用Qss设置窗体样式
随机推荐
DAO赛道异军突起,M-DAO的优势在哪里?
Seay source code audit system
裸金属云FASS高性能弹性块存储解决方案
PHP如何生成二维码?
Fantom (FTM) 在 FOMC会议之前飙升 45%
DAY5:PHP 简单语法与使用
C# 连接 SharepointOnline WebService
QT setting background image method
Xsan is highly available - xdfs and San are integrated with new vitality
如何在加密市场熊市中生存?
The bear market is slow, and bit.store provides stable stacking products to help you get through the bull and bear market
Sliding switch of tab of uniapp component
学习、研究编程之道
Starfish OS: create a new paradigm of the meta universe with reality as the link
浅谈分布式全闪存储自动化测试平台设计
“山东大学移动互联网开发技术教学网站建设”项目实训日志三
Win10 搭建MSYS2环境
DAY4:SQL Sever 简单使用
Okaleido tiger logged into binance NFT on July 27, and has achieved good results in the first round
Go|Gin 快速使用Swagger