0.修改时区(前提条件已经安装好elk7.2)

rm -f /etc/localtime
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
timedatectl set-timezone Asia/Shanghai

1.升级python

# 安装依赖
yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
# 获取编译安装python3.6.9
mkdir -p /usr/local/python3
wget https://www.python.org/ftp/python/3.6.9/Python-3.6.9.tgz
tar xf Python-3.6..tgz
cd Python-3.6.
./configure --prefix=/usr/local/python3
make && make install
ln -s /usr/local/python3/bin/python-3.6./bin/python3. /usr/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3

2.安装virtualenv虚拟环境

pip3 install virtualenv
# 创建存放虚拟环境的目录
mkdir -p /usr/local/venv_py3.6_elastalert-0.2. # 创建纯净的虚拟环境
cd /usr/local
git clone https://github.com/Yelp/elastalert.git
cd /usr/local/elastalert /usr/local/python3/bin/virtualenv --no-site-packages --python=/usr/local/python3/bin/python3. /usr/local/venv_py3.6_elastalert-0.2.
[root@eus-kibana-elastalert-:/usr/local/venv_py3.6_elastalert-0.2.]# source bin/activate
(venv_py3.6_elastalert-0.2.) [root@eus-kibana-elastalert-:/usr/local/venv_py3.6_elastalert-0.2.]#

3.在虚拟的python3.6环境中安装alasticalert

# 指定库,安装依赖,否则可能安装失败
(venv_py3.6_elastalert-0.2.) [root@eus-kibana-elastalert-:/usr/local/elastalert]# pip install -r requirements.txt -i https://pypi.python.org/simple
# 安装主程序,否则无法使用 elastalert-create-index 命令
(venv_py3.6_elastalert-0.2.) [root@eus-kibana-elastalert-:/usr/local/elastalert]# python setup.py install
# 运行 elastalert-create-index 配置
(venv_py3.6_elastalert-0.2.) [root@eus-kibana-elastalert-:/usr/local/elastalert]# elastalert-create-index

4.elastalert的主配置

[root@rbtnode1 elastalert]# cat config.yaml
rules_folder: example_rules
run_every:
minutes:
buffer_time:
minutes:
es_host: 192.168.1.156
es_port:
writeback_index: elastalert_status
writeback_alias: elastalert_alerts
alert_time_limit:
days:

6.用邮箱发告警的规则

[root@rbtnode1 example_rules]# cat my_rule.yaml|egrep -v '^#'
es_host: 192.168.1.156
es_port:
name: eus-log-elasticsearch-cluster-alert
type: frequency
index: syslog*
num_events:
timeframe:
# hours: 在多长时间内
minutes: 1
filter:
- query_string:
query: "message: hello"
smtp_host: smtp..com
smtp_port:
smtp_auth_file: /opt/elastalert/smtp_auth.yaml
email_reply_to: linux1634@.com
from_addr: linux1634@.com
alert:
- "email"
email:
- "linux163@163.com"

邮箱账户密码:

[root@rbtnode1 example_rules]# cat /opt/elastalert/smtp_auth.yaml        
user: "linux1634@163.com"
password: "hahahhahaha" 授权码
参考:https://www.cnblogs.com/reblue520/p/11539956.html  7.用企业微信告警
cd /usr/local/elastalert/elastalert_modules/
wget https://raw.githubusercontent.com/anjia0532/elastalert-wechat-plugin/master/elastalert_modules/wechat_qiye_alert.py
touch __init__.py
修改wechat_qiye_alert.py
3    from MyEncoder import MyEncoder
126 response = requests.post(send_url, data=json.dumps(payload, cls=MyEncoder, indent=, ensure_ascii=False), headers=headers) #修改后

8.添加一个类,处理因python2,python3不兼容导致的:TypeError: Object of type 'bytes' is not JSON serializable

cd /usr/local/venv_py3.6_elastalert-0.2./lib/python3./site-
packages
(venv_py3.6_elastalert-0.2.) [root@rbtnode1 site-packages]# cat MyEncoder.py
import json
class MyEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, bytes):
return str(obj, encoding='utf-8')
return json.JSONEncoder.default(self, obj) cp MyEncoder.py /usr/local/venv_py3.6_elastalert-0.2.1/lib/
cp MyEncoder.py  /usr/local/venv_py3.6_elastalert-0.2.1/lib/python3.6/

8.企业微信告警规则

(venv_py3.6_elastalert-0.2.) [root@rbtnode1 example_rules]# cat my_rule.yaml|egrep -v '^$'
es_host: 192.168.1.156
es_port:
name: "eus-log-elasticsearch-cluster-alert"
use_ssl: False
type: frequency
index: syslog*
num_events:
timeframe:
hours:
filter:
- query_string:
query: "message: hello"
alert:
- "elastalert_modules.wechat_qiye_alert.WeChatAlerter"
alert_text_args:
- message
corp_id: "wwwdbe2b483965af612"
secret: "6gAuFwoAvGvshiZ6RUsaL6mfobiBi3JPkO99sxw21cLw"
agent_id:
party_id: ""
user_id: "@all"
#tag_id: ""

参考:

https://blog.csdn.net/xiaohuo0930/article/details/90373181

