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

6,检测邮件情况

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

转载于:https://blog.51cto.com/536410/1914865

Elasticsearch 基于ElastAlert发送邮件报警相关推荐

  1. CentOS下ELK基于ElastAlert实现日志的微信报警

    转载来源 :ELK基于ElastAlert实现日志的微信报警 : https://www.jianshu.com/p/f31c0d6020fe 一.ElastAlert介绍 在日志管理上我们使用Ela ...

  2. Nagios监控之9:利用sendmail使用第三方SMTP服务发送邮件报警

    使用Centos系统自带的sendmail服务作为客户端,使用第三方SMTP服务发送邮件报警. 此功能是在nagios服务正常安装运行的基础上实现的;因此要先安装好基本的nagios运行环境,这个可以 ...

  3. zabbix纯内网环境监控服务器发送邮件报警

    Linux | zabbix | 实战篇(一步步带你到邮件报警) 一.本章环境: Zabbix3.4.8服务器OS:Centos7.6x86_64 邮件服务器OS:Windows10x86_64 邮件 ...

  4. 【Kubernetes 企业项目实战】03、基于 Alertmanager 发送报警到多个接收方(下)

    目录 一.promethues 采集 tomcat 监控数据 1.1 制作 tomcat 镜像 1.2 基于上面的镜像创建一个 tomcat 实例 1.3 采集数据 二.promethues 采集 r ...

  5. 【6】nagios从零学习使用 - centreon发送邮件报警

    通过邮件发送报警信息给139邮箱,这样随时随地都可以了解服务器情况. 在网上查一段时间资料,发现在mutt+msmtp这样的组合最简单方便. 邮件客户端安装设置如下: msmtp下载 http://s ...

  6. Zabbix使用SMTP发送邮件报警并且制定报警内容

    接上篇Zabbix监控介绍及安装配置 选择报警项 创建一个报警项 选择到刚刚自定义的80端口 定义报警方法 定义告警级别 一些报警方法 diff 比较是否有修改 last 最低值 nodata 没有数 ...

  7. Spring Boot——基于spring-boot-starter-mail发送邮件的 Service 服务类DEMO

    前言 发送邮件应该是网站的必备拓展功能之一,注册验证,忘记密码或者是给用户发送营销信息.正常我们会用JavaMail相关api来写发送邮件的相关代码,但现在Spring Boot提供了一套集成spri ...

  8. ElasticSearch基于REST风格APi的常用操作

    前言 该文章最好要有一点REST风格API的知识. 操作是ES配置Kibana进行使用. 基本的REST命令说明 method url地址 说明 PUT localhost:9200/索引名称/类型名 ...

  9. 【Elasticsearch】Elasticsearch 基于scoll技术滚动搜索大量数据

    如果一次性要查出来比如10万条数据,那么性能会很差,此时一般会采取用scoll滚动查询,一批一批的查,直到所有数据都查询完处理完 使用scoll滚动搜索,可以先搜索一批数据,然后下次再搜索一批数据,以 ...

  10. 基于javaMail发送邮件的实现

    关于JavaMail发送验证邮件的心得:   qq邮箱默认SMTP/POP3服务是关闭的,其他邮箱是默认开启的.   qq邮箱开启SMTP/POP3服务时会要求使用授权码,并在使用第三方客户端发送   ...

最新文章

  1. python3精要(62)-编译与解释实践(1)
  2. Android中CardView的简单使用
  3. Qt Creator连接设备
  4. 良心之作----centos6.5下安装svn客户端报错
  5. consul docker方式搭建
  6. 面试官:什么是JDK什么是JRE?服务器可以只安装JRE吗?
  7. VisualSvn Server安装和使用
  8. ES6规格之数组的空位
  9. mysqldump导出insert带字段
  10. 【微服务架构】SpringCloud组件和概念介绍(一)
  11. ffmpeg拉流设置暂停_解决ffmpeg拉流转发频繁丢包问题max delay reached. need to consume packet...
  12. java和基岩怎么联机_JAVA和基岩版要同步了
  13. android 转场动画 4.4,Android高级UI开发(二十七)Material Design之转场动画(一)
  14. matlab导入vgg16,简单导入VGG16
  15. 呼叫中心系统的工单流转处理流程
  16. 央视揭秘“微商传销”:通过朋友圈炫富发展下线
  17. 微信小程序 实现背景色渐变(css实现)
  18. 22.IO引脚复用和映射原理与配置
  19. Lyx的安装流程(windows10系统)及配置中文环境
  20. 仿佛来自虚空,Grothendieck的故事2

热门文章

  1. Python 基礎 - 變量
  2. 组合数学及其应用——鸽巢原理
  3. Visual Studio 自定义控件不显示在工具箱
  4. 阅读之大量数据访问机器的架构优化
  5. jmeter 压测之动态数据关联
  6. ifconfig源码分析之与内核交互数据
  7. git 拉取某个分支到本地
  8. 咖啡品牌“三顿半”完成千万级Pre-A轮融资,峰瑞资本投资...
  9. Jmeter之简单控制器
  10. Cloudera Manager 安装 CDH5.x 心得