python3.6-Yelp/elastalert0.2.1-elk7.2.0邮件加企业微信告警
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
python3.6-Yelp/elastalert0.2.1-elk7.2.0邮件加企业微信告警的更多相关文章
- python3:利用smtplib库和smtp.qq.com邮件服务器发送邮件
python3:利用smtplib库和smtp.qq.com邮件服务器发送邮件 使用qq的邮件服务器需要注意的两个地方主要是: 1.协议问题 使用465端口 SSL 协议 2.口令问题 出现SMTPA ...
- ELK7.4.0分析nginx json日志
ELK7.4.0单节点部署 环境准备 安装系统,数据盘设置为/srv 内核优化参考 我们需要创建elk专用的账号,并创建所需要的目录并授权 useradd elk; mkdir /srv/{app,d ...
- 在Centos7下docker配置自动化环境镜像(python3.7+selenium 3.11+firefox 62+geckodriver 0.21)
最近在学习Docker,准备做自动化测试代码集成的功能.如下文章的前提是已经安装好linux系统,且成功安装好Docker. 接下来我会按步骤一步一步的对自动化需要的一些环境进行安装,如果没有特别说明 ...
- 后端Python3+Flask结合Socket.io配合前端Vue2.0实现简单全双工在线客服系统
原文转载自「刘悦的技术博客」https://v3u.cn/a_id_158 在之前的一篇文章中:为美多商城(Django2.0.4)添加基于websocket的实时通信,主动推送,聊天室及客服系统,详 ...
- Python3调用企业微信用于告警
前段时间利用py爬虫抓取一些网页信息,然后通过wxpy发送到微信群,以用作日常告警,感觉还是很方便. 但好景不长,我的小号微信被腾讯封了(很常见咯), 显示无法登录网页版微信,至今已经有半个多月了. ...
- Python3基础 __add__,__sub__ 两个类的实例相互加减
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- python3企业微信群组报警
公司提出一个需求需要做一个企业微信的一个消息推送,需要将消息发送到聊天群里详细信息如下. 如何创建应用请阅读我的上篇文章:https://www.cnblogs.com/wangyajunblog/p ...
- Python3 使用企业微信 API 发送消息
#coding=utf- import requests import json Secret = "TUbfeW8nFQakwOS4czm13SCnxSUPOqY2K0XHtM8XLT34 ...
- Python3基础 bool True为1 False为0
Python : 3.7.3 OS : Ubuntu 18.04.2 LTS IDE : pycharm-community-2019.1.3 ...
随机推荐
- MongoDB CRUD 操作
crud是指在做计算处理时的增加(Create).读取查询(Retrieve).更新(Update)和删除(Delete)几个单词的首字母简写.crud主要被用在描述软件系统中数据库或者持久层的基本操 ...
- Postgresql 日志相关
目录日志种类作用总结配置文件中与日志相关的配置日志种类 PostgreSQL有3种日志 pg_log(数据库运行日志) 内容可读 默认关闭的,需要设置参数启动pg_xlog(WAL 日志,即 ...
- 为什么深度(Ubuntu)Linux挂载NTFS分区只读不可写?
如前所述,经扩展,Dell Vostro 1520笔记本电脑拥有了两块硬盘. 本着旧物利用的心思,在其中一块256GiB固态盘上安装了深度linux,同时挂载另一块2TiB机械盘作为存储盘. 这块 ...
- CF590E Birthday
题意 给定 \(n\) 个只由 \(a,b\) 组成的字符串,保证两两不同. 要求从中选出尽可能多的字符串,使得选出的字符串中,任意一个字符串不是另一个的子串. 求最多能选多少并输出一个可行解. \( ...
- 正确处理listview的position
当ListView包含有HeaderView或FooterView时,传入getView或者onItemClick的position是怎样的,这是个值得探讨的问题 先列出错误的用法 定义: priva ...
- Qt 的插件制作
首先会遇到一些插件使用的问题: 插件加载的时候出现乱码 qrc:/main.qml:20: Error: Qt.createQmlObject(): failed to create object: ...
- 从Cortex-M3的MSP 和PSP谈Linux能否在中断中使用Sleep
1.Cortex-M3 的PSP和MSP 曾经在STM32上使用过RT thread和uC/OS,对于任务切换代码一直是一知半解,没有自己手动写出来过,对于任务切换后的ORR LR, LR, #0 ...
- 【边缘计算】 Edge Computing: Vision and Challenges
原文地址: http://www.cs.wayne.edu/~weisong/papers/shi16-edge-computing.pdf ----------------------------- ...
- jmeter 分布式配置(含参数化问题)
这次用的是 jmeter 5.1.1 jdk8 调度机: 修改bin目录下jmeter.properties文件 第258行 remote_hosts=192.168.87.34:1856,192. ...
- 源码安装LNMP
需要准备的安装包以及下载地址(只是一个大概地址,版本和下载方式需要自行选择): Nginx http://nginx.org/en/download.html nginx主程序包 MySQL http ...