最近在做把elk告警日志发送到kinesis 流,供后续数据分析处理使用。。。。。。。。

基于尽量不修改elastalert ,把修改工作放到接收端服务的原则。计划把elk的告警数据通过远程api的接口的形式发送到接收端,然后由接收端处理接收到的数据,并传送保存到kinesis 中。

从网上搜索了下elastalert 相关告警配置,搜到的文章大多以邮件告警为主,从官网扒拉了下资源,简单实现方式如下:

1、elastalert 配置(可以本地测试)

1)启动配置config.yaml

rules_folder: rules
run_every:
minutes: 1 buffer_time:
minutes: 5
es_host: es_endpoint
es_port: 9200
es_username: username
es_password: password use_ssl: False
verify_certs: False
writeback_index: elastalert_status
alert_time_limit:
hours: 2

2)告警规则kinesis.yaml

name: alertfortest
type: frequency
num_events: 1
timeframe:
minutes: 1 index: debug-*
filter:
- terms:
fields.app: ["app1","app2"]
- query:
query_string:
default_field: "message"
query: "error NOT INFO" alert:
- "email"
- "post" http_post_url: "http://localhost:8000/elastalert/"
http_post_static_payload:
rule_name: alertfortest smtp_host: "smtp.163.com"
smtp_port: 25
from_addr: "elastalert@163.com"
smtp_auth_file: /tmp/smtp_auth.yaml
email:
- "youremail@qq.com"

2、数据接收端

def elastalert2kinesis(request):
if request.method == 'GET':return HttpResponse(status=400)
elif request.method == 'POST':
data_dict = {
"region":"",
"env":"","service":"",
"ip":"","endpoint":"",
"metric":"",
"value":"",
"timestamp":0,
"dataSource":"",
"status":""
}
alertbody = json.loads(bytes.decode(request.body)) endpoint_list = alertbody['beat']['hostname'].split('-')
data_dict['env'] = endpoint_list[0]
data_dict['region'] = endpoint_list[1]
data_dict['service'] = "-".join(endpoint_list[2:-1])
data_dict['ip'] = endpoint_list[-1]
data_dict['endpoint'] = alertbody['beat']['hostname']
data_dict['dataSource'] = "elk"
data_dict['metric'] = alertbody['source']
data_dict['value'] = alertbody['message']
data_dict['timestamp'] = utc_to_local(alertbody['@timestamp'].split('.')[0]+"Z")
Stream().put_to_stream(data_dict['service'],**data_dict)
print("data_dict.....................:",data_dict) return HttpResponse(status=200)

