手机网站大全免费下载,做网站 赚钱多吗,长沙优化公司,线上平面设计培训文章目录 前言一、ElastAlert 概览1.1 简介1.2 ElastAlert 特性 二、ElastAlert 下载部署2.1 安装 Python3 环境2.2 下载 ElastAlert2.3 部署 ElastAlert 三、接入平台3.1 对外接口层3.2 服务层 前言
ElastAlert 是 Yelp 公司基于 python 开发的 ELK 日志告警插件#xff0c;… 文章目录 前言一、ElastAlert 概览1.1 简介1.2 ElastAlert 特性 二、ElastAlert 下载部署2.1 安装 Python3 环境2.2 下载 ElastAlert2.3 部署 ElastAlert 三、接入平台3.1 对外接口层3.2 服务层 前言
ElastAlert 是 Yelp 公司基于 python 开发的 ELK 日志告警插件Elastalert 通过查询 Elasticsearch 中的记录与定于的告警规则进行对比判断是否满足告警条件。发生匹配时将为该告警触发一个或多个告警动作。告警规则由 ElastAlert 的 rules 定义每个规则定义一个查询。
一、ElastAlert 概览
1.1 简介
ElastAlert 程序的设计是可靠的、高度可定制的、安装方面也是简单的并且可配置的。
它通过将 Elasticsearch 与两个组件规则类型rule types以及警报alerts相结合进行实现。Elasticsearch 会定期的被程序查询得出的数据经由规则类型rule type确定何时找到了匹配项。当找到匹配项后会根据匹配的数据结果给出一个或多个警报。
配置方面是由一组规则rules进行管控每个规则rules里面定义了一个查询一个规则类型以及一组警报。
目前支持以下的报警类型
CommandEmailJIRAOpsGenieSNSHipChatSlackTelegramDebugStomp
1.2 ElastAlert 特性
架构简单定制灵活支持多种匹配规则频率、阈值、数据变化、黑白名单、变化率等支持多种警报类型邮件、HTTP POST、自定义脚本等匹配项汇总报警重复警报抑制报警失败重试和过期可用性强状态信息保存到Elasticsearch的索引中
二、ElastAlert 下载部署
2.1 安装 Python3 环境
切换到 /data 目录下
cd /data安装 openssl
yum -y install wget openssl openssl-devel gcc gcc-c下载 Python 安装包
wget https://www.python.org/ftp/python/3.6.9/Python-3.6.9.tgz解压缩
tar -zxvf Python-3.6.9.tgzcd Python-3.6.9 目录
cd Python-3.6.9安装配置
./configure编译
make make install建立软连接去除系统自带的 Python2
mv /usr/bin/python /usr/bin/python_old
ln -s /usr/local/python/bin/python3 /usr/bin/python
ln -s /usr/local/python/bin/pip3 /usr/bin/pip
pip install --upgrade pip查看版本
[rootboe-dc-38 bin]# python -V
Python 3.6.9
[rootboe-dc-38 bin]# pip -V
pip 21.3.1 from /usr/local/python/lib/python3.6/site-packages/pip (python 3.6)2.2 下载 ElastAlert
1.克隆 ElastAlert 项目
git clone https://github.com/Yelp/elastalert.git2.安装
cd elastalert
pip install elasticsearch7.0.0
pip install -r requirements.txt
python setup.py install3.安装成功后可以看到四个命令
[rootboe-dc-38 bin]# ll /usr/local/python/bin/elastalert*
-rwxr-xr-x 1 root root 396 Nov 17 13:40 /usr/local/python/bin/elastalert
-rwxr-xr-x 1 root root 422 Nov 17 13:40 /usr/local/python/bin/elastalert-create-index
-rwxr-xr-x 1 root root 430 Nov 17 13:40 /usr/local/python/bin/elastalert-rule-from-kibana
-rwxr-xr-x 1 root root 416 Nov 17 13:40 /usr/local/python/bin/elastalert-test-rule4.软连接到 /usr/bin 下方便使用
ln -s /usr/local/python/bin/elastalert* /usr/binelastalert 报警执行的命令会根据报警规则执行相应操作。elastalert-create-index 会创建一个索引ElastAlert 会把执行记录存放到这个索引中默认情况下索引名叫 elastalert_status。其中有 4 个 _type都有自己的 timestamp 字段所以同样也可以用 Kibana 来查看这个索引的日志记录情况。elastalert-rule-from-kibana 从 Kibana3 已保存的仪表盘中读取 Filtering 设置帮助生成config.yaml 里的配置。不过注意它只会读取 filtering不包括 queries。elastalert-test-rule 测试自定义配置中的 rule 设置。
5.创建 elastalert 索引
elastalert-create-index2.3 部署 ElastAlert
1.主配置文件config.yaml
#加载rule的目录,默认是example_rules
rules_folder: /data/elastalter/example_rules#设置定时向elasticsearch发送请求,也就是告警频率
run_every:minutes: 1#用来设置请求里时间字段的范围
buffer_time:minutes: 15#elasticsearch的ip地址和端口
es_host: 192.168.136.123
es_port: 9200#elastalert产生的日志在elasticsearch中的创建的索引
writeback_index: elastalert_status
writeback_alias: elastalert_alerts
1
#失败重试的时间限制
alert_time_limit:days: 22.邮件告警配置
python -m elastalert.elastalert --verbose --config /data/elastalter/config.yaml --rule /data/elastalter/example_rules/visual-chart.yaml三、接入平台
3.1 对外接口层
Slf4j
RestController
RequestMapping(/webhook)
public class WebhookController {AutowiredWebhookService webhookService;/*** 接收elastalert告警消息** param request* return*/RequestMapping(/elastalert)public Result elastalert(HttpServletRequest request) throws IOException {//设置流的编码request.setCharacterEncoding(UTF-8);StringBuffer data new StringBuffer();String line null;BufferedReader reader null;reader request.getReader();while (null ! (line reader.readLine())) {data.append(line);}String result data.toString().replace(timestamp,timestamp);ElastalertAlarmMessageDTOS elastalertAlarmMessageDTOS JSON.parseObject(result, ElastalertAlarmMessageDTOS.class);String jsonFlatten JsonFlatten.jsonFlatten(elastalertAlarmMessageDTOS.getLog());elastalertAlarmMessageDTOS.setLog(jsonFlatten);log.info(请求数据 elastalertAlarmMessageDTOS);webhookService.handleElastalert(elastalertAlarmMessageDTOS);return Result.success();}
}3.2 服务层
/*** 处理Elastalert消息** param alarmMessages 告警消息*/
public void handleElastalert(ElastalertAlarmMessageDTOS alarmMessages) {String subject String.format(MailConstants.ELASTALERT_SUBJECT_TEMPLATE, alarmMessages.get_index());String content String.format(MailConstants.ELASTALERT_CONTENT_TEMPLATE_LARD, alarmMessages.get_index(),alarmMessages.get_index(), alarmMessages.getTimestamp(), alarmMessages.getLog(),alarmMessages.getMessage(), alarmMessages.get_id());try {msgService.sendLark(subject, content);} catch (Exception e) {log.error(发送错误日志告警通知异常, 主题:{}, 内容:{}, subject, content);}String indexName serviceService.serviceName(alarmMessages.get_index());// 获取服务名称String serviceName getServiceName(indexName);// 根据服务名获取服务信息TService service serviceService.findByName(serviceName);if (service null) {log.warn(处理Elastalert告警信息失败, 原因:未找到对应服务信息, 服务名称:{}, serviceName);}TElastalertAlarmRecord alarmRecord new TElastalertAlarmRecord();alarmRecord.setAlarmTime(alarmMessages.getTimestamp().toString());alarmRecord.setBuId(service.getBuId());alarmRecord.setPath(alarmMessages.getLog());alarmRecord.setServiceName(serviceName);alarmRecord.setAlarmMessage(alarmMessages.getMessage());alarmRecordService.save(alarmRecord);// 查找该BU关联的用户ListTUser users userService.findByBuId(service.getBuId());users.removeIf(user - MailConstants.WARN_SKIP_USERS.contains(user.getEmpNo()));if (CollectionUtils.isEmpty(users)) {log.warn(发送Elastalert告警通知邮件失败, 原因:未找到对应的负责人, 服务名称:{}, serviceName);}String[] to users.stream().map(TUser::getEmail).collect(Collectors.toList()).toArray(new String[0]);String contentMail String.format(MailConstants.ELASTALERT_CONTENT_TEMPLATE_LARD_MAIL, alarmMessages.get_index(),alarmMessages.get_index(), alarmMessages.getTimestamp(), alarmMessages.getLog(),alarmMessages.getMessage(), alarmMessages.get_id());try {msgService.sendHTMLMail(to, null, subject, contentMail);} catch (Exception e) {log.error(发送Elastalert告警通知邮件异常, 收件人:{}, 主题:{}, 内容:{}, to, subject, content);}
}
文章转载自: http://www.morning.tkchg.cn.gov.cn.tkchg.cn http://www.morning.nkqxb.cn.gov.cn.nkqxb.cn http://www.morning.kzhxy.cn.gov.cn.kzhxy.cn http://www.morning.pmtky.cn.gov.cn.pmtky.cn http://www.morning.tnwgc.cn.gov.cn.tnwgc.cn http://www.morning.mmhyx.cn.gov.cn.mmhyx.cn http://www.morning.rjrnx.cn.gov.cn.rjrnx.cn http://www.morning.cxtbh.cn.gov.cn.cxtbh.cn http://www.morning.fwdln.cn.gov.cn.fwdln.cn http://www.morning.jxscp.cn.gov.cn.jxscp.cn http://www.morning.swdnr.cn.gov.cn.swdnr.cn http://www.morning.sfwcx.cn.gov.cn.sfwcx.cn http://www.morning.gcftl.cn.gov.cn.gcftl.cn http://www.morning.jqbmj.cn.gov.cn.jqbmj.cn http://www.morning.mdwtm.cn.gov.cn.mdwtm.cn http://www.morning.gjlml.cn.gov.cn.gjlml.cn http://www.morning.jnzfs.cn.gov.cn.jnzfs.cn http://www.morning.vaqmq.cn.gov.cn.vaqmq.cn http://www.morning.kqpsj.cn.gov.cn.kqpsj.cn http://www.morning.sqhtg.cn.gov.cn.sqhtg.cn http://www.morning.jpwkn.cn.gov.cn.jpwkn.cn http://www.morning.dqbpf.cn.gov.cn.dqbpf.cn http://www.morning.qnftc.cn.gov.cn.qnftc.cn http://www.morning.xqjh.cn.gov.cn.xqjh.cn http://www.morning.sjqpm.cn.gov.cn.sjqpm.cn http://www.morning.blxor.com.gov.cn.blxor.com http://www.morning.dhqzc.cn.gov.cn.dhqzc.cn http://www.morning.oioini.com.gov.cn.oioini.com http://www.morning.qpnmd.cn.gov.cn.qpnmd.cn http://www.morning.rfhmb.cn.gov.cn.rfhmb.cn http://www.morning.kfmlf.cn.gov.cn.kfmlf.cn http://www.morning.bzpwh.cn.gov.cn.bzpwh.cn http://www.morning.gmztd.cn.gov.cn.gmztd.cn http://www.morning.lpzqd.cn.gov.cn.lpzqd.cn http://www.morning.jqsyp.cn.gov.cn.jqsyp.cn http://www.morning.junmap.com.gov.cn.junmap.com http://www.morning.dgsr.cn.gov.cn.dgsr.cn http://www.morning.ydnxm.cn.gov.cn.ydnxm.cn http://www.morning.qgjgsds.com.cn.gov.cn.qgjgsds.com.cn http://www.morning.ksjnl.cn.gov.cn.ksjnl.cn http://www.morning.dtnyl.cn.gov.cn.dtnyl.cn http://www.morning.qgghj.cn.gov.cn.qgghj.cn http://www.morning.lveyue.com.gov.cn.lveyue.com http://www.morning.nytqy.cn.gov.cn.nytqy.cn http://www.morning.lkthj.cn.gov.cn.lkthj.cn http://www.morning.srzhm.cn.gov.cn.srzhm.cn http://www.morning.27asw.cn.gov.cn.27asw.cn http://www.morning.yrsg.cn.gov.cn.yrsg.cn http://www.morning.hwbmn.cn.gov.cn.hwbmn.cn http://www.morning.tdnbw.cn.gov.cn.tdnbw.cn http://www.morning.hncrc.cn.gov.cn.hncrc.cn http://www.morning.dqcpm.cn.gov.cn.dqcpm.cn http://www.morning.njddz.cn.gov.cn.njddz.cn http://www.morning.sqgqh.cn.gov.cn.sqgqh.cn http://www.morning.hmqmm.cn.gov.cn.hmqmm.cn http://www.morning.pjftk.cn.gov.cn.pjftk.cn http://www.morning.ckctj.cn.gov.cn.ckctj.cn http://www.morning.tqxtx.cn.gov.cn.tqxtx.cn http://www.morning.jjrsk.cn.gov.cn.jjrsk.cn http://www.morning.lqtwb.cn.gov.cn.lqtwb.cn http://www.morning.fgkwh.cn.gov.cn.fgkwh.cn http://www.morning.ntzfj.cn.gov.cn.ntzfj.cn http://www.morning.kxbdm.cn.gov.cn.kxbdm.cn http://www.morning.rtzd.cn.gov.cn.rtzd.cn http://www.morning.wdpbq.cn.gov.cn.wdpbq.cn http://www.morning.srky.cn.gov.cn.srky.cn http://www.morning.hxbjt.cn.gov.cn.hxbjt.cn http://www.morning.prgyd.cn.gov.cn.prgyd.cn http://www.morning.lcdtb.cn.gov.cn.lcdtb.cn http://www.morning.mldrd.cn.gov.cn.mldrd.cn http://www.morning.smhtg.cn.gov.cn.smhtg.cn http://www.morning.hxgly.cn.gov.cn.hxgly.cn http://www.morning.ccphj.cn.gov.cn.ccphj.cn http://www.morning.fnpmf.cn.gov.cn.fnpmf.cn http://www.morning.tkryt.cn.gov.cn.tkryt.cn http://www.morning.lynb.cn.gov.cn.lynb.cn http://www.morning.xshkh.cn.gov.cn.xshkh.cn http://www.morning.ahscrl.com.gov.cn.ahscrl.com http://www.morning.zpfr.cn.gov.cn.zpfr.cn http://www.morning.ncrk.cn.gov.cn.ncrk.cn