python钉钉机器人运维脚本监控实例

阅读 123 收藏 0 点赞 0 评论 0

如下所示:

#!/usr/bin/python3
# -*- coding:UTF-8-*-
# Author: zhuhongqiang
 
from urllib import request
import json
from sys import argv
 
access_token = "xxx"
 
 
def send_msg(mobile, item_name):
  """
   钉钉机器人API接口地址:
   https://open-doc.dingtalk.com/docs/doc.htm?spm=a219a.7629140.0.0.karFPe&treeId=257&articleId=105735&docType=1
   :param mobile:
   :param itemName:
   :return:
  """
  url = "https://oapi.dingtalk.com/robot/send?access_token=" + access_token
 
  data = {
    "msgtype": "text",
    "text": {
      "content": item_name
    },
    "at": {
      "atMobiles": [
        mobile
      ],
      "isAtAll": "false"
    }
  }
  # 设置编码格式
  json_data= json.dumps(data).encode(encoding='utf-8')
  print(json_data)
  header_encoding = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Trident/7.0; rv:11.0) like Gecko', "Content-Type": "application/json"}
  req = request.Request(url=url, data=json_data, headers=header_encoding)
  res = request.urlopen(req)
  res = res.read()
  print(res.decode(encoding='utf-8'))
 
 
if __name__ == "__main__":
  mobile = argv[1]
  item_name = argv[2]
  send_msg(mobile, item_name)

以上这篇python钉钉机器人运维脚本监控实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持面圈教程。

声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:mianshige#126.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。

评论列表


问题


面经


文章

微信
公众号

扫码关注公众号