Python脚本
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Author: JiuCheng
import requests
import json
import sys
import os
def msg(message):
url = ‘https://oapi.dingtalk.com/robot/send?access_token=9096de5bb1602b0878797c9f53209e29ac29f7ee39bf497b1cea401ca09635a3’
HEADERS = {
“Content-Type”: “application/json ;charset=utf-8”
}
String_textMsg = {
“msgtype”: “text”,
“text”: {“content”: message},
“at”: {
“atMobiles”: [
“130xxxxxxxx” #如果需要@某人,这里写他的手机号
],
“isAtAll”: 0 #如果需要@所有人,这里写1
}
}
String_textMsg = json.dumps(String_textMsg)
res = requests.post(url, data=String_textMsg, headers=HEADERS)
print(res.text)
if __name__ == ‘__main__’:
text = sys.argv[3]
msg(text)
sh脚本
#!/bin/bash
to=$1
subject=$2
text=$3
curl -i -X POST \
‘https://oapi.dingtalk.com/robot/send?access_token=9096de5bb1602b0878797c9f53209e29ac29f7ee39bf497b1cea401ca09635a3’ \
-H ‘Content-type’:’application/json’ \
-d ‘
{
“msgtype”: “text”,
“text”: {
“content”: “‘监控报警a:””$text”‘”
},
“at”:{
“atMobiles”:[
“‘”$1″‘”
],
“isAtAll”:false
}
}’