海豚调度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
微信应该也可以收到该消息,但是需要企业公众号或者企业认证才能开通
开通方式:工作台-管理企业-与微信消息互通