当前位置:网站首页>钉钉告警脚本
钉钉告警脚本
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()边栏推荐
猜你喜欢

Dao race track is booming. What are the advantages of m-dao?

以‘智’提‘质|金融影像平台解决方案

Laravel服务容器(继承与事件)

华为2020校招笔试编程题 看这篇就够了(下)

超简单集成HMS ML Kit 实现parental control

Okaleido Tiger 7.27日登录Binance NFT,首轮已获不俗成绩

Plato Farm有望通过Elephant Swap,进一步向外拓展生态

极致通缩和永动机模型,将推动 PlatoFarm 爆发

Bare metal cloud FASS high performance elastic block storage solution

Day14: upload labs customs clearance tutorial
随机推荐
Breaking through the hardware bottleneck (I): the development of Intel Architecture and bottleneck mining
使用Qss设置窗体样式
Fantom (FTM) prices will soar by 20% in the next few days
第五空间智能安全⼤赛真题----------PNG图⽚转换器
Fvuln-自动化web漏洞检测工具
dcat 批量操作弹窗及参数传递
加密资产熊市之下,PlatoFarm的策略玩法依旧能获得稳定收益
DAY14:Upload-labs 通关教程
Shanzhai coin Shib has a US $548.6 million stake in eth whale's portfolio - traders should be on guard
量化开发必掌握的30个知识点【什么是Level-2数据】
XDFS&空天院HPC集群典型案例
Go|Gin 快速使用Swagger
Thinkphp6管道模式Pipeline使用
浅谈分布式全闪存储自动化测试平台设计
Fantom (FTM) 价格将在未来几天飙升 20%
Countdown of the uniapp component (such as the countdown to reading the agreement and the countdown to completing learning)
运动健康深入人心,MOVE PROTOCOL引领品质生活
闪贷Dapp的调研及实现
Fvuln automated web vulnerability detection tool
Flink connector Oracle CDC 实时同步数据到MySQL(Oracle12c)