阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

Elasticsearch 基于ElastAlert发送邮件报警

507次阅读
没有评论

共计 4963 个字符,预计需要花费 13 分钟才能阅读完成。

ElastAlert
  ElastAlert 是 Yelp 公司开源的一套用 Python2.6 写的报警框架。属于后来 Elastic.co 公司出品的 Watcher 同类产品。官网地址见:http://elastalert.readthedocs.org/。
  当我们把 ELK 搭建好后,也顺利的收集到日志了,但是日志里发生了什么事,我们并不能第一时间知道日志里到底发生了什么,运维需要第一时间知道日志发生了什么事,所以就有了 ElastAlert 的邮件报警,如下是详细操作

环境
CentOS 7.0
elasticsearch 5.2.2
logstash 5.2.2
kibana 5.2.2
依赖
参见 http://elastalert.readthedocs.io/en/latest/running_elastalert.html#requirements
Elasticsearch

ISO8601 or Unix timestamped data

Python 2.6 or 2.7

pip, see requirements.txt

1,下载最新 elastalert 并安装模块

# yum install python-setuptools
# git clone https://github.com/Yelp/elastalert.git
# cd elastalert
# pip install -U setuptools
# python setup.py install
# pip install -r requirements.txt 
2,设置配置文件和规则 Rule
[root@localhost ~]# cd /usr/local/elastalert/
[root@localhost elastalert]# cp config.yaml.example config.yaml
[root@localhost elastalert]# vim config.yaml
# This is the folder that contains the rule yaml files
# Any .yaml file will be loaded as a rule
rules_folder: es_rules
# How often ElastAlert will query Elasticsearch
# The unit can be anything from weeks to seconds
run_every:
  minutes: 1
# ElastAlert will buffer results from the most recent
# period of time, in case some log sources are not in real time
buffer_time:
  minutes: 15
# The Elasticsearch hostname for metadata writeback
# Note that every rule can have its own Elasticsearch host
es_host: 192.168.0.33
# The Elasticsearch port
es_port: 9200
# The AWS region to use. Set this when using AWS-managed elasticsearch
#aws_region: us-east-1
# The AWS profile to use. Use this if you are using an aws-cli profile.
# See http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html
# for details
#profile: test
# Optional URL prefix for Elasticsearch
#es_url_prefix: elasticsearch
# Connect with TLS to Elasticsearch
#use_ssl: True
# Verify TLS certificates
#verify_certs: True
# GET request with body is the default option for Elasticsearch.
# If it fails for some reason, you can pass ‘GET’, ‘POST’ or ‘source’.
# See http://elasticsearch-py.readthedocs.io/en/master/connection.html?highlight=send_get_body_as#transport
# for details
#es_send_get_body_as: GET
# Option basic-auth username and password for Elasticsearch
#es_username: someusername
#es_password: somepassword
# The index on es_host which is used for metadata storage
# This can be a unmapped index, but it is recommended that you run
# elastalert-create-index to set a mapping
writeback_index: elastalert_status
# If an alert fails for some reason, ElastAlert will retry
# sending the alert until this time period has elapsed
alert_time_limit:
  days: 2
 
3,发送邮件的邮箱设置
[root@localhost elastalert]# vim example_rules/smtp_auth_file.yaml
user: jet.liu@qq.com

password: xxx
4,配置规则
 [root@iZ6232hr6ksZ elastalert]# vim example_rules/example_frequency.yaml
 # Alert when the rate of events exceeds a threshold
# (Optional)
# Elasticsearch host
# es_host: elasticsearch.example.com
# (Optional)
# Elasticsearch port
# es_port: 14900
# (OptionaL) Connect with SSL to Elasticsearch
#use_ssl: True
# (Optional) basic-auth username and password for Elasticsearch
#es_username: someusername
#es_password: somepassword
# (Required)
# Rule name, must be unique
name: Example rule
# (Required)
# Type of alert.
# the frequency rule type alerts when num_events events occur with timeframe time
type: frequency
# (Required)
# Index to search, wildcard supported
index: logstash-*
# (Required, frequency specific)
# Alert when this many documents matching the query occur within a timeframe
# 限定时间内,发生事件次数
num_events: 1
# (Required, frequency specific)
# num_events must occur within this amount of time to trigger an alert
# 限定时间刻度
timeframe:
 # hours: 4
 #1 分钟
  minutes: 1