https://anjia0532.github.io/2017/02/16/elastalert-wechat-plugin/

https://github.com/anjia0532/elastalert-wechat-plugin

https://github.com/anjia0532/elastalert-wechat-plugin/issues/2

http://www.appblog.cn/2019/11/23/ELK%207.x%20--%20elastalert%20%E4%BC%81%E4%B8%9A%E5%BE%AE%E4%BF%A1%E5%91%8A%E8%AD%A6/

 
												

python3.6-Yelp/elastalert0.2.1-elk7.2.0邮件加企业微信告警的更多相关文章

  1. python3:利用smtplib库和smtp.qq.com邮件服务器发送邮件

    python3:利用smtplib库和smtp.qq.com邮件服务器发送邮件 使用qq的邮件服务器需要注意的两个地方主要是: 1.协议问题 使用465端口 SSL 协议 2.口令问题 出现SMTPA ...

  2. ELK7.4.0分析nginx json日志

    ELK7.4.0单节点部署 环境准备 安装系统,数据盘设置为/srv 内核优化参考 我们需要创建elk专用的账号,并创建所需要的目录并授权 useradd elk; mkdir /srv/{app,d ...

  3. 在Centos7下docker配置自动化环境镜像(python3.7+selenium 3.11+firefox 62+geckodriver 0.21)

    最近在学习Docker,准备做自动化测试代码集成的功能.如下文章的前提是已经安装好linux系统,且成功安装好Docker. 接下来我会按步骤一步一步的对自动化需要的一些环境进行安装,如果没有特别说明 ...

  4. 后端Python3+Flask结合Socket.io配合前端Vue2.0实现简单全双工在线客服系统

    原文转载自「刘悦的技术博客」https://v3u.cn/a_id_158 在之前的一篇文章中:为美多商城(Django2.0.4)添加基于websocket的实时通信,主动推送,聊天室及客服系统,详 ...

  5. Python3调用企业微信用于告警

    前段时间利用py爬虫抓取一些网页信息,然后通过wxpy发送到微信群,以用作日常告警,感觉还是很方便. 但好景不长,我的小号微信被腾讯封了(很常见咯), 显示无法登录网页版微信,至今已经有半个多月了. ...

  6. Python3基础 __add__,__sub__ 两个类的实例相互加减

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  7. python3企业微信群组报警

    公司提出一个需求需要做一个企业微信的一个消息推送,需要将消息发送到聊天群里详细信息如下. 如何创建应用请阅读我的上篇文章:https://www.cnblogs.com/wangyajunblog/p ...

  8. Python3 使用企业微信 API 发送消息

    #coding=utf- import requests import json Secret = "TUbfeW8nFQakwOS4czm13SCnxSUPOqY2K0XHtM8XLT34 ...

  9. Python3基础 bool True为1 False为0

             Python : 3.7.3          OS : Ubuntu 18.04.2 LTS         IDE : pycharm-community-2019.1.3    ...

随机推荐

  1. 从设计稿到实现React应用(分类数据处理)

    1. 确定设计稿和数据 设计稿: 数据: [ {category: "Sporting Goods", price: "$49.99", stocked: tr ...

  2. sql sever 触发器的概念和使用

    触发器简介: 触发器是一种特殊的存储过程,它的执行不是由程序调用,也不是手动执行,而是由事件来触发.触发器是当对某一个表进行操作.例如:update.insert.delete这些操作的时候,系统会自 ...

  3. 38 | 都说InnoDB好,那还要不要使用Memory引擎?

    我在上一篇文章末尾留给你的问题是:两个 group by 语句都用了 order by null,为什么使用内存临时表得到的语句结果里,0 这个值在最后一行:而使用磁盘临时表得到的结果里,0 这个值在 ...

  4. RabbitMQ持久化和非持久化

    但是,非持久化要比持久化速度更快. 队列是否需要持久化:看需求

  5. 递归函数返回值 undefined

    getItem(obj, arr, index) { if (arr.length - 1 !== index) { const tempObj = obj[arr[index]]; this.get ...

  6. easy-table-vue+VueJs、SpringBoot+Mybatis实现MVVM模型前后台数据交互

    该项目分为前端展示部分和后台服务部分. 前端部分 使用的技术是:NodeJs.Webpack.VueJs 使用的组件库是:IVIEW.easy-table-vue 使用的开发工具是:WebStorm ...

  7. Mac 下 安装 Nginx

    ---恢复内容开始--- Mac 下 安装nginx 首先确定自己有安装homebrew 安装 nginx brew install nginx 启动nginx 1.15版本下 安装是 直接在ngin ...

  8. c 字符串的结束标志

    //char carray[]="nihao"; char carray[]={'a','b','c','d','\0'}; printf("array=%s" ...

  9. Android中View大小的确定过程

    View and ViewGroup 安卓中有5种基本的 ViewGroup: FrameLayout RelativeLayout LinearLayout TableLayout Absolute ...

  10. idea 2019激活码

    9MWZD5CC4E-eyJsaWNlbnNlSWQiOiI5TVdaRDVDQzRFIiwibGljZW5zZWVOYW1lIjoiMjAxNzY1MDYxQGNxdS5lZHUuY24gLiIsI ...