欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Python釘釘報(bào)警及Zabbix集成釘釘報(bào)警的示例代碼

 更新時(shí)間:2020年08月17日 14:44:07   作者:you-men  
這篇文章主要介紹了Python釘釘報(bào)警及Zabbix集成釘釘報(bào)警的示例代碼,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

釘釘報(bào)警設(shè)置

創(chuàng)建群機(jī)器人

接口地址

發(fā)送短消息

發(fā)送普通消息

import requests
import json

url = 'https://oapi.dingtalk.com/robot/send?access_token=71638980426c030'

headers = {
 "Content-Type": "application/json",
 "Chartset": "utf-8"
}
# 要發(fā)送的文本是json格式
request_data = {
 # 此消息的類型為固定的text
 "msgtype": "text",

 "text": {
  # 消息的內(nèi)容
  "content": "大家新年快樂test"
 },
 "at": {
  # 被@人的手機(jī)號
  "atMobiles": [],
  # 控制@所有人
  "isAtAll": True
 }
}
# 把json轉(zhuǎn)變?yōu)樽址袷綌?shù)據(jù)
send_data = json.dumps(request_data)
# 這個(gè)是發(fā)送post請求,請求釘釘接口
response = requests.post(url=url, headers=headers, data=send_data)
# 講求成功后返回的數(shù)據(jù)
content = response.content.decode()
# 打印
# 課程 vip 標(biāo)準(zhǔn)
# 替換 視頻
print(content)

接口開發(fā)

修改結(jié)構(gòu)

import requests
import json
import sys

url = 'https://oapi.dingtalk.com/robot/send?access_token=71389c030'

def WriteLogByDing(content):
 headers = {

  "Content-Type": "application/json",
  "Chartset": "utf-8"
 }
 request_data = {
  "msgtype": "text",
  "text": {
   "content": content
  },
  "at": {
   "atMobiles": [],
   "isAtAll": True

  }

 }

 sendData = json.dumps(request_data)
 response = requests.post(url=url, headers=headers, data=sendData)
 content = response.content.decode()
 print(content)


if __name__ == "__main__":
 content = input('請輸入想要的信息: ')
 content += "test"
 # content = sys.argv[1]
 WriteLogByDing(content)

發(fā)送帶鏈接的文檔

import requests
import json

url = 'https://oapi.dingtalk.com/robot/send?access_token=7164d45fa912dc12ed721522371ecf7428ad912740e87a63c3bf38980426c030'

headers = {
 "Content-Type": "application/json",
 "Chartset": "utf-8"
}

# 要發(fā)送的文本是json格式
request_data = {

 # 發(fā)送鏈接類型的數(shù)據(jù)
 "msgtype": "link",
 "link": {

  # 鏈接提示
  "text": "群機(jī)器人是釘釘群的高級擴(kuò)展功能。群機(jī)器人可以將第三方服務(wù)的信息聚合到群聊中,實(shí)現(xiàn)自動(dòng)化的信息同步。例如:通過聚合GitHub,GitLab等源碼管理服務(wù),實(shí)現(xiàn)源碼更新同步;通過聚合Trello,JIRA等項(xiàng)目協(xié)調(diào)服務(wù),實(shí)現(xiàn)項(xiàng)目信息同步。不僅如此,群機(jī)器人支持Webhook協(xié)議的自定義接入,支持更多可能性,例如:你可將運(yùn)維報(bào)警提醒通過自定義機(jī)器人聚合到釘釘群。",

  # 鏈接標(biāo)題
  "title": "自定義機(jī)器人協(xié)議test",
  # 圖片url地址
  "picUrl": "http://p3.so.qhmsg.com/sdr/200_200_/t013d7a21145c708288.jpg",
  # 信息的鏈接跳轉(zhuǎn)
  "messageUrl": "http://www.zcj.net.cn"
 }
}

# 把json轉(zhuǎn)變?yōu)樽址袷綌?shù)據(jù)
send_data = json.dumps(request_data)

# 這個(gè)是發(fā)送post請求,請求釘釘接口
response = requests.post(url=url, headers=headers, data=send_data)

# 講求成功后返回的數(shù)據(jù)
content = response.content.decode()

# 打印
# 課程 vip 標(biāo)準(zhǔn)
# 替換 視頻
print(content)

發(fā)送makedown

import requests
import json

url = 'https://oapi.dingtalk.com/robot/send?access_token=7164d45fa912dc12ed721522371ecf7428ad912740e87a63c3bf38980426c030'

headers = {

 "Content-Type": "application/json",
 "Chartset": "utf-8"
}

# 要發(fā)送的文本是json格式
request_data = {
 "msgtype": "markdown",
 "markdown": {"title": "杭州天氣",
     "text": "#### 杭州天氣 \n > 9度, 西北風(fēng)1級,空氣良89,相對溫度73%\n\n > ![screenshot](http://i01.lw.aliimg.com/media/lALPBbCc1ZhJGIvNAkzNBLA_1200_588.png)\n > ###### 10點(diǎn)20分發(fā)布 [天氣](http://www.thinkpage.cn/) test"
     },
 "at": {
  "atMobiles": [],
  "isAtAll": False
 }

}

# 把json轉(zhuǎn)變?yōu)樽址袷綌?shù)據(jù)
send_data = json.dumps(request_data)
# 這個(gè)是發(fā)送post請求,請求釘釘接口
response = requests.post(url=url, headers=headers, data=send_data)
# 講求成功后返回的數(shù)據(jù)
content = response.content.decode()
# 打印
print(content)

zabbix集成釘釘報(bào)警

釘釘報(bào)警python腳本

https://ding-doc.dingtalk.com/doc#/serverapi2/qf2nxq

http://www.dbjr.com.cn/article/193470.htm

#!/usr/bin/env python
#coding:utf-8
#zabbix釘釘報(bào)警
import requests,json,sys,os,datetime
webhook="https://oapi.dingtalk.com/robot/send?access_token=ce0d39251"
user=sys.argv[1]
text=sys.argv[3]
data={
 "msgtype": "text",
 "text": {
  "content": "test"
 },
 "at": {
  "atMobiles": [
  # user
  ],
  "isAtAll": False
 }
}
headers = {'Content-Type': 'application/json'}
x=requests.post(url=webhook,data=json.dumps(data),headers=headers)
if os.path.exists("/usr/local/zabbix_server/logs/dingding.log"):
 f=open("/usr/local/zabbix_server/logs/dingding.log","a+")
else:
 f=open("/usr/local/zabbix_server/logs/dingding.log","w+")
f.write("\n"+"--"*30)
if x.json()["errcode"] == 0:
 f.write("\n"+str(datetime.datetime.now())+" "+str(user)+" "+"發(fā)送成功"+"\n"+str(text))
 f.close()
else:
 f.write("\n"+str(datetime.datetime.now()) + " " + str(user) + " " + "發(fā)送失敗" + "\n" + str(text))
 f.write(str(x)+str(x.json()))
 f.close()

到此這篇關(guān)于Python釘釘報(bào)警及Zabbix集成釘釘報(bào)警的示例代碼的文章就介紹到這了,更多相關(guān)Python釘釘報(bào)警 內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論