# (Required)
# A list of Elasticsearch filters used for find events
# These filters are joined with AND and nested in a filtered query
# For more info: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl.html
filter:
# 这条是发现日志中有 ERROR 的字段,就发邮件报警,这段很重要,如果写错了就会报错
– query:
    match:
      message:
        query: “ERROR” 
#SMTP 协议的邮件服务器相关配置
smtp_host: smtp.exmail.qq.com
smtp_prot: 25
# 用户认证文件,需要 user 和 password 两个属性
smtp_auth_file: /usr/local/elastalert/example_rules/smtp_auth_file.yaml
# 回复给那个邮箱
email_reply_to: jet.liu@qq.com
# 从哪个邮箱发送
from_addr: jet.liu@qq.com
# (Required)
# The alert is use when a match is found
alert:
– “email”
# (required, email specific)
# a list of email addresses to send alerts to
email:
# 接收报警邮件的邮箱
– “jet.liu@qq.com”
5,测试规则
[root@localhost elastalert]#nohup python -m elastalert.elastalert –verbose –rule example_rules/example_frequency.yaml

Elasticsearch 基于 ElastAlert 发送邮件报警

6,检测邮件情况

Elasticsearch 基于 ElastAlert 发送邮件报警

邮件已收到,当日志中发现有 ERROR 都会发邮件报警!

Elasticsearch 教程系列文章

Linux 上安装部署 ElasticSearch 全程记录  http://www.linuxidc.com/Linux/2015-09/123241.htm

Linux 下 Elasticsearch 1.7.0 安装配置 http://www.linuxidc.com/Linux/2017-05/144215.htm

在 Ubuntu 16.04 中安装 Elasticsearch 5.4 分析引擎  http://www.linuxidc.com/Linux/2017-07/145588.htm

Ubuntu 14.04 搭建 ELK 日志分析系统(Elasticsearch+Logstash+Kibana) http://www.linuxidc.com/Linux/2016-06/132618.htm

Elasticsearch1.7 升级到 2.3 实践总结  http://www.linuxidc.com/Linux/2016-11/137282.htm

Ubuntu 14.04 中 Elasticsearch 集群配置  http://www.linuxidc.com/Linux/2017-01/139460.htm

Elasticsearch-5.0.0 移植到 Ubuntu 16.04 http://www.linuxidc.com/Linux/2017-01/139505.htm

ElasticSearch 5.2.2 集群环境的搭建  http://www.linuxidc.com/Linux/2017-04/143136.htm

Linux 下安装搜索引擎 Elasticsearch  http://www.linuxidc.com/Linux/2017-05/144105.htm

CentOS 上安装 ElasticSearch 详解  http://www.linuxidc.com/Linux/2017-05/143766.htm

ElasticSearch 的详细介绍:请点这里
ElasticSearch 的下载地址:请点这里

本文永久更新链接地址:http://www.linuxidc.com/Linux/2017-08/146434.htm

正文完
星哥玩云-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-21发表,共计4963字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中

星哥玩云

星哥玩云
星哥玩云
分享互联网知识
用户数
4
文章数
19351
评论数
4
阅读量
7984811
文章搜索
热门文章
星哥带你玩飞牛NAS-6:抖音视频同步工具,视频下载自动下载保存

星哥带你玩飞牛NAS-6:抖音视频同步工具,视频下载自动下载保存

星哥带你玩飞牛 NAS-6:抖音视频同步工具,视频下载自动下载保存 前言 各位玩 NAS 的朋友好,我是星哥!...
星哥带你玩飞牛NAS-3:安装飞牛NAS后的很有必要的操作

星哥带你玩飞牛NAS-3:安装飞牛NAS后的很有必要的操作

星哥带你玩飞牛 NAS-3:安装飞牛 NAS 后的很有必要的操作 前言 如果你已经有了飞牛 NAS 系统,之前...
我把用了20年的360安全卫士卸载了

我把用了20年的360安全卫士卸载了

我把用了 20 年的 360 安全卫士卸载了 是的,正如标题你看到的。 原因 偷摸安装自家的软件 莫名其妙安装...
再见zabbix!轻量级自建服务器监控神器在Linux 的完整部署指南

