第一步:申請企業微信應用
申請後需要記住申請的三個參數(CorpID、Secret、AgentId )
第二步:放置腳本在/usr/lib/zabbix/alertscripts檔案夾下,腳本内容如下
[[email protected] alertscripts] # cat Email.weixin.sh
#!/bin/bash
CorpID=‘ww685aa8e14a1dbc9d’ #我的企業下面的CorpID
Secret=‘zA0KVMhYplLLnIFLKz8myrbqT0Q5H73OEszRjzE35io’ #建立的應用那有Secret
GURL=“https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=KaTeX parse error: Expected 'EOF', got '&' at position 7: CorpID&̲corpsecret=Secret”
Token=$(/usr/bin/curl -s -G $GURL |awk -F": ‘{print $4}’ |awk -F" ‘{print $2}’)
#echo T o k e n P U R L = " h t t p s : / / q y a p i . w e i x i n . q q . c o m / c g i − b i n / m e s s a g e / s e n d ? a c c e s s t o k e n = Token PURL="https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token= TokenPURL="https://qyapi.weixin.qq.com/cgi−bin/message/send?accesstoken=Token"
function body(){
local int agentid=1000002 #改為AgentId 在建立的應用那裡看
local UserID=“XXXXXXX” #發送的使用者位于KaTeX parse error: Expected 'EOF', got '#' at position 42: …D=2 #̲第一步看的通訊錄中的部門ID …(echo “KaTeX parse error: Undefined control sequence: \n at position 39: … printf '{\̲n̲' print…UserID”"",\n"
printf ‘\t"toparty": "’“KaTeX parse error: Can't use function '\"' in math mode at position 9: PartyID"\̲"̲",\n" p…agentid”"",\n"
printf ‘\t"text": {\n’
printf ‘\t\t"content": "’"$Msg"""\n"
printf ‘\t},\n’
printf ‘\t"safe":“0”\n’
printf ‘}\n’
}
/usr/bin/curl --data-ascii “$(body $1 $2 $3)” $PURL
第三步:腳本編寫完成之後需要為腳本添加執行權限
[[email protected] alertscripts] # chmod 777 Email.weixin.sh
第四步:在web界面添加報警媒介類型
第五步:關聯使用者報警
第六步:設定關關聯作
此操作與郵件報警添加相同(一個是添加郵箱報警,一個是添加郵件報警)