今天做了个kibana的sentinl插件的一个告警,期间遇到了几个问题。
1.es里存的时间是timestamp类型,发送告警邮件时需要把时间转换为日期格式。
2.接收到的邮件里的时间是UTC时间,和北京时间差了8个小时。
解决方案:
在搜索es的时候在结果中添加一个字段,并通过脚本的方式将时间偏差修正过来。
"script_fields": {
"newField": {
"script": "LocalDateTime.ofInstant(Instant.ofEpochMilli(doc['timeField'].value), ZoneId.of('+0800')).format(DateTimeFormatter.ofPattern('E yyyy-MM-dd HH:mm:ss',Locale.CHINA))"
}
}