- 邮件
- 微信(企业号)
- 钉钉报警 企业OA系统 办公自动化 请假 审批 提交问题 打卡
文章目录
一. 邮件报警
1. QQ邮箱
- 开启QQ发邮件功能 SMTP 发件人
- 开启smtp功能
- 生成授权码 biekmtiriuoiu461uk


2. Zabbix 配置发件人
-
修改后启用

-
配置邮箱名称
-
密码为授权码

3. Zabbix 配置收件人

4.定义动作


发生故障: {EVENT.NAME}
故障开始时间 {EVENT.TIME} 日期 {EVENT.DATE}
故障名称: {EVENT.NAME}
主机: {HOST.NAME}
严重性: {EVENT.SEVERITY}
故障ID: {EVENT.ID}
{TRIGGER.URL}

5. 测试
- 制造故障
- 查看故障
- 查看动作
- 查看动作日志






二. 企业微信报警(蓝信等等)
- 配置Python脚本
#!/usr/bin/env python
#-*- coding: utf-8 -*-
#author: oldboy
#date: 2018-04-20
#comment: zabbix接入微信报警脚本
import requests
import sys
import os
import json
import logging
logging.basicConfig(level = logging.DEBUG, format = '%(asctime)s, %(filename)s, %(levelname)s, %(message)s',
datefmt = '%a, %d %b %Y %H:%M:%S',
filename = os.path.join('/tmp','weixin.log'),
filemode = 'a')
corpid='ww164db8ae79266c79'
appsecret='O1YlCDKECHVaz_iUU_b8CmMyvZ0ehyvWSVaRQ8gx7yo'
agentid=1000002
#获取accesstoken
token_url='https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=' + corpid + '&corpsecret=' + appsecret
req=requests.get(token_url)
accesstoken=req.json()['access_token']
#发送消息
msgsend_url='https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=' + accesstoken
touser=sys.argv[1]
subject=sys.argv[2]
#toparty='3|4|5|6'
message=sys.argv[2] + "\n\n" +sys.argv[3]
params={
"touser": touser,
# "toparty": toparty,
"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)
上传到配置目录
[root@m01 alertscripts]# pwd
/usr/lib/zabbix/alertscripts
[root@m01 alertscripts]# ll
total 4
-rwxr-xr-x 1 root root 1358 Nov 8 11:47 weixin.py
安装requests模块
[root@m01 alertscripts]# python weixin.py
Traceback (most recent call last):
File "weixin.py", line 7, in <module>
import requests
ImportError: No module named requests
#配置 pypi pip下载的源
[root@m01 alertscripts]# yum install -y python-pip
#下载这个模块
[root@m01 alertscripts]# pip install requests -i https://pypi.tuna.tsinghua.edu.cn/simple
#pip查看安装后软件的信息
[root@m01 alertscripts]# pip2.7 show requests
---
Metadata-Version: 1.1
Name: requests
Version: 2.6.0
Summary: Python HTTP for Humans.
Home-page: http://python-requests.org
Author: Kenneth Reitz
Author-email: me@kennethreitz.com
License: Apache 2.0
Location: /usr/lib/python2.7/site-packages
Requires:
Classifiers:
Development Status :: 5 - Production/Stable
Intended Audience :: Developers
Natural Language :: English
License :: OSI Approved :: Apache Software License
Programming Language :: Python
Programming Language :: Python :: 2.6
Programming Language :: Python :: 2.7
Programming Language :: Python :: 3
Programming Language :: Python :: 3.3
Programming Language :: Python :: 3.4
You are using pip version 8.1.2, however version 19.3.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
配置企业微信
- 配置weixin.py 连接/使用 企业号
- 生成 企业号的用户名 密码 id



根据上面内容修改:
1000003
Za8RFyzi6y7S-OQAR3pFCZLuuyFw6GvvSanYNBJkecI
ww164db8ae79266c79
[root@m01 alertscripts]# egrep -n '^(corpid|appsecret|agentid)' weixin.py
18:corpid='ww164db8ae79266c79'
19:appsecret='Za8RFyzi6y7S-OQAR3pFCZLuuyFw6GvvSanYNBJkecI'
20:agentid=1000003

[root@m01 alertscripts]# python weixin.py "NiuCongShuo" "test" "gogogo"
[root@m01 alertscripts]#


{ALERT.SENDTO}
{ALERT.SUBJECT}
{ALERT.MESSAGE}




1856

被折叠的 条评论
为什么被折叠?



