淺談Python 釘釘報警必備知識系統(tǒng)講解
本章所講內(nèi)容:
1、釘釘報警設(shè)置
2、釘釘報警腳本運行。
1、釘釘報警設(shè)置
釘釘,關(guān)于webhook的報警需求,釘釘報警也是我們在公司中常見的報警系統(tǒng),在這里主要是結(jié)合zabbix二次開發(fā)使用,來達(dá)到完美報警的使用。
1.1、釘釘報警第一步,創(chuàng)建群機器人
接口地址:
https://oapi.dingtalk.com/robot/send?access_token=a25324cafc5b0f2bb239b5e56c71e7f378f570a3d281160dbec9e4f8c4a7e493
文檔地址:
1.2 發(fā)送信信息
1.2.1 發(fā)送@所有人的消息
1、發(fā)送普通的消息
import requests import json url = 'https://oapi.dingtalk.com/robot/send?access_token=a25324cafc5b0f2bb239b5e56c71e7f378f570a3d281160dbec9e4f8c4a7e493 ' headers = { "Content-Type": "application/json", "Chartset": "utf-8" } #要發(fā)送的文本是json格式 request_data = { #此消息的類型為固定的text "msgtype": "text", "text": { #消息的內(nèi)容 "content": "大家新年快樂" }, "at": { #被@人的手機號 "atMobiles": [], #控制@所有人 "isAtAll": True } } #把json轉(zhuǎn)變?yōu)樽址袷綌?shù)據(jù) send_data = json.dumps(request_data) #這個是發(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ā)
2、修改結(jié)構(gòu),具體操作
import sys import json import requests url = 'https://oapi.dingtalk.com/robot/send?access_token=a25324cafc5b0f2bb239b5e56c71e7f378f570a3d281160dbec9e4f8c4a7e493 ' 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 = sys.argv[1] WriteLogByDing(content)
1.2.2 發(fā)送帶有鏈接的文檔
import requests import json url = 'https://oapi.dingtalk.com/robot/send?access_token=a25324cafc5b0f2bb239b5e56c71e7f378f570a3d281160dbec9e4f8c4a7e493 ' headers = { "Content-Type": "application/json", "Chartset": "utf-8" } #要發(fā)送的文本是json格式 request_data = { #發(fā)送鏈接類型的數(shù)據(jù) "msgtype": "link", "link": { #鏈接提示 "text":"群機器人是釘釘群的高級擴展功能。群機器人可以將第三方服務(wù)的信息聚合到群聊中,實現(xiàn)自動化的信息同步。例如:通過聚合GitHub,GitLab等源碼管理服務(wù),實現(xiàn)源碼更新同步;通過聚合Trello,JIRA等項目協(xié)調(diào)服務(wù),實現(xiàn)項目信息同步。不僅如此,群機器人支持Webhook協(xié)議的自定義接入,支持更多可能性,例如:你可將運維報警提醒通過自定義機器人聚合到釘釘群。", #鏈接標(biāo)題 "title": "自定義機器人協(xié)議", #圖片url地址 "picUrl": "http://p3.so.qhmsg.com/sdr/200_200_/t013d7a21145c708288.jpg", #信息的鏈接跳轉(zhuǎn) "messageUrl": "https://open-doc.dingtalk.com/docs/doc.htm?spm=a219a.7629140.0.0.Rqyvqo&treeId=257&articleId=105735&docType=1" } } #把json轉(zhuǎn)變?yōu)樽址袷綌?shù)據(jù) send_data = json.dumps(request_data) #這個是發(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)
1.2.3 發(fā)送makedown文檔
import requests import json url = 'https://oapi.dingtalk.com/robot/send?access_token=a25324cafc5b0f2bb239b5e56c71e7f378f570a3d281160dbec9e4f8c4a7e493 ' 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 > \n > ###### 10點20分發(fā)布 [天氣](http://www.thinkpage.cn/) " }, "at": { "atMobiles": [], "isAtAll":False } } #把json轉(zhuǎn)變?yōu)樽址袷綌?shù)據(jù) send_data = json.dumps(request_data) #這個是發(fā)送post請求,請求釘釘接口 response = requests.post(url=url,headers=headers,data=send_data) #講求成功后返回的數(shù)據(jù) content = response.content.decode() #打印 print(content)
#要發(fā)送的文本是json格式 發(fā)送整體跳轉(zhuǎn)的actionCard類型 request_data = { "actionCard": { "title": "喬布斯 20 年前想打造一間蘋果咖啡廳,而它正是 Apple Store 的前身", "text": " \n #### 喬布斯 20 年前想打造的蘋果咖啡廳 \n\n Apple Store 的設(shè)計正從原來滿滿的科技感走向生活化,而其生活化的走向其實可以追溯到 20 年前蘋果一個建立咖啡館的計劃", "hideAvatar": "0", "btnOrientation": "0", "singleTitle" : "閱讀全文", "singleURL" : "https://www.dingtalk.com/" }, "msgtype": "actionCard" }
{ "feedCard": { "links": [ { "title": "時代的火車向前開", "messageURL": "https://mp.weixin.qq.com/s?__biz=MzA4NjMwMTA2Ng==&mid=2650316842&idx=1&sn=60da3ea2b29f1dcc43a7c8e4a7c97a16&scene=2&srcid=09189AnRJEdIiWVaKltFzNTw&from=timeline&isappinstalled=0&key=&ascene=2&uin=&devicetype=android-23&version=26031933&nettype=WIFI", "picURL": "https://www.dingtalk.com/" }, { "title": "時代的火車向前開2", "messageURL": "https://mp.weixin.qq.com/s?__biz=MzA4NjMwMTA2Ng==&mid=2650316842&idx=1&sn=60da3ea2b29f1dcc43a7c8e4a7c97a16&scene=2&srcid=09189AnRJEdIiWVaKltFzNTw&from=timeline&isappinstalled=0&key=&ascene=2&uin=&devicetype=android-23&version=26031933&nettype=WIFI", "picURL": "https://www.dingtalk.com/" } ] }, "msgtype": "feedCard" }
總結(jié):
1、釘釘報警設(shè)置
2、釘釘報警腳本運行。
到此這篇關(guān)于淺談Python 釘釘報警必備知識系統(tǒng)講解的文章就介紹到這了,更多相關(guān)Python 釘釘報警內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Python中語音轉(zhuǎn)文字相關(guān)庫介紹(最新推薦)
Python的speech_recognition庫是一個用于語音識別的Python包,它可以使Python程序能夠識別和翻譯來自麥克風(fēng)、音頻文件或網(wǎng)絡(luò)流的語音,這篇文章主要介紹了Python中語音轉(zhuǎn)文字相關(guān)庫介紹,需要的朋友可以參考下2023-05-05django寫用戶登錄判定并跳轉(zhuǎn)制定頁面的實例
今天小編就為大家分享一篇django寫用戶登錄判定并跳轉(zhuǎn)制定頁面的實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-08-08解決pycharm編輯區(qū)顯示yaml文件層級結(jié)構(gòu)遇中文亂碼問題
這篇文章主要介紹了解決pycharm編輯區(qū)顯示yaml文件層級結(jié)構(gòu)遇中文亂碼問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-04-04python免殺技術(shù)shellcode的加載與執(zhí)行
本文主要介紹了python免殺技術(shù)shellcode的加載與執(zhí)行,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-04-04利用Python實現(xiàn)去重聚合Excel數(shù)據(jù)并對比兩份數(shù)據(jù)的差異
在數(shù)據(jù)處理過程中,常常需要將多個數(shù)據(jù)表進行合并,并進行比對,以便找出數(shù)據(jù)的差異和共同之處,本文將介紹如何使用 Pandas 庫對兩個 Excel 數(shù)據(jù)表進行合并與比對,需要的可以參考下2023-11-11