elastalert 配置post告警方式(备忘)的更多相关文章

  1. ElastAlert配置和告警规则各种用法

    config.yaml配置说明 #用来加载rule的目录,默认是example_rules rules_folder: example_rules #用来设置定时向elasticsearch发送请求 ...

  2. java+hadoop+spark+hbase+scala+kafka+zookeeper配置环境变量记录备忘

    java+hadoop+spark+hbase+scala 在/etc/profile 下面加上如下环境变量 export JAVA_HOME=/usr/java/jdk1.8.0_102 expor ...

  3. ExtJs4常用配置方法备忘

    viewport布局常用属性 new Ext.Viewport({ layout: "border", renderTo: Ext.getBody(), defaults: { b ...

  4. debian文本配置网络备忘:/etc/network/interfaces

    我装了wheezy有gnome3,xfce4: 郁闷的是,不论在gnome还是xfce4中 我都无法图形登录或者切换用户到root: 而且我无法在普通用户下图形修改网络配置: 我也搜索不到启用root ...

  5. (网页的缓存控制)HTML配置no-cache(备忘) “Cache-control”常见的取值

    HTML配置no-cache(备忘) No-cache配置 html表头如下 <meta http-equiv="Content-Type" content="te ...

  6. Nmap备忘单:从探索到漏洞利用(Part 5)

    这是备忘单的最后一部分,在这里主要讲述漏洞评估和渗透测试. 数据库审计 列出数据库名称 nmap -sV --script=mysql-databases 192.168.195.130 上图并没有显 ...

  7. Nmap备忘单:从探索到漏洞利用(Part 4)

    这是我们的Nmap备忘单的第四部分(Part 1. Part 2. Part 3).本文中我们将讨论更多东西关于扫描防火墙,IDS / IPS 逃逸,Web服务器渗透测试等.在此之前,我们应该了解一下 ...

  8. Linux常用命令速查备忘

    Linux常用命令速查备忘   PS:备忘而已,详细的命令参数说明自己man 一. 启动,关机,登入,登出相关命令 [login] 登录 [logout] 登出 [exit] 登出 [shutdown ...

  9. Npm vs Yarn 之备忘大全

    有则笑话,如此讲到:"老丈人爱吃核桃,昨天买了二斤陪妻子送去,老丈人年轻时练过武,用手一拍核桃就碎了,笑着对我说:你还用锤子,你看我用手就成.我嘴一抽,来了句:人和动物最大的区别就是人会使用 ...

随机推荐

  1. linux下编译protobuf

    这里我介绍两种方法,一是直接ccmake配置,二是修改cmake文件下面的CMakeList.txt文件 第一种方法:配置ccmake 1.安装sudo apt-get install cmake-c ...

  2. (办公)mysql连接不上(java.sql.SQLException: null, message from server: "Host 'LAPTOP-O0GA2P8J' is not allowed to connect to this MySQL server")(转)

    转载自csdn文章:https://blog.csdn.net/Tangerine_bisto/article/details/803461511.对所有主机进行访问授权 GRANT ALL PRIV ...

  3. windows 为qt5.7.1 安装openssl

    本人使用qt5.7.1+msvc2015写一个https的客户端程序,但是用到解析https协议时,报出如下错误 qt.network.ssl: QSslSocket: cannot call unr ...

  4. SQLServer修改表数据

    使用SSMS数据库管理工具修改数据 修改任意一条或者多条都可以 1:打开数据库,选择数据表,右键点击->编辑所有行(如未配置,点击编辑前200行). 2.编辑需要修改的数据->编辑完成后, ...

  5. 明天研究下jpa直接像django一样生成

    https://blog.csdn.net/yztezhl/article/details/79390714 自动生成 教程-- https://blog.csdn.net/mxjesse/artic ...

  6. Ambari——大数据平台的搭建利器之进阶篇

    前言 本文适合已经初步了解 Ambari 的读者.对 Ambari 的基础知识,以及 Ambari 的安装步骤还不清楚的读者,可以先阅读基础篇文章<Ambari——大数据平台的搭建利器>. ...

  7. linux -- 添加、修改、删除路由

    在日常的使用中,或者在服务器中,有两个网卡配置两个地址,访问不同的网络段,这种情况是非常常见的现象,但是,我们需要额外的添加路由表来决定发送的数据包经过正确的网关和interface才能正确的进行通信 ...

  8. Angular5 路由守卫

    今年下半年一直很忙,没有多少时间来写博客,很多笔记都记在了本地一起提交到了git上边. 夏末的时候做的两个vue项目中有接触到vue的路由守卫,今天在另外一个angular上,发现路由守卫有异常,导致 ...

  9. SQL NOW() 函数

    NOW() 函数 NOW 函数返回当前的日期和时间. 提示:如果您在使用 Sql Server 数据库,请使用 getdate() 函数来获得当前的日期时间. SQL NOW() 语法 SELECT ...

  10. springboot为导出的pdf和excel加水印

    相信很多小伙伴们在做导出pdf或者excel文件时会被要求在文件上加上水印,本篇博客就来讲讲如何为pdf和excel加水印. 导出pdf加水印 其实在导出pdf时加上水印并不难,因为itext提供了添 ...