前言
可视化监控报警插件 KAAE:Kibi + Kibana Alert & Report App for Elasticsearch。
最近搭建了ELK系统,便想在此基础上做一个基于Kibana的可视化报警配置,在网上东翻西翻,基本没有相关的资料,唯有一篇介绍了KEEA,从这里入手,笔者搭建了自己的报警系统。这里笔者分享下个人在配置过程中的经验与心得。
KAAE介绍:[ phachon的博客 ]
GitHub:[ KAAE GitHub ]
1.KAAE安装
注意:sentinl.zip的版本和Kibana的版本需要相互对应。
方式1:/elk/kibana/bin/kibana-plugin install https://github.com/sirensolutions/sentinl/releases/download/tag-5.4.0/sentinl.zip
方式2:git clone https://github.com/sirensolutions/sentinl
安装nodejs(npm):yum install -y nodejs
安装Gulp(本文为全局安装):npm install -g gulp
安装rsync:yum install rsync
cd sentinl npm install gulp package /elk/kibana/bin/kibana-plugin install file://`pwd`/target/gulp/sentinl.zip
安装完成后,浏览器输入:http://ip:5601出现以下界面说明插件安装成功
2.KAAE配置
这是一份新建watchers后的默认配置
{
"_index": "watcher",
"_type": "watch",
"_id": "new_watcher_jy9qwqzz9",
"_score": 1,
"_source": {
"title": "watcher_title",
"disable": true,
"uuid": "new_watcher_jy9qwqzz9",
"trigger": {
"schedule": {
"later": "every 5 minutes"
}
},
"input": {
"search": {
"request": {
"index": [],
"body": {}
}
}
},
"condition": {
"script": {
"script": "payload.hits.total > 100"
}
},
"transform": {
"script": {
"script": ""
}
},
"actions": {
"email_admin": {
"throttle_period": "15m",
"email": {
"to": "alarm@localhost",
"from": "sentinl@localhost",
"subject": "Sentinl Alarm",
"priority": "high",
"body": "Found {{payload.hits.total}} Events"
}
}
}
}
}
主要配置分为两步
1. kibana.yml配置
配置发件箱信息,在kibana.yml最后添加如下内容
sentinl: settings: email: active: true user: xxx@163.com //邮箱账号 password: xxxxxxx //邮箱密码(第三方登录密码) host: smtp.server.com // 邮箱smtp 服务器地址 ssl: true report: active: true tmp_path: /tmp/
2.配置watchers信息
watchers配置主要为General、Input、Condition、Transform、Actions的配置。其中General为基本配置,设置报警触发时长,Input为限制报警源,Condition为报警触发条件,Action为报警时的邮件设置。Raw为总体配置展现。
本文配置后具体Raw如下所示
{ "_index": "watcher", "_type": "watch", "_id": "new_watcher_bzd9kgjzi", "_score": 1, "_source": { "title": "Alerm", "disable": false, "uuid": "new_watcher_bzd9kgjzi", "trigger": { "schedule": { "later": "every 1 hours" //执行时间为1小时 } }, "input": { "search": { "request": { "body": { "query": { "bool": { "must": [ { "query_string": { "fields": [ "body^5", "_all" ], "query": "ERROR~", //限制报警源为出错ERROR的日志 "use_dis_max": true } }, { "range": { "@timestamp": { "gte": "now-1h", //对进1小时的日志进行检测 "lte": "now", "format": "epoch_millis" } } } ], "must_not": [] } } } } } }, "condition": { "script": { "script": "payload.hits.total>=1" //当报警条件为ERROR出现的次数大于1 } }, "transform": { "script": { "script": "" } }, "actions": { "AlermNeon": { "throttle_period": "1h0m0s", "email": { "to": "yyyg@163.com", //接收报警的邮箱 "from": "xxxx@163.com",//发送报警的邮箱(与kibana.yml配置中一致) "subject": "Sentinl Alarm", "priority": "high", "body": "Alerm of neon: {{payload.hits.total}} !" //邮件内容 } } } } }
到此为止,KAAE(Sentinl)就配置好了。
3.KAAE报警展示
在完成第2部分后,我们启动watchers。
在触发报警时,我们可以看到kibana的日志如下所示
或者在kibana界面sentinl插件中查看报警信息如下所示
当然,如果在报警周期中不存在符合条件的报警,在上述界面是无记录的,我们可以再kibana日志中找到如下信息
到这里本文就结束了。