15_微信告警实战

企业微信地址,个人可注册

企业微信

登录企业微信

  1. 企业->微工作台里可以直接微信关注,无需下载企业微信
  2. 通讯录里的账号在发微信脚本中要用到
  3. 应用于与小程序可创建应用
  4. 发微信的python脚本(加执行权限chmod a+x zabbix_wx.py)
#!/usr/bin/python
# -*- coding:utf-8 -*-
# zabbix_wx.py
import json
import sys
import urllib,urllib2

agentid="xxx" #自建应用的AgentId
corpid="xxx" #公司的id,在我的企业--企业ID
corpsecret="xxx" #AgentId下面的Secret密码
 
#get token
gettoken_url='https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid='+corpid+'&corpsecret='+corpsecret
token_file=urllib2.urlopen(gettoken_url)
token_data=token_file.read().decode('utf-8')
token_json=json.loads(token_data)
my_token=token_json['access_token']

#send wechart
touser=sys.argv[1] #many user:'zhangsan|wangwu|lisi'
content=sys.argv[2] #content
post_content={
  "touser":touser,
  "agentid":agentid,
  "msgtype":"text",
  "text":{
    "content":content,
  }
}
json_content=json.dumps(post_content)
url = 'https://https://qyapi.weixin.qq.com/cgi-bin/message/sent?access_token='+my_token
response=urllib2.urlopen(url,json_content)
print(response.read().decode("utf-8"))

测试脚本:/usr/local/zabbix/alertscripts/zabbix_wx.py 'chiss' 'disk using > 90%'

zabbix微信告警配置步骤

类似邮件告警

  1. 写一个微信告警脚本
  2. 报警媒介添加微信告警
  3. 用户设置报警媒介
  4. 创建触发动作