海豚排程2.0.4微信告警配置記錄
- 準備工作
- 微信告警配置參數
-
- corpid
- agentid
- secret
- users
- send.type
- user.send.msg
- 告警使用記錄
-
- 40008錯誤
- 再次驗證
- 如何發送具體任務錯誤資訊
-
- 檢視源碼
- 變量msg格式配置不對,沒加$,{},“”,會報44004錯誤
- 再次驗證
- 其它
-
- 微信直接接收企業應用通知
- chatid
準備工作
企業微信管理者賬号(可以自己申請一個企業賬戶,用來測試)
自建應用,用來測試
微信告警配置參數
corpid
每個企業都擁有唯一的corpid,擷取此資訊可在管理背景“我的企業”-“企業資訊”下檢視“企業ID”(需要有管理者權限)
agentid
每個應用都有唯一的agentid。在管理背景->“應用與小程式”->“應用”,點進某個應用,即可看到agentid。
secret
secret是企業應用裡面用于保障資料安全的“鑰匙”,每一個應用都有一個獨立的通路密鑰,為了保證資料的安全,secret務必不能洩漏。
目前secret有:
自建應用secret。在管理背景->“應用與小程式”->“應用”->“自建”,點進某個應用,即可看到。
基礎應用secret。某些基礎應用(如“審批”“打卡”應用),支援通過API進行操作。在管理背景->“應用與小程式”->“應用->”“基礎”,點進某個應用,點開“API”小按鈕,即可看到
users
可以随便輸入
send.type
發送類型,應用和群聊
user.send.msg
要發送的内容,JSON格式
應用格式
{
"touser": "UserID1|UserID2|UserID3",
"toparty": "PartyID1|PartyID2",
"totag": "TagID1 | TagID2",
"msgtype": "text",
"agentid": 1,
"text": {
"content": "你的快遞已到\n請攜帶工卡前往郵件中心領取"
},
"safe": 0,
"enable_id_trans": 0,
"enable_duplicate_check": 0
}
群聊格式
{
"chatid": "CHATID",
"msgtype": "text",
"text": {
"content": "你的快遞已到\n請攜帶工卡前往郵件中心領取"
},
"safe": 0
}
參照企業微信開發中心
告警使用記錄
40008錯誤
2022-03-02 11:15:27.150 INFO 1909 --- [pool-3-thread-1] o.a.d.plugin.alert.wechat.WeChatSender : Enterprise WeChat send [https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=wdH26O_yUyQ7HE9qTgocvHz4IW2Thw1qc-XIUK8IPsTs1TTzykogH1BHFpcBTVQbohcUuquq-U90rrWZO_86r-VWyZJpLEdjrLNwgVCS1jqt-RotbaxJ92uZBh_Nzln6P75HiSmoTfmw98b5IZkI9fDLhpAxrz5GtXwXAuoneazV2gmaehT5v5cSHUuEkbUeCGx7-n7MAn06yRIea4Aeug], param:test alert, resp:{"errcode":40008,"errmsg":"Warning: wrong json format. invalid message type, hint: [1646190927277970339863326], from ip: 36.5.134.204, more info at https://open.work.weixin.qq.com/devtool/query?e=40008"}
2022-03-02 11:15:27.172 INFO 1909 --- [pool-3-thread-1] o.a.dolphinscheduler.alert.AlertSender : Alert Plugin 微信 send error : Warning: wrong json format. invalid message type, hint: [1646190927277970339863326], from ip: 36.5.134.204, more info at https://open.work.weixin.qq.com/devtool/query?e=40008
原因是user.send.msg配置内容不對,通過企業微信開發者中心-接口調試工具,直接調試通過後,把body内容複制過來即可
再次驗證
2022-03-02 14:31:57.250 INFO 1909 --- [pool-3-thread-1] o.a.d.plugin.alert.wechat.WeChatSender : Enterprise WeChat send [https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=0suIhV8_YfrgWRQ8o5JYO9UhqsQIxxJKaHmdROUt3MJAM24IgwMTw6lwDa45btKtBzrJ7NsIhw2Sde-3AWyjlKJ36jHTaXeAe_ZAOi0Yye_OrvzPk0zr28iayeT25Jn3d_ONQ8Fk9vQe6zts3FZc6dlIuncrAsfTJRfEHH99Ht7zjPyVD6XO1wO1MiWiGaJHLAQ09gYw0LlgzwnwH_IQjA], param:{ "touser": "1", "toparty": "1", "totag": "TagID1 | TagID2", "msgtype": "text", "agentid": 1000002, "text": { "content": "測試微信API" }, "safe": 0, "enable_id_trans": 0, "enable_duplicate_check": 0 }, resp:{"errcode":0,"errmsg":"ok","invaliduser":"1","invalidtag":"0","msgid":"Dv0oBVNA9p2BIWPODPqgktEu4XC8Y5v2dnEPBBt0GuGW6lViRFDOqz-9mIPuwa5IzUngy4Yk3Ef4tXu0ADGW8w"}
2022-03-02 14:31:57.250 INFO 1909 --- [pool-3-thread-1] o.a.dolphinscheduler.alert.AlertSender : Alert Plugin 微信 send success
但是告警内容是寫死的!!!!
如何發送具體任務錯誤資訊
檢視源碼
修改content内容,替換具體任務資訊
變量msg格式配置不對,沒加$,{},“”,會報44004錯誤
2022-03-02 15:11:57.193 INFO 1909 --- [pool-3-thread-1] o.a.d.plugin.alert.wechat.WeChatSender : Enterprise WeChat send [https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=0suIhV8_YfrgWRQ8o5JYO9UhqsQIxxJKaHmdROUt3MJAM24IgwMTw6lwDa45btKtBzrJ7NsIhw2Sde-3AWyjlKJ36jHTaXeAe_ZAOi0Yye_OrvzPk0zr28iayeT25Jn3d_ONQ8Fk9vQe6zts3FZc6dlIuncrAsfTJRfEHH99Ht7zjPyVD6XO1wO1MiWiGaJHLAQ09gYw0LlgzwnwH_IQjA], param:{ "touser": "14ead2cf8110655aed8fdf2257ab5c1d", "toparty": "1", "totag": "TagID1 | TagID2", "msgtype": "text", "agentid": 1000002, "text": {"content": $`start process failed`
>projectId:1
>projectName:dolphin
>owner:admin
>processId:49
>processDefinitionCode:4696813047552
>processName:alert-1-20220302151151784
>taskCode:4696810253440
>taskName:testAlert
>taskType:SHELL
>taskState:FAILURE
>taskStartTime:2022-03-02 15:11:51
>taskEndTime:2022-03-02 15:11:51
>taskHost:192.168.56.10:1234
>logPath:/home/dolphinscheduler/app/dolphinscheduler/logs/4696813047552_1/49/57.log
}, "safe": 0, "enable_id_trans": 0, "enable_duplicate_check": 0 }, resp:{"errcode":44004,"errmsg":"Warning: wrong json format. empty content, hint: [1646205117042450091058341], from ip: 36.5.134.204, more info at https://open.work.weixin.qq.com/devtool/query?e=44004","msgid":"Dv0oBVNA9p2BIWPODPqgktEu4XC8Y5v2dnEPBBt0GuFZDilY0v-NBE66YjhWNimCQRXZm-_TMwwtLbWQxXgDDA"}
2022-03-02 15:11:57.193 INFO 1909 --- [pool-3-thread-1] o.a.dolphinscheduler.alert.AlertSender : Alert Plugin 微信 send error : Warning: wrong json format. empty content, hint: [1646205117042450091058341], from ip: 36.5.134.204, more info at https://open.work.weixin.qq.com/devtool/query?e=44004
再次驗證
2022-03-02 15:16:42.172 INFO 1909 --- [pool-3-thread-1] o.a.d.plugin.alert.wechat.WeChatSender : Enterprise WeChat send [https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=0suIhV8_YfrgWRQ8o5JYO9UhqsQIxxJKaHmdROUt3MJAM24IgwMTw6lwDa45btKtBzrJ7NsIhw2Sde-3AWyjlKJ36jHTaXeAe_ZAOi0Yye_OrvzPk0zr28iayeT25Jn3d_ONQ8Fk9vQe6zts3FZc6dlIuncrAsfTJRfEHH99Ht7zjPyVD6XO1wO1MiWiGaJHLAQ09gYw0LlgzwnwH_IQjA], param:{ "touser": "14ead2cf8110655aed8fdf2257ab5c1d", "toparty": "1", "totag": "TagID1 | TagID2", "msgtype": "text", "agentid": 1000002, "text": {"content": "$`start process failed`
>projectId:1
>projectName:dolphin
>owner:admin
>processId:50
>processDefinitionCode:4696813047552
>processName:alert-1-20220302151637646
>taskCode:4696810253440
>taskName:testAlert
>taskType:SHELL
>taskState:FAILURE
>taskStartTime:2022-03-02 15:16:37
>taskEndTime:2022-03-02 15:16:37
>taskHost:192.168.56.10:1234
>logPath:/home/dolphinscheduler/app/dolphinscheduler/logs/4696813047552_1/50/58.log
" }, "safe": 0, "enable_id_trans": 0, "enable_duplicate_check": 0 }, resp:{"errcode":0,"errmsg":"ok. Warning: wrong json format. ","invalidtag":"0","msgid":"ApdmTZacy5fwcrmY4C90r3teipLMq1w1kUrdF8B6gEPJugsbwGrAkbGGkYsRAC5doqD9unFNXaaL36GjzulS4w"}
2022-03-02 15:16:42.173 INFO 1909 --- [pool-3-thread-1] o.a.dolphinscheduler.alert.AlertSender : Alert Plugin 微信 send success
(END)
其它
微信直接接收企業應用通知
chatid
隻有api建立的群才有群ID
微信應該也可以收到該消息,但是需要企業公衆号或者企業認證才能開通
開通方式:工作台-管理企業-與微信消息互通