zabbix监控报警: 钉钉、企业微信、Email方式

  1、添加报警媒介:

  管理-->报警媒介类型-->创建媒介类型:  

    

    

    

   编辑Email:

     

 

2、添加监控脚本: 
 钉钉: dingding.py

  参考官方开放平台文档:https://open-doc.dingtalk.com/docs/doc.htm?spm=a219a.7629140.0.0.6ab04a97J3fY3Y&treeId=257&articleId=105733&docType=1

 

#!/usr/bin/python
# -*- coding: utf-8 -*-

import sys,os,requests,json

headers = {'Content-Type': 'application/json;charset=utf-8'}
api_url = "https://oapi.dingtalk.com/robot/send?access_token=钉钉获取"
 
def sendmsg(text):
    json_text= {
     "msgtype": "text",
        "at": {
            "atMobiles": [
                "手机号"
            ],
            "isAtAll": False
        },
        "text": {
            "content": text
        }
    }
    print requests.post(api_url,json.dumps(json_text),headers=headers).content

if __name__ == '__main__':
    text = sys.argv[1]
    sendmsg(text)
View Code
  企业微信: weixin.py

  参考官方文档:https://work.weixin.qq.com/api/doc#10167

#!/usr/bin/env python
#-*- coding: utf-8 -*-

import sys,os,requests,json,logging

logging.basicConfig(level = logging.DEBUG, format = '%(asctime)s, %(filename)s, %(levelname)s, %(message)s',
                datefmt = '%a, %d %b %Y %H:%M:%S',
                filename = "/tmp/zabbix_server.log",
                filemode = 'a')

#企业微信信息: 申请企业微信后,去企业微信管理后台获取  
corpid = ''
appsecret = ''
agentid = 

'''
获取access_token:
请求方式:GET(HTTPS)
请求URL:https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=ID&corpsecret=SECRECT
'''
token_url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=%s&corpsecret=%s" %(corpid,appsecret)
res = requests.get(token_url)
errcode = res.json()['errcode']

# 脚本传入参数
touser = sys.argv[1]
subject = sys.argv[2]
message = sys.argv[3]

if errcode == 0:
    access_token = res.json()['access_token']

    #发送消息
    msgsend_url='https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=' + access_token

    params={
            "touser": touser,
            "msgtype": "text",
            "agentid": agentid,
            "text": {
                    "content": message
            },
            "safe":0
    }

    req=requests.post(msgsend_url, data=json.dumps(params))
    logging.info('sendto:' + touser + ';;subject:' + subject + ';;message:' + message)

else:
    errmsg = res.json()['errmsg']
    logging.info("get access_token failed, errcode=%s, errmsg=%s" %(errcode,errmsg))
weixin.py
将脚本上传至zabbix_server端口:/usr/local/zabbix/alertscripts 目录下。
3、创建触发器:

  配置-->动作-->事件源选:触发器-->创建动作:

    

     

    

  故障恢复添加:

恢复主机:{HOST.NAME}
主机地址:{HOST.IP}
恢复时间:{EVENT.DATE} {EVENT.TIME}
恢复等级:{TRIGGER.SEVERITY}
恢复信息:{TRIGGER.NAME}
问题详情:{ITEM.NAME}:{ITEM.VALUE}

  创建微信和Email触发器同上。

4、配置接收报警信息的用户:

  管理-->用户-->选择Admin:  报警媒介-->添加钉钉、企业微信和Email。添加完点更新即可。

 

转载于:https://www.cnblogs.com/pythonlee/p/9922836.html

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值