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. 使用druid连接池的超时回收机制排查连接泄露

    起因:系统连接池满了 Exception wait millis 60012, active 2000, maxActive 2000, creating 0 加配置排查: <!-- 超过时间限 ...

  2. LOJ P10171 牧场的安排 题解

    每日一题 day6 打卡 Analysis 状压dp dp[i][j]+=dp[i-1][k]; #include<iostream> #include<cstdio> #in ...

  3. 007_Python3 字符串

    字符串是 Python 中最常用的数据类型.我们可以使用引号( ' 或 " )来创建字符串. 创建字符串很简单,只要为变量分配一个值即可. 例如: var1 = 'Hello World!' ...

  4. learning scala How To Create Variable Argument Function - varargs :_ *

    Scala collection such as List or Sequence or even an Array to variable argument function using the s ...

  5. luogu P3386 【模板】二分图匹配

    二次联通门 : luogu P3386 [模板]二分图匹配 /* luogu P3386 [模板]二分图匹配 最大流 设置源点,汇点,连到每条边上 跑一边最大流即可 */ #include <i ...

  6. [Shell]CVE-2019-0708漏洞复现及修复补丁

    0x01 漏洞原理 Windows系列服务器于2019年5月15号,被爆出高危漏洞,该漏洞影响范围较广,windows2003.windows2008.windows2008 R2.windows 7 ...

  7. 对象转型、迭代器Iterator、Set集合、装箱与拆箱、基本数据类型与字符串的转换、TreeSet集合与对象

      包的声明与定义 需要注意的是,包的声明只能位于Java源文件的第一行. 在实际程序开发过程中,定义的类都是含有包名的: 如果没有显式地声明package语句,创建的类则处于默认包下: 在实际开发中 ...

  8. delphi 解决android 9上无法使用http协议

    delphi 解决android 9上无法使用http协议 安卓9不让客户端通过非https方式访问服务端数据(不允许发送明文http请求)的问题. 解决方法: 1.选择安卓平台编译一次程序,在项目根 ...

  9. OpenNebula概述

    OpenNebula概述 OpenNebula是专门为云计算打造的开源系统,用户可以使用Xen.KVM.VMware等虚拟化软件一起打造企业云.利用OpenNebula可以轻松构建私有云.混合云.公开 ...

  10. 自己发挥的内容 有关ViewModel的一句翻译(难点expecting)