再见zabbix!轻量级自建服务器监控神器在Linux 的完整部署指南

再见 zabbix!轻量级自建服务器监控神器在 Linux 的完整部署指南 在日常运维中,服务器监控是绕不开的...
飞牛NAS中安装Navidrome音乐文件中文标签乱码问题解决、安装FntermX终端

飞牛NAS中安装Navidrome音乐文件中文标签乱码问题解决、安装FntermX终端

飞牛 NAS 中安装 Navidrome 音乐文件中文标签乱码问题解决、安装 FntermX 终端 问题背景 ...
阿里云CDN
阿里云CDN-提高用户访问的响应速度和成功率
随机文章
开发者福利:免费 .frii.site 子域名,一分钟申请即用

开发者福利:免费 .frii.site 子域名,一分钟申请即用

  开发者福利:免费 .frii.site 子域名,一分钟申请即用 前言 在学习 Web 开发、部署...
星哥带你玩飞牛 NAS-10:备份微信聊天记录、数据到你的NAS中!

星哥带你玩飞牛 NAS-10:备份微信聊天记录、数据到你的NAS中!

星哥带你玩飞牛 NAS-10:备份微信聊天记录、数据到你的 NAS 中! 大家对「数据安全感」的需求越来越高 ...
支付宝、淘宝、闲鱼又双叕崩了,Cloudflare也瘫了连监控都挂,根因藏在哪?

支付宝、淘宝、闲鱼又双叕崩了,Cloudflare也瘫了连监控都挂,根因藏在哪?

支付宝、淘宝、闲鱼又双叕崩了,Cloudflare 也瘫了连监控都挂,根因藏在哪? 最近两天的互联网堪称“故障...
恶意团伙利用 PHP-FPM 未授权访问漏洞发起大规模攻击

恶意团伙利用 PHP-FPM 未授权访问漏洞发起大规模攻击

恶意团伙利用 PHP-FPM 未授权访问漏洞发起大规模攻击 PHP-FPM(FastCGl Process M...
飞牛NAS玩转Frpc并且配置,随时随地直连你的私有云

飞牛NAS玩转Frpc并且配置,随时随地直连你的私有云

飞牛 NAS 玩转 Frpc 并且配置,随时随地直连你的私有云 大家好,我是星哥,最近在玩飞牛 NAS。 在数...

免费图片视频管理工具让灵感库告别混乱

一言一句话
-「
手气不错
Prometheus:监控系统的部署与指标收集

Prometheus:监控系统的部署与指标收集

Prometheus:监控系统的部署与指标收集 在云原生体系中,Prometheus 已成为最主流的监控与报警...
星哥带你玩飞牛NAS-16:飞牛云NAS换桌面,fndesk图标管理神器上线!

星哥带你玩飞牛NAS-16:飞牛云NAS换桌面,fndesk图标管理神器上线!

  星哥带你玩飞牛 NAS-16:飞牛云 NAS 换桌面,fndesk 图标管理神器上线! 引言 哈...
12.2K Star 爆火!开源免费的 FileConverter:右键一键搞定音视频 / 图片 / 文档转换,告别多工具切换

12.2K Star 爆火!开源免费的 FileConverter:右键一键搞定音视频 / 图片 / 文档转换,告别多工具切换

12.2K Star 爆火!开源免费的 FileConverter:右键一键搞定音视频 / 图片 / 文档转换...
星哥带你玩飞牛NAS硬件03:五盘位+N5105+双网口的成品NAS值得入手吗

星哥带你玩飞牛NAS硬件03:五盘位+N5105+双网口的成品NAS值得入手吗

星哥带你玩飞牛 NAS 硬件 03:五盘位 +N5105+ 双网口的成品 NAS 值得入手吗 前言 大家好,我...
星哥带你玩飞牛NAS-14:解锁公网自由!Lucky功能工具安装使用保姆级教程

星哥带你玩飞牛NAS-14:解锁公网自由!Lucky功能工具安装使用保姆级教程

星哥带你玩飞牛 NAS-14:解锁公网自由!Lucky 功能工具安装使用保姆级教程 作为 NAS 玩家,咱们最...