一、需求
1、logstash采集日志数据,并将日志数据写入 ES 集群中,其中@timestamp采用北京时间(默认为ISO8601)
2、elastalert 间隔60秒运行一次规则文件,如果查询到匹配规则文件的日志,则告警。elastalert默认是查询 @timestamp,并在内部转换为 ISO8601 格式的时间。
二、解决方案
1、 logstash 执行时指定的配置文件,在采集日志写 ES前,修改 @timestamp时间,增加 8*60*60(北京时间)
2、logstash 执行时指定的配置文件,新增一个记录如utc_time,其值为 ISO8601 格式的 @timestamp ,用于 elastalert 查询使用
3、 elastalert 查询时的规则文件,增加 timestamp_field: utc_time (默认为 @timestamp)
三、对于的脚本
1、logstash 启动指定的脚本,这里使用 app-es.conf
启动命令: ./logstash -f app-es.conf
input{
file{
path => "/home/app/testlog/test.log"
start_position => "beginning" # 每次从文件开头读取
sincedb_path => "/dev/null" # sincedb_path 记录读取位置,这里指向