利用钉钉的群机器人功能,即时发送告警信息
作者:邓聪聪
[root@cacti ~]# more dingding.py #!/usr/bin/env python #-*- coding: utf-8 -*- import os import sys import json import datetime import requests txt=open('/tmp/message.txt','r') #打开文本文件 msg=txt.read() #读取文本文件内容 def info(): url = 'https://oapi.dingtalk.com/robot/send?access_token=XXX' headers = { 'Content-Type': 'application/json;charset=utf-8' } formdata = { "msgtype": "text", "text": {"content":str(msg)} } post = requests.post(url=url, data=json.dumps(formdata), headers=headers) print post.text if __name__ == '__main__': info() txt.close() #关闭文